def load(self, ips):
     if not ips.is3d:
         IPy.alert('stack3d required!')
         return False
     self.buflut = ips.lut
     ips.lut = ips.lut.copy()
     return True
Beispiel #2
0
 def load(self, ips):
     if ips.roi is None or ips.roi.dtype != 'point':
         IPy.alert('need a point roi')
         return False
     self.buflut = ips.lut
     ips.lut = ips.lut.copy()
     return True
Beispiel #3
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.int16:
            IPy.alert('Label image must be in type 8-bit or 16-bit')
            return
        index = list(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 = list(zip(*data))
        IPy.table(ips.title + '-segment', data, titles)
Beispiel #4
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 = list(zip(imr.imgs, img.imgs, imb.imgs))
        for i in range(sr):
            self.progress(i, 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.show_img(rgb, 'rgb-merge')
        if self.para['destory']:
            for title in [para[i] for i in idx]:
                WindowsManager.close(title)
Beispiel #5
0
 def load(self, ips):
     titles = list(RoiManager.rois.keys())
     if len(titles) == 0:
         IPy.alert('No roi in manager!')
         return False
     self.para['name'] = titles[0]
     self.view = [(list, 'name', titles, str, 'Name', '')]
     return True
Beispiel #6
0
 def load(self, ips):
     if not ips.is3d:
         IPy.alert('stack3d required!')
         return False
     self.frame = myvi.Frame3D.figure(IPy.curapp, title='3D Canvas')
     self.buflut = ips.lut
     ips.lut = ips.lut.copy()
     return True
Beispiel #7
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()
            self.ips.update()
        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()
            self.ips.update()
        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()

        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()
            self.ips2.update()
            ips.mark.set_xy(x, y)
            ips.update()
Beispiel #8
0
	def load(self):
		try:
			from dulwich.repo import Repo
			from dulwich.client import get_transport_and_path
			self.repo, self.trans = Repo, get_transport_and_path
		except:
			IPy.alert('dulwich is needed, you can use Plugins > Install > Install Packages:\ndulwich --global-option="--pure" to install')
			return False
		return True
Beispiel #9
0
 def run(self, para = None):
     path = para['path']
     fp, fn = os.path.split(path)
     fn, fe = os.path.splitext(fn) 
     img = np.fromfile(para['path'], dtype=para['type'])
     sp = (para['h'], para['w'], para['c'])[:2 if para['c']==1 else 3]
     if img.size != para['h']*para['w']*para['c']:
         IPy.alert('raw data error!')
         return
     img.shape = sp
     IPy.show_img([img], fn)
Beispiel #10
0
 def run(self, ips, imgs, para = None):
     if para['kill']:
         ips.backimg = None
     else:
         img = WindowsManager.get(para['img']).ips.img
         if img.dtype != np.uint8 or img.shape[:2] != ips.img.shape[:2]:
             IPy.alert('a background image must be 8-bit and with the same size')
             return
         ips.backimg = img
         ips.backmode = (para['k'], para['op'])
     ips.update = 'pix'
Beispiel #11
0
 def load(self):
     plus = IPy.get_ips()
     if plus==None:
         img = np.ones((30,1), dtype=np.uint8) * np.arange(256, dtype=np.uint8)
         ips = ImagePlus([img], self.title)
         ips.lut = ColorManager.get_lut(self.title)
         IPy.show_ips(ips)
         return False
     elif plus.channels != 1:
         IPy.alert('RGB image do not surport Lookup table!')
         return False
     return True
Beispiel #12
0
 def load(self, ips):
     if not Predict.model is None: return True
     from keras.models import load_model
     try:
         path = osp.join(osp.abspath(osp.dirname(__file__)), 'U-net.h5')
         Predict.model = load_model(path)
     except Exception as e:
         IPy.alert('Not Found Net')
         return False
     #一定要预测一次,否则后面会出错
     Predict.model.predict(np.zeros((1, 224, 224, 1)))
     return True
Beispiel #13
0
    def run(self, ips, imgs, para=None):
        if not ('prjs' in ips.data and 'trans' in ips.data):
            return IPy.alert('need projection and transform matrix!')
        objs = ImageManager.get(para['fragments'])
        if not ('prjs' in objs.data and 'trans' in objs.data):
            return IPy.alert('need projection and transform matrix!')
        goal = (imgs[0], ips.data['prjs'][0], ips.data['trans'][0])
        rasters = zip(objs.imgs, objs.data['prjs'], objs.data['trans'])

        rst = geo_util.rasters2des(list(rasters), goal, para['step'])

        ips = ImagePlus([rst[0]], ips.title + '-combine')
        ips.data['prjs'], ips.data['trans'] = [rst[1]], [rst[2]]
        IPy.show_ips(ips)
Beispiel #14
0
    def run(self, para=None):
        rst = [
            'Questionnaire Result',
            'Name:%s' % para['name'],
            'Age:%s' % para['age'],
            'Height:%sm' % para['h'],
            'Weight:%skg' % para['w'],
            'Like Sport:%s' % para['sport'],
            'Favourite System:%s' % para['sys'],
            'Like lanuage:%s' % para['lan'],
            'Favourite Color:%s' % str(para['c'])
        ]

        IPy.alert('\r\n'.join(rst))
 def run(self, para=None):
     imp = IPy.get_ips()
     if imp is None:
         IPy.alert("Please open the image you want to classify", 'Error')
         return
     name = imp.title
     recent = fileio.recent
     for i in recent:
         pos1 = i.rfind(os.sep)
         pos2 = i.rfind('.')
         if name == i[pos1 + 1:pos2]:
             image = i
     className = dc4b.predict(image, self.framework, self.model)
     IPy.alert("The class which the image belongs is " + className,
               'Prediction')
Beispiel #16
0
    def run(self, ips, imgs, para=None):
        if not ('prj' in ips.data and 'trans' in ips.data):
            return IPy.alert('need projection and transform matrix!')
        objs = ImageManager.get(para['fragments'])
        if not ('prjs' in objs.data and 'trans' in objs.data):
            return IPy.alert('need projection and transform matrix!')

        goal = geo_struct.Raster(imgs, ips.data['prj'], ips.data['trans'])
        objs = zip(objs.imgs, objs.data['prjs'], objs.data['trans'])
        rasters = [geo_struct.Raster([i[0]], i[1], i[2]) for i in objs]
        rst = geo_util.rasters2one(rasters, goal, para['step'])

        ips = ImagePlus(rst.imgs, ips.title + '-combine')
        ips.data['prj'], ips.data['trans'] = goal.prj, goal.m
        IPy.show_ips(ips)
Beispiel #17
0
    def run(self, para = None):
        path = para['path']
        date = para['time']
        check = para['check']
        line = para['line']
        point = para['type'] == '点图'
        text = [para['t%d'%i] for i in (1,2,3,4,5,6,7,8)]
        text = [i for i in text if len(i)>1]

        try:
            rst = draw(path, date, text, point, line, check)
            if check: IPy.show_table(rst, '新增地名列表')
            else: IPy.show_img([rst], '草地贪夜蛾分布示意图')
        except: 
            IPy.alert('请检查数据格式!')
Beispiel #18
0
 def mouse_down(self, ips, x, y, btn, **key):
     if btn == 1:
         r, c = int(y), int(x)
         if r < 0 or r > ips.img.shape[0]: return
         if c < 0 or c > ips.img.shape[1]: return
         if ips.img[r, c] == 0: return
         lab, n = label(ips.img > 0)
         ips.img[lab == lab[r, c]] = (128, 255)[ips.img[r, c] != 255]
         ips.update()
     if btn == 3:
         img = getscr(ips.img, self.size)
         for i in range(len(ips.imgs)):
             ips.imgs[i][:] = generate(img, self.size)
             img = run(img)
         IPy.alert('Complete!')
Beispiel #19
0
 def on_remove(self, event):
     idx = self.lst_model.GetSelection()
     if idx == -1: return IPy.alert('no model selected!')
     os.remove(
         osp.join(IPy.root_dir,
                  'data/ilastik/%s' % self.lst_model.GetStringSelection()))
     self.LoadModel()
Beispiel #20
0
 def on_saveas(self, event):
     if manager.model_para is None:
         return IPy.alert('you must train your model first!')
     para = {'path': ''}
     filt = '|'.join(['%s files (*.%s)|*.%s' % ('FCL', 'fcl', 'fcl')])
     if not IPy.getpath('Save..', filt, 'save', para): return
     joblib.dump(manager.model_para, para['path'])
Beispiel #21
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'
Beispiel #22
0
    def run(self, para=None):
        fp, fn = os.path.split(para['path'])
        fn, fe = os.path.splitext(fn)
        read = ReaderManager.get(fe[1:])
        view = ViewerManager.get(fe[1:]) or show

        try:
            img = read(para['path'])
        except:
            IPy.alert('unknown img format!')
            return

        files = self.getfiles(para['path'])
        files.sort()
        imgs = self.readimgs(files[para['start']:para['end'] + 1:para['step']],
                             read, img.shape, img.dtype)
        view(imgs, para['title'])
Beispiel #23
0
    def run(self, ips, imgs, para=None):
        ips1 = ImageManager.get(para['img1'])
        ips2 = ImageManager.get(para['img2'])
        ips2.snapshot()

        img = ips1.img
        imgs = ips2.imgs

        sl1, sl2 = ips1.get_nslices(), ips2.get_nslices()
        cn1, cn2 = ips1.get_nchannels(), ips2.get_nchannels()
        if not (ips1.img.dtype == np.uint8 and ips2.img.dtype == np.uint8):
            IPy.alert('Two image must be type of 8-bit or rgb!')
            return

        for i in range(sl2):
            self.progress(i, sl2)
            match(img, imgs[i])
        ips2.update = 'pix'
Beispiel #24
0
	def run(self, ips, imgs, para = None):
		mats = TableManager.get(para['mat']).data.values
		if len(imgs) != len(mats):
			IPy.alert('image stack must has the same length as transfrom mats!')
			return
		newimgs = []
		img = np.zeros_like(ips.img, dtype=np.float64)
		for i in range(len(mats)):
			tform = tf.ProjectiveTransform(matrix=mats[i].reshape((3,3)))
			if imgs[i].ndim==2: 
				img[:] = tf.warp(imgs[i], tform)
			else:
				for c in range(img.shape[2]):
					img[:,:,c] = tf.warp(imgs[i][:,:,c], tform)
			img -= imgs[i].min(); img *= imgs[i].max() - imgs[i].min()
			if para['new']: newimgs.append(img.astype(ips.img.dtype))
			else: imgs[i] = img
			self.progress(i, len(mats))
		if para['new']: IPy.show_img(newimgs, '%s-trans'%ips.title)
Beispiel #25
0
 def __init__(self, ips=None, path=''):
     Simple.__init__(self, ips)
     self.model = None
     self.root = osp.join(IPy.root_dir, 'data/ilastik')
     fs = glob(osp.join(self.root, '*.fcl'))
     fs = [osp.split(i)[1] for i in fs]
     if '/' in path: fs = [path]
     if len(fs) == 0: return IPy.alert('No feature classfier found!')
     self.para['predictor'] = fs[0]
     self.view[0] = (list, 'predictor', fs, str, 'predictor', '')
Beispiel #26
0
 def run(self, ips, imgs, para = None):
     idx = ['red','green','blue']
     print(para)
     imr,img,imb = [ImageManager.get(para[i]) 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' or \
         imr.size!=img.size or img.size!=imb.size or sr!=sg or sg!=sb:
         IPy.alert('three images must be 8-bit image, with the same size and  slices!')
         return
         
     rgbs = []
     w,h = imr.size
     for i in range(sr):
         self.progress(i,sr)
         rgbs.append(self.trans(imr.imgs[i], img.imgs[i], imb.imgs[i]))
     IPy.show_img(rgbs, self.titles()[0])
     if self.para['destory']:
         for title in [para[i] for i in idx]:
             WindowsManager.get(title).close()
Beispiel #27
0
 def on_rename(self, event):
     idx = self.lst_model.GetSelection()
     if idx == -1: return IPy.alert('no model selected!')
     para = {'name': 'New Model'}
     if not IPy.get_para('name', [(str, 'name', 'model', 'name')], para):
         return
     oldname = osp.join(
         IPy.root_dir,
         'data/ilastik/%s' % self.lst_model.GetStringSelection())
     os.rename(oldname,
               osp.join(IPy.root_dir, 'data/ilastik/%s.fcl' % para['name']))
     self.LoadModel()
Beispiel #28
0
 def on_save(self, event):
     if manager.model_para is None:
         return IPy.alert('you must train your model first!')
     para = {'name': 'New Model'}
     if not IPy.get_para('name', [(str, 'name', 'model', 'name')], para):
         return
     if not osp.exists(osp.join(IPy.root_dir, 'data/ilastik')):
         os.mkdir(osp.join(IPy.root_dir, 'data/ilastik'))
     joblib.dump(
         manager.model_para,
         osp.join(IPy.root_dir, 'data/ilastik/%s.fcl' % para['name']))
     self.LoadModel()
    def run(self, para=None):
        imp = IPy.get_ips()
        if imp is None:
            IPy.alert("Please open the image you want to classify", 'Error')
            return
        name = imp.title
        recent = fileio.recent
        for i in recent:
            pos1 = i.rfind(os.sep)
            pos2 = i.rfind('.')
            if name == i[pos1 + 1:pos2]:
                image = i

        subprocess.check_output([
            self.python, self.pathAPI + 'predict.py', '-i', image, '-f',
            self.framework, '-m', self.model
        ])
        data = json.load(open('data.json'))
        className = data['class']
        IPy.alert("The class which the image belongs is " + className,
                  'Prediction')
Beispiel #30
0
 def on_export(self, event):
     idx = self.lst_model.GetSelection()
     if idx == -1: return IPy.alert('no model selected!')
     para = {'path': ''}
     filt = '|'.join(['%s files (*.%s)|*.%s' % ('FCL', 'fcl', 'fcl')])
     if not IPy.getpath('Save..', filt, 'save', para): return
     oldname = osp.join(
         IPy.root_dir,
         'data/ilastik/%s' % self.lst_model.GetStringSelection())
     print(para['path'])
     shutil.copyfile(oldname, para['path'])
     self.LoadModel()