Example #1
0
    def run(self, ips, imgs, para=None):
        ips1 = WindowsManager.get(para['img1']).ips
        ips2 = WindowsManager.get(para['img2']).ips

        sl1, sl2 = ips1.get_nslices(), ips2.get_nslices()
        cn1, cn2 = ips1.get_nchannels(), ips2.get_nchannels()
        if ips1.dtype != ips2.dtype:
            IPy.alert('Two stack must be equal dtype!')
            return
        elif sl1 > 1 and sl2 > 1 and sl1 != sl2:
            IPy.alert('Two stack must have equal slices!')
            return
        elif cn1 > 1 and cn2 > 1 and cn1 != cn2:
            IPy.alert('Two stack must have equal chanels!')
            return

        w, h = ips1.size, ips2.size
        w, h = min(w[0], h[0]), min(w[1], h[1])
        if sl1 == 1:
            bliter.blit(ips1.get_img(), ips2.get_img(), mode=para['op'])
        elif sl1 > 1 and sl2 == 1:
            for i in range(sl1):
                IPy.set_progress(round(i * 100.0 / sl1))
                bliter.blit(ips1.imgs[i], ips2.get_img(), mode=para['op'])
        elif sl1 > 1 and sl2 > 1:
            for i in range(sl1):
                IPy.set_progress(round(i * 100.0 / sl1))
                bliter.blit(ips1.imgs[i], ips2.imgs[i], mode=para['op'])
        IPy.set_progress(0)
        ips1.update = 'pix'
Example #2
0
    def run(self, ips, imgs, para=None):
        if not para['slice']:
            msks = [ips.get_img()]
            imgs = [WindowsManager.get(para['img']).ips.get_img()]
        else:
            msks = imgs
            imgs = WindowsManager.get(para['img']).ips.imgs

        titles = ['Slice', 'ID'][0 if para['slice'] else 1:]
        if para['center']: titles.extend(['Center-X', 'Center-Y'])
        if para['area']: titles.append('Area')
        if para['l']: titles.append('Perimeter')
        if para['extent']: titles.extend(['Min-Y', 'Min-X', 'Max-Y', 'Max-X'])
        if para['cov']: titles.extend(['Major', 'Minor', 'Ori'])
        buf = imgs[0].astype(np.uint16)
        data, mark = [], []
        print len(imgs)
        for i in range(len(imgs)):
            label(msks[i], np.ones((3, 3)), output=buf)
            ls = regionprops(buf, imgs[i])

            dt = [[i] * len(ls), range(len(ls))]
            if not para['slice']: dt = dt[1:]

            if not para['cov']: cvs = [None] * len(ls)
            else:
                cvs = [(i.major_axis_length, i.minor_axis_length,
                        i.orientation) for i in ls]
            centroids = [i.centroid for i in ls]
            mark.append([(center, cov) for center, cov in zip(centroids, cvs)])
            if para['center']:
                dt.append([round(i.centroid[0], 1) for i in ls])
                dt.append([round(i.centroid[1], 1) for i in ls])
            if para['area']:
                dt.append([i.area for i in ls])
            if para['l']:
                dt.append([round(i.perimeter, 1) for i in ls])
            if para['extent']:
                for j in (0, 1, 2, 3):
                    dt.append([i.bbox[j] for i in ls])
            if para['cov']:
                dt.append([round(i.major_axis_length, 1) for i in ls])
                dt.append([round(i.minor_axis_length, 1) for i in ls])
                dt.append([round(i.orientation, 1) for i in ls])

            data.extend(zip(*dt))
        ips.mark = Mark(mark)
        IPy.table(ips.title + '-region', data, titles)
Example #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)
Example #4
0
    def run(self, ips, imgs, para=None):
        lab = WindowsManager.get(para['lab']).ips.get_img()
        if lab.dtype != np.uint8 and lab.dtype != np.uint16:
            IPy.alert('Label image must be in type 8-bit or 16-bit')
            return
        index = range(1, lab.max() + 1)
        titles = ['Center-X', 'Center-Y', 'Max-X', 'Max-Y', 'Min-X', 'Min-Y']
        key = {
            'Max-X': 'max',
            'Max-Y': 'max',
            'Min-X': 'min',
            'Min-Y': 'min',
            'Center-X': 'center',
            'Center-Y': 'center'
        }
        titles = ['value'] + [i for i in titles if para[key[i]]]

        data = [index]
        img = ips.get_img()
        if img is lab: img = img > 0
        if para['center']:
            pos = np.round(ndimage.center_of_mass(img, lab, index), 2)
            data.append(pos[:, 0])
            data.append(pos[:, 1])
        if para['max']:
            pos = np.round(ndimage.minimum_position(img, lab, index), 2)
            data.append(pos[:, 0])
            data.append(pos[:, 1])
        if para['min']:
            pos = np.round(ndimage.maximum_position(img, lab, index), 2)
            data.append(pos[:, 0])
            data.append(pos[:, 1])
        data = zip(*data)
        IPy.table(ips.title + '-position', data, titles)
Example #5
0
    def run(self, ips, imgs, para=None):
        lab = WindowsManager.get(para['lab']).ips.get_img()
        if lab.dtype != np.uint8 and lab.dtype != np.uint16:
            IPy.alert('Label image must be in type 8-bit or 16-bit')
            return
        index = range(1, lab.max() + 1)
        titles = ['Max', 'Min', 'Mean', 'Variance', 'Standard', 'Sum']
        key = {
            'Max': 'max',
            'Min': 'min',
            'Mean': 'mean',
            'Variance': 'var',
            'Standard': 'std',
            'Sum': 'sum'
        }
        titles = ['value'] + [i for i in titles if para[key[i]]]

        data = [index]
        img = ips.get_img()
        if img is lab: img = img > 0
        if para['max']: data.append(ndimage.maximum(img, lab, index))
        if para['min']: data.append(ndimage.minimum(img, lab, index))
        if para['mean']: data.append(ndimage.mean(img, lab, index).round(4))
        if para['var']: data.append(ndimage.variance(img, lab, index).round(4))
        if para['std']:
            data.append(ndimage.standard_deviation(img, lab, index).round(4))
        if para['sum']: data.append(ndimage.sum(img, lab, index).round(4))
        data = zip(*data)
        IPy.table(ips.title + '-segment', data, titles)
Example #6
0
 def run(self, ips, imgs, para=None):
     lab = WindowsManager.get(para['lab']).ips.get_img()
     if lab.dtype != np.uint8 and lab.dtype != np.uint16:
         IPy.alert('Label image must be in type 8-bit or 16-bit')
         return
     index = range(1, lab.max() + 1)
     data = [index]
     img = ips.get_img()
     if img is lab: img = img > 0
     if para['mode'] == 'Center':
         pos = np.round(ndimage.center_of_mass(img, lab, index), 2)[:, ::-1]
         data.append(pos[:, 0])
         data.append(pos[:, 1])
     if para['mode'] == 'Max':
         pos = np.round(ndimage.maximum_position(img, lab, index),
                        2)[:, ::-1]
         data.append(pos[:, 0])
         data.append(pos[:, 1])
     if para['mode'] == 'Min':
         pos = np.round(ndimage.minimum_position(img, lab, index),
                        2)[:, ::-1]
         data.append(pos[:, 0])
         data.append(pos[:, 1])
     body = [tuple(i) for i in pos]
     ips.roi = PointRoi(body)
Example #7
0
 def show(self):
     self.dialog = ParaDialog(WindowsManager.get(), self.title)
     self.dialog.init_view(self.view,
                           self.para,
                           'preview' in self.note,
                           modal=self.modal)
     self.dialog.set_handle(lambda x: self.preview(self.para))
     if self.modal: return self.dialog.ShowModal()
     self.dialog.on_ok = lambda: self.ok(self.ips)
     self.dialog.on_cancel = lambda: self.cancel(self.ips)
     self.dialog.Show()
Example #8
0
 def run(self, ips, imgs, para=None):
     ips1 = WindowsManager.get(para['img1']).ips
     ips2 = WindowsManager.get(para['img2']).ips
     detector = cv2.SURF(hessianThreshold=para['thr'],
                         nOctaves=para['oct'],
                         nOctaveLayers=para['int'],
                         upright=para['upright'],
                         extended=para['ext'])
     kps1, feats1 = detector.detectAndCompute(ips1.get_img(), None)
     kps2, feats2 = detector.detectAndCompute(ips2.get_img(), None)
     dim, std = {
         'None': 0,
         'Affine': 6,
         'H**o': 8
     }[para['trans']], para['std'] / 100.0
     style = para['style'] == 'Blue/Yellow'
     idx, msk, m = Matcher(dim, std).filter(kps1, feats1, kps2, feats2)
     picker1 = Pick(kps1, kps2, idx, msk, ips1, ips2, True, style)
     picker2 = Pick(kps1, kps2, idx, msk, ips1, ips2, False, style)
     ips1.tool, ips1.mark = picker1, picker1
     ips2.tool, ips2.mark = picker2, picker2
     if para['log']: self.log(kps1, kps2, msk, m, dim)
     ips1.update, ips2.update = True, True