Пример #1
0
    def mouse_down(self, ips, x, y, btn, **key):
        if ips == self.ips1:
            self.ips1.mark.set_xy(x, y)
            self.ips.mark.set_xy(None, y)
            self.ips.cur = int(x)
            self.ips1.update = True
            self.ips.update = True
        elif ips == self.ips2:
            self.ips2.mark.set_xy(x, y)
            self.ips.mark.set_xy(x, None)
            self.ips.cur = int(y)
            self.ips2.update = True
            self.ips.update = True
        elif ips.get_nslices() == 1 or not ips.is3d:
            IPy.alert('stack required!')
            return
        elif self.view1 == None:
            img1, img2 = self.getimgs(ips.imgs, x, y)
            self.ips1 = ImagePlus([img1])
            self.ips2 = ImagePlus([img2])
            self.view1 = CanvasFrame(IPy.curapp)
            self.view2 = CanvasFrame(IPy.curapp)

            self.ips = ips
            self.view1.set_ips(self.ips1)
            self.view2.set_ips(self.ips2)
            canvas1, canvas2 = self.view1.canvas, self.view2.canvas
            canvas = IPy.get_window().canvas
            canvas1.scaleidx = canvas2.scaleidx = canvas.scaleidx
            canvas1.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            canvas2.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            self.view1.Show()
            self.view2.Show()
            ips.mark = Cross(*ips.size[::-1])
            ips.mark.set_xy(x, y)
            self.ips1.mark = Cross(*self.ips1.size[::-1])
            self.ips2.mark = Cross(*self.ips2.size[::-1])
            self.ips1.mark.set_xy(x, ips.cur)
            self.ips2.mark.set_xy(ips.cur, y)
            ips.update = True

        else:
            img1, img2 = self.getimgs(ips.imgs, x, y)
            self.ips1.set_imgs([img1])
            self.ips2.set_imgs([img2])
            '''
            canvas1, canvas2 = self.view1.canvas, self.view2.canvas
            canvas = IPy.curwindow.canvas
            canvas1.scaleidx = canvas2.scaleidx = canvas.scaleidx
            canvas1.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            canvas2.zoom(canvas.scales[canvas.scaleidx], 0, 0)
            '''
            self.ips1.mark.set_xy(ips.cur, y)
            self.ips2.mark.set_xy(x, ips.cur)
            self.ips1.update = True
            self.ips2.update = True
            ips.mark.set_xy(x, y)
            ips.update = True
Пример #2
0
 def run(self, ips, imgs, para = None):
     name = self.para['name']
     if ips.get_nslices()==1 or self.para['stack']==False:
         if ips.roi == None:
             img = ips.get_img().copy()
             ipsd = ImagePlus([img], name)
         else:
             img = ips.get_subimg().copy()
             ipsd = ImagePlus([img], name)
             box = ips.roi.get_box()
             ipsd.roi = ips.roi.affine(np.eye(2), (-box[0], -box[1]))
     elif ips.get_nslices()>1 and self.para['stack']:
         if ips.roi == None:
             if ips.is3d:imgs=imgs.copy()
             else:imgs = [i.copy() for i in imgs]
         else:
             sc, sr = ips.get_rect()
             if ips.is3d: imgs=imgs[:, sc, sr].copy()
             else: imgs = [i[sc,sr].copy() for i in imgs]
         ipsd = ImagePlus(imgs, name)
         ipsd.roi = ips.roi.affine(np.eye(2), (-sr.start, -sc.start))
             
     frame = CanvasFrame(IPy.curapp)
     frame.set_ips(ipsd)
     frame.Show()
Пример #3
0
    def run(self, ips, imgs, para=None):
        idx = ['red', 'green', 'blue']
        imr, img, imb = [WindowsManager.get(para[i]).ips for i in idx]
        sr, sg, sb = [i.get_nslices() for i in [imr, img, imb]]

        if imr.imgtype != '8-bit' or img.imgtype != '8-bit' or imb.imgtype != '8-bit':
            IPy.alert('must be three 8-bit image!')
            return
        if imr.size != img.size or img.size != imb.size or sr != sg or sg != sb:
            IPy.alert(
                'three image must be in same size and have the same slices!')
            return

        rgb = []
        w, h = imr.size
        rgbs = zip(imr.imgs, img.imgs, imb.imgs)
        for i in range(sr):
            IPy.curapp.set_progress(round((i + 1) * 100.0 / sr))
            img = np.zeros((w, h, 3), dtype=np.uint8)
            for j in (0, 1, 2):
                img[:, :, j] = rgbs[i][j]
            rgb.append(img)
        IPy.curapp.set_progress(0)
        ip = ImagePlus(rgb, 'rgb-merge')
        frame = CanvasFrame(IPy.curapp)
        frame.set_ips(ip)
        frame.Show()
        if self.para['destory']:
            for title in [para[i] for i in idx]:
                WindowsManager.close(title)
Пример #4
0
def show_img(imgs, title):
    from imageplus import ImagePlus
    from ui.canvasframe import CanvasFrame
    ips = ImagePlus(imgs, title)
    frame = CanvasFrame(curapp)
    frame.set_ips(ips)
    frame.Show()
Пример #5
0
 def run(self, para=None):
     w, h = para['width'], para['height']
     chanels = (1, 3)[para['type'] == 'RGB']
     slices = para['slice']
     shape = (h, w, chanels) if chanels != 1 else (h, w)
     imgs = [np.zeros(shape, dtype=np.uint8) for i in range(slices)]
     ips = ImagePlus(imgs, para['name'])
     frame = CanvasFrame(IPy.curapp)
     frame.set_ips(ips)
     frame.Show()
Пример #6
0
    def run(self, ips, snap, img, para=None):
        if para == None: para = self.para
        ips.lut = self.lut
        msk = img > para['thr']
        con = 1 if para['con'] == '4-Connect' else 2
        strc = generate_binary_structure(2, con)
        msk = label(msk, strc, output=np.uint16)

        nips = ImagePlus([msk[0]], ips.title + '-label')
        frame = CanvasFrame(IPy.curapp)
        frame.set_ips(nips)
        frame.Show()
Пример #7
0
 def run(self, ips, imgs, para=None):
     r, g, b = [], [], []
     for i, n in zip(imgs, range(ips.get_nslices())):
         IPy.curapp.set_progress(round((n + 1) * 100.0 / len(imgs)))
         for c, ci in zip((r, g, b), (0, 1, 2)):
             if self.para['copy']: c.append(i[:, :, ci].copy())
             else: c.append(i[:, :, ci])
     IPy.curapp.set_progress(0)
     for im, tl in zip([r, g, b], ['red', 'green', 'blue']):
         ip = ImagePlus(im, ips.title + '-' + tl)
         frame = CanvasFrame(IPy.curapp)
         frame.set_ips(ip)
         frame.Show()
     if self.para['destory']:
         WindowsManager.close(ips.title)
Пример #8
0
    def run(self, para=None):

        plus = IPy.get_ips()
        if plus == None:
            img = np.ones(
                (30, 1), dtype=np.uint8) * np.arange(256, dtype=np.uint8)
            ips = ImagePlus([img])
            frame = CanvasFrame(IPy.curapp)
            frame.set_ips(ips)
            ips.lut = ColorManager.get_lut(self.title)
            frame.Show()
        elif plus.chanels != 1:
            IPy.alert('RGB image do not surport Lookup table!')
            return
        else:
            plus.lut = ColorManager.get_lut(self.title)
            plus.update = 'pix'
Пример #9
0
            bf = np.clip(img[:, :, self.chan[i]], rg[0], rg[1])
            np.subtract(bf, rg[0], out=bf, casting='unsafe')
            np.multiply(bf, k, out=rgb[:, :, i], casting='unsafe')
        return rgb

    def swap(self):
        print(type(self.snap), type(self.imgs[self.cur]), self.cur)
        if self.snap is None: return
        if isinstance(self.imgs, list):
            self.snap, self.imgs[self.cur] = self.imgs[self.cur], self.snap
        else:
            buf = self.img.copy()
            self.img[:], self.snap[:] = self.snap, buf

    def __del__(self):
        print(self.title, '>>> delete ips')


if __name__ == '__main__':
    from skimage.io import imread
    img = imread('results.bmp')
    ips = ImagePlus([img, 255 - img])

    from ui.canvasframe import CanvasFrame
    import wx

    app = wx.PySimpleApp()
    frame = CanvasFrame()
    frame.set_ips(ips)
    frame.Show()
    app.MainLoop()
Пример #10
0
def showips(ips):
    from ui.canvasframe import CanvasFrame
    frame = CanvasFrame(curapp)
    frame.set_ips(ips)
    frame.Show()
Пример #11
0
def showips(ips):
    frame = CanvasFrame(curapp)
    frame.set_ips(ips)
    frame.Show()