Esempio n. 1
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)
Esempio n. 2
0
	def run(self, ips, imgs, para = None):
		k = para['diag']/np.sqrt((np.array(ips.img.shape)**2).sum())
		size = tuple((np.array(ips.img.shape)*k).astype(np.int16))
		IPy.set_info('down sample...')
		news = []
		for img in imgs:
			if k!=0: img = tf.resize(img, size)
			if para['sigma']!=0:
				img = ndimg.gaussian_filter(img, para['sigma'])
			news.append(img)

		IPy.set_info('register...')
		sr = StackReg(eval('StackReg.%s'%para['trans']))
		sr.register_stack(np.array(news), reference=para['ref'])

		mats = sr._tmats.reshape((sr._tmats.shape[0],-1))
		if k!=0: mats[:,[0,1,3,4,6,7]] *= k
		if k!=0: mats[:,[0,1,2,3,4,5]] /= k

		if para['tab']: IPy.show_table(pd.DataFrame(
			mats, columns=['A%d'%(i+1) for i in range(mats.shape[1])]), title='%s-Tmats'%ips.title)

		if para['new'] == 'None': return
		IPy.set_info('transform...')
		for i in range(sr._tmats.shape[0]):
			tform = tf.ProjectiveTransform(matrix=sr._tmats[i])
			img =  tf.warp(imgs[i], tform)
			img -= imgs[i].min(); img *= imgs[i].max() - imgs[i].min()
			if para['new'] == 'Inplace': imgs[i][:] = img
			if para['new'] == 'New': news[i] = img.astype(ips.img.dtype)
			self.progress(i, len(imgs))
		if para['new'] == 'New': IPy.show_img(news, '%s-reg'%ips.title)
Esempio n. 3
0
	def run(self, para = None):
		#imgs = readGif(para['path'])

		imgs = imageio.mimread(para['path'])
		fp, fn = os.path.split(para['path'])
		fn, fe = os.path.splitext(fn) 
		IPy.show_img(imgs, fn)
Esempio n. 4
0
 def run(self, para=None):
     w, h = para['width'], para['height']
     channels = (1, 3)[para['type'] == 'RGB']
     slices = para['slice']
     shape = (h, w, channels) if channels != 1 else (h, w)
     imgs = [np.zeros(shape, dtype=np.uint8) for i in range(slices)]
     IPy.show_img(imgs, para['name'])
Esempio n. 5
0
 def run(self, para=None):
     img = self.data()
     if isinstance(img, tuple):
         return IPy.show_img(list(img), self.title)
     if img.dtype == np.bool:
         img.dtype = np.uint8
         img *= 255
     IPy.show_img([img], self.title)
Esempio n. 6
0
 def run(self, para=None):
     if len(para['chans']) == 0: return
     shp, prj, m, chans = gio.read_raster_box(para['path'])
     idx = [chans.index(i) for i in para['chans']]
     print(para['chans'], idx, '==========')
     files = self.getfiles(para['path'])
     rasters = self.readimgs(files, idx, shp)
     IPy.show_img(rasters, para['title'])
Esempio n. 7
0
 def run(self, ips, imgs, para=None):
     IPy.show_img(
         hessian(imgs,
                 range(para['start'], para['end'], para['step']),
                 alpha=para['alpha'],
                 beta=para['beta'],
                 gamma=para['gamma'],
                 black_ridges=para['bridges']), ips.title + '-hessian')
Esempio n. 8
0
 def run(self, ips, imgs, para=None):
     if not para['slice']: imgs = [ips.img]
     shift = fftshift if para['shift'] else lambda x: x
     rst = []
     for i in range(len(imgs)):
         rst.append(shift(fft2(imgs[i])))
         self.progress(i, len(imgs))
     IPy.show_img(rst, '%s-fft' % ips.title)
Esempio n. 9
0
	def run(self, para = None):
		imgs = readGif(para['path'])
		for i in range(len(imgs)):
			if imgs[i].ndim==3 and imgs[i].shape[2]>3:
				imgs[i] = imgs[i][:,:,:3].copy()
		fp, fn = os.path.split(para['path'])
		fn, fe = os.path.splitext(fn) 
		IPy.show_img(imgs, fn)
Esempio n. 10
0
 def run(self, ips, imgs, para=None):
     cmap = ColorManager.luts[para['LUT']]
     imglut = color_code(imgs[para['Start image'] - 1:para['End image']],
                         cmap)
     IPy.show_img([imglut], 'Color-coded %s' % ips.title)
     if para['Creatbar']:
         cmapshow = np.ones([32, 256, 3]) * cmap
         IPy.show_img([cmapshow.astype('uint8')], 'Color bar')
Esempio n. 11
0
 def run(self, para=None):
     try:
         response = urlopen('http://imagej.net/images/' + self.name)
         stream = StringIO(response.read())
         img = imread(stream)
         IPy.show_img([img], self.title)
     except Exception as e:
         IPy.write('Open url failed!\tErrof:%s' % sys.exc_info()[1])
Esempio n. 12
0
 def run(self, ips, snap, img, para=None):
     ips.lut = self.buflut
     pts = np.where(ips.get_msk())
     msk = grayselect(snap, pts, para['sigma'], para['cov'])
     if para['within']: msk = within(msk, pts)
     if para['msk'] == 'clear out': img[~msk] = ips.range[0]
     if para['new']:
         msk = np.multiply(msk, 255, dtype=np.uint8)
         IPy.show_img([msk], ips.title + '-graymsk')
Esempio n. 13
0
 def run(self, tps, snap, data, para=None):
     table = TableManager.get(para['temp']).get_subtab()
     box = gutil.shp2box(table, para['scale']
                         or (para['width'], para['height']), para['mar'])
     chans = list(data['channels'][0])
     chans = [chans.index(i) for i in para['chans']]
     order = {'nearest': 0, 'linear': 1}[para['order']]
     rst = gmt.match_idx(data, box, chans, step=para['step'], order=order)
     IPy.show_img([rst], tps.title + '-merge')
Esempio n. 14
0
 def run(self, ips, imgs, para=None):
     table = TableManager.get(para['temp']).get_subtab()
     box = gutil.shp2box(table, para['scale']
                         or (para['width'], para['height']), para['mar'])
     chans = ['Channel %s' % i for i in range(ips.get_nchannels())]
     chans = [chans.index(i) for i in para['chans']]
     order = {'nearest': 0, 'linear': 1}[para['order']]
     rst = gmt.match_multi(imgs, box, chans, step=para['step'], order=order)
     IPy.show_img([rst], ips.title + '-merge')
Esempio n. 15
0
    def run(self, para=None):
        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')
        X, Y, Z = axes3d.get_test_data(0.05)
        ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
        plt.show()

        #area = (area-5) * 8
        IPy.show_img([(Z + 80).astype(np.uint8)], '3D Surface')
Esempio n. 16
0
 def run(self, ips, imgs, para=None):
     if not para['slice']: imgs = [ips.img]
     shift = ifftshift if para['shift'] else lambda x: x
     tp = {'uint8': np.uint8, 'int': np.int32, 'float': np.float32}
     rst, tp = [], tp[para['type']]
     for i in range(len(imgs)):
         rst.append(ifft2(shift(ips.img)).astype(tp))
         self.progress(i, len(imgs))
     IPy.show_img(rst, '%s-ifft' % ips.title)
Esempio n. 17
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.int16)

        IPy.show_img([msk[0]], ips.title + '-label')
Esempio n. 18
0
 def run(self, ips, imgs, para=None):
     nr, ng, nb = [], [], []
     for i in range(ips.get_nslices()):
         nrgb = self.trans(imgs[i])
         nr.append(nrgb[:, :, 0])
         ng.append(nrgb[:, :, 1])
         nb.append(nrgb[:, :, 2])
         self.progress(i, len(imgs))
     for im, tl in zip([nr, ng, nb], self.titles()):
         IPy.show_img(im, ips.title + '-' + tl)
Esempio n. 19
0
 def run(self, ips, imgs, para = None):
     if not para['slice']:  imgs = [ips.img]
     labels = []
     for i in range(len(imgs)):
         self.progress(i, len(imgs))
         con = 1 if para['con']=='4-Connect' else 2
         strc = generate_binary_structure(2, con)
         lab, n = label(imgs[i], strc, output = np.int32)
         labels.append(lab)
     IPy.show_img(labels, ips.title+'-label') 
Esempio n. 20
0
 def run(self, tps, snap, data, para=None):
     img = ImageManager.get(para['temp']).img
     chans = list(data['channels'][0])
     chans = [chans.index(i) for i in para['chans']]
     nimg = gmt.match_idx(data,
                          img,
                          step=para['step'],
                          order=para['order'],
                          chan=chans)
     IPy.show_img([nimg], tps.title + '-match')
Esempio n. 21
0
 def run(self, ips, imgs, para=None):
     if not para['slice']: imgs = [ips.img]
     tp = {'uint8': np.uint8, 'int': np.int32, 'float': np.float32}
     rst, tp = [], tp[para['type']]
     for i in range(len(imgs)):
         zs = np.log(np.abs(imgs[i]))
         zs /= np.log(para['log'])
         rst.append(zs.astype(tp))
         self.progress(i, len(imgs))
     IPy.show_img(rst, '%s-fft' % ips.title)
Esempio n. 22
0
 def run(self, ips, imgs, para=None):
     ips.lut = self.buflut
     idx = np.array(ips.roi.body).astype(np.uint16).T
     pts = (idx[2], idx[1], idx[0])
     msk = grayselect(imgs, pts, para['sigma'], para['cov'])
     if para['within']: msk = within(msk, pts)
     if para['msk'] == 'clear out': imgs[~msk] = ips.range[0]
     if para['new']:
         msk = np.multiply(msk, 255, dtype=np.uint8)
         IPy.show_img(msk, ips.title + '-graymsk')
Esempio n. 23
0
 def run(self, ips, snap, img, para=None):
     img[:] = snap
     pts = np.where(ips.get_msk())
     msk = colorselect(snap, pts, para['sigma'], para['cov'])
     if para['within']: msk = within(msk, pts)
     if para['msk'] == 'red': img[msk] = (255, 0, 0)
     if para['msk'] == 'dark out': img[~msk] //= 3
     if para['new']:
         msk = np.multiply(msk, 255, dtype=np.uint8)
         IPy.show_img([msk], ips.title + '-colormsk')
Esempio n. 24
0
 def run(self, ips, imgs, para=None):
     if not para['slice']: imgs = [ips.img]
     copy = np.copy if para['copy'] else lambda x: x
     imags, reals = [], []
     for i in range(len(imgs)):
         reals.append(copy(imgs[i].real))
         imags.append(copy(imgs[i].imag))
         self.progress(i, len(imgs))
     IPy.show_img(reals, '%s-real' % ips.title)
     IPy.show_img(imags, '%s-image' % ips.title)
Esempio n. 25
0
 def run(self, ips, imgs, para=None):
     r, g, b = [], [], []
     for i, n in zip(imgs, list(range(ips.get_nslices()))):
         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])
         self.progress(i, n)
     for im, tl in zip([r, g, b], ['red', 'green', 'blue']):
         IPy.show_img(im, ips.title + '-' + tl)
     if self.para['destory']:
         ImageManager.close(ips.title)
Esempio n. 26
0
 def run(self, ips, imgs, para = None):
     if not para['slice']:  imgs = [ips.img]
     labels = []
     for i in range(len(imgs)):
         self.progress(i, len(imgs))
         con = 1 if para['con']=='4-Connect' else 2
         bound = find_boundaries(imgs[i], con, para['mode'])
         bound.dtype = np.uint8
         bound *= 255
         labels.append(bound)
     IPy.show_img(labels, ips.title+'-boundary') 
Esempio n. 27
0
 def run(self, ips, imgs, para=None):
     if not para['stack']: imgs = [ips.img]
     ips.swap()
     rst = []
     for i in range(len(imgs)):
         rst.append(
             segmentation.felzenszwalb(imgs[i], para['scale'],
                                       para['sigma'],
                                       para['min_size']).astype('int32'))
         self.progress(i, len(imgs))
     IPy.show_img(rst, ips.title + '-felzenszwalblab')
Esempio n. 28
0
 def run(self, ips, imgs, para=None):
     if not para['stack']: imgs = [ips.img]
     ips.swap()
     rst = []
     for i in range(len(imgs)):
         rst.append(
             segmentation.slic(imgs[i], para['n_segments'],
                               para['compactness'], para['max_iter'],
                               para['sigma']).astype('int32'))
         self.progress(i, len(imgs))
     IPy.show_img(rst, ips.title + '-sliclab')
Esempio n. 29
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)
Esempio n. 30
0
 def run(self, para=None):
     try:
         fp, fn = os.path.split(para['url'])
         fn, fe = os.path.splitext(fn)
         response = urlopen(para['url'])
         ## TODO: Fixme!
         stream = StringIO(response.read())
         img = imread(stream)
         IPy.show_img([img], fn)
     except Exception as e:
         IPy.write('Open url failed!\tErrof:%s' % sys.exc_info()[1])