コード例 #1
0
ファイル: rgbmerge_plg.py プロジェクト: shuxin/imagepy
    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)
コード例 #2
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'
コード例 #3
0
ファイル: canvasframe.py プロジェクト: shuxin/imagepy
    def __init__(self, parent=None):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( -1,-1 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
        
        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
        self.SetBackgroundColour( wx.Colour( 255, 255, 255 ) )
        sizer = wx.BoxSizer( wx.VERTICAL )
        self.txt_info = wx.StaticText( self, wx.ID_ANY, u'500*500 pixels 173k', wx.DefaultPosition, wx.DefaultSize, 0 )
        self.txt_info.Wrap( -1 )
        sizer.Add( self.txt_info, 0, wx.ALL, 0 )
        
        self.canvas = Canvas(self)
        self.canvas.fit = self
 
        sizer.Add( self.canvas, 1, wx.EXPAND |wx.ALL, 0 )
        
        self.page = wx.ScrollBar( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SB_HORIZONTAL)
        self.page.SetScrollbar(0,0,0,0, refresh=True)
        sizer.Add( self.page, 0, wx.ALL|wx.EXPAND, 0 )
        #self.page.Hide()
        self.SetSizer(sizer)
        self.Layout()
        
        self.Bind(wx.EVT_IDLE, self.on_idle)
        self.Bind(wx.EVT_SCROLL_THUMBTRACK, self.on_scroll)
        self.Bind(wx.EVT_ACTIVATE, self.on_valid) 
        self.Bind(wx.EVT_CLOSE, self.on_close)
        self.canvas.Bind(wx.EVT_CHAR, self.on_key)
        self.canvas.SetFocus()
        # panel.Bind(wx.EVT_CHAR, self.OnKeyDown)
        self.opage = 0
        self.Fit() 
        WindowsManager.add(self)
コード例 #4
0
ファイル: rgbsplit_plg.py プロジェクト: shuxin/imagepy
 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)
コード例 #5
0
ファイル: regionprops_plg.py プロジェクト: kaiser34/imagepy
    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)
コード例 #6
0
ファイル: segment_plg.py プロジェクト: shuxin/imagepy
    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)
コード例 #7
0
ファイル: segment_plg.py プロジェクト: shuxin/imagepy
 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)
コード例 #8
0
ファイル: segment_plg.py プロジェクト: shuxin/imagepy
    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)
コード例 #9
0
 def load(self, ips):
     titles = WindowsManager.get_titles()
     self.para['img1'] = titles[0]
     self.para['img2'] = titles[0]
     Plugin.view = [(list, titles, str, 'image1', 'img1', ''),
                    (list, ['max', 'min', 'diff', 'add',
                            'substract'], str, 'operator', 'op', ''),
                    (list, titles, str, 'image2', 'img2', '')]
     return True
コード例 #10
0
ファイル: rgbmerge_plg.py プロジェクト: shuxin/imagepy
 def load(self, ips):
     titles = WindowsManager.get_titles()
     self.para['red'] = titles[0]
     self.para['green'] = titles[0]
     self.para['blue'] = titles[0]
     Plugin.view = [(list, titles, str, 'Red', 'red', ''),
                    (list, titles, str, 'Green', 'green', ''),
                    (list, titles, str, 'Blue', 'blue', ''),
                    (bool, 'Destory r,g,b image', 'destory')]
     return True
コード例 #11
0
ファイル: filter.py プロジェクト: courins/imagepy
 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()
コード例 #12
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
コード例 #13
0
 def load(self, ips):
     titles = WindowsManager.get_titles()
     self.para['img1'] = titles[0]
     self.para['img2'] = titles[0]
     Match.view = [('lab', '=========  two image in 8-bit  ========='),
                   (list, titles, str, 'image1', 'img1', ''),
                   (list, titles, str, 'image2', 'img2', ''), ('lab', ''),
                   ('lab', '======  parameter about the surf  ======'),
                   (int, (0, 5), 0, 'octaves', 'oct', ''),
                   (int, (0, 5), 0, 'intervals', 'int', ''),
                   (int, (500, 2000), 0, 'threshold', 'thr', '1-100'),
                   (bool, 'extended', 'ext'), (bool, 'upright', 'upright'),
                   ('lab', ''),
                   ('lab', '======  how to match and display  ======'),
                   (list, ['None', 'Affine',
                           'H**o'], str, 'transform', 'trans', ''),
                   (int, (1, 5), 0, 'Std', 'std', 'torlerance'),
                   (list, ['Blue/Yellow',
                           'Hide'], str, 'Aspect', 'style', 'color'),
                   (bool, 'Show log', 'log')]
     return True
コード例 #14
0
ファイル: imageplus.py プロジェクト: shuxin/imagepy
 def set_title(self, title):
     self.title = WindowsManager.name(title)
コード例 #15
0
ファイル: panelconfig.py プロジェクト: shuxin/imagepy
 def add_img(self, title, key, unit):
     titles = WindowsManager.get_titles()
     self.add_choice(titles, str, title, key, unit)
     self.para[key] = titles[0]
     return True
コード例 #16
0
 def run(self, para=None):
     if para['name'] == 'All':
         for i in WindowsManager.get_titles():
             WindowsManager.close(i)
     else:
         WindowsManager.close(para['name'])
コード例 #17
0
ファイル: canvasframe.py プロジェクト: courins/imagepy
 def on_close(self, event):
     WindowsManager.remove(self)
     self.Destroy()
コード例 #18
0
ファイル: canvasframe.py プロジェクト: courins/imagepy
 def on_valid(self, event):
     if event.GetActive():
         WindowsManager.add(self)
コード例 #19
0
 def load(self):
     ImageKiller.para = {'name': 'All'}
     titles = ['All'] + WindowsManager.get_titles()
     ##!TODO: waht is the view ?
     ImageKiller.view = [(list, titles, str, 'Name', 'name', 'selected')]
     return True