def run(self, para=None): if para['name'] == 'All': for i in ImageManager.get_titles(): WindowsManager.get(i).close() else: print(WindowsManager.get(para['name'])) WindowsManager.get(para['name']).close()
def run(self, ips, snap, img, para = None): intenimg = WindowsManager.get(para['inten']).ips.img strc = ndimage.generate_binary_structure(2, 1 if para['con']=='4-connect' else 2) buf, n = ndimage.label(snap, strc, output=np.uint16) index = range(1, n+1) idx = (np.ones(n+1)*para['front']).astype(np.uint8) msk = np.ones(n, dtype=np.bool) if para['mean']>0: msk *= ndimage.mean(intenimg, buf, index)>=para['mean'] if para['mean']<0: msk *= ndimage.mean(intenimg, buf, index)<-para['mean'] if para['max']>0: msk *= ndimage.maximum(intenimg, buf, index)>=para['max'] if para['max']<0: msk *= ndimage.maximum(intenimg, buf, index)<-para['max'] if para['min']>0: msk *= ndimage.minimum(intenimg, buf, index)>=para['min'] if para['min']<0: msk *= ndimage.minimum(intenimg, buf, index)<-para['min'] if para['sum']>0: msk *= ndimage.sum(intenimg, buf, index)>=para['sum'] if para['sum']<0: msk *= ndimage.sum(intenimg, buf, index)<-para['sum'] if para['std']>0: msk *= ndimage.standard_deviation(intenimg, buf, index)>=para['std'] if para['std']<0: msk *= ndimage.standard_deviation(intenimg, buf, index)<-para['std'] xy = ndimage.center_of_mass(intenimg, buf, index) xy = np.array(xy).round(2).T idx[1:][~msk] = para['back'] idx[0] = 0 img[:] = idx[buf] WindowsManager.get(para['inten']).ips.mark = RGMark((xy.T, msk)) WindowsManager.get(para['inten']).ips.update = True
def run(self, ips, imgs, para = None): ips1 = WindowsManager.get(para['img1']).ips ips2 = WindowsManager.get(para['img2']).ips ips1.snapshot() 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 channels!') 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.img, ips2.img, mode=para['op']) elif sl1>1 and sl2==1: for i in range(sl1): self.progress(i, sl1) bliter.blit(ips1.imgs[i], ips2.img, mode=para['op']) elif sl1>1 and sl2>1: for i in range(sl1): self.progress(i, sl1) bliter.blit(ips1.imgs[i], ips2.imgs[i], mode=para['op']) ips1.update = 'pix'
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)
def run(self, ips, imgs, para=None): r, g, b = [], [], [] for i, n in zip(imgs, list(range(ips.get_nslices()))): self.progress(i, n) 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]) for im, tl in zip([r, g, b], ['red', 'green', 'blue']): IPy.show_img(im, ips.title + '-' + tl) if self.para['destory']: WindowsManager.close(ips.title)
def run(self, ips, imgs, para=None): r, g, b = [], [], [] for i, n in zip(imgs, list(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)
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)
def load(self, ips): titles = WindowsManager.get_titles() self.para['img1'] = titles[0] self.para['img2'] = titles[0] Match.view = [(list, titles, str, 'template', 'img1', ''), (list, titles, str, 'object', 'img2', '')] return True
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 = [], [] strc = np.array([[0,1,0],[1,1,1],[0,1,0]], dtype=np.uint8) for i in range(len(imgs)): label(msks[i], strc, output=buf) ls = regionprops(buf, imgs[i]) dt = [[i]*len(ls), list(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(list(zip(*dt))) ips.mark = Mark(mark) IPy.table(ips.title+'-region', data, titles)
def run(self, ips, imgs, para=None): ips1 = WindowsManager.get(para['img1']).ips ips2 = WindowsManager.get(para['img2']).ips 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'
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
def run(self, ips, imgs, para = None): msk = ips.get_msk('in') if ips.imgtype == 'rgb': img = ips.img if msk is None else ips.img[msk] hist = [np.histogram(img[:,:,i], np.arange(257))[0] for i in (0,1,2)] else: img = ips.lookup() if msk is None else ips.lookup()[msk] hist = np.histogram(img, np.arange(257))[0] show_hist(WindowsManager.get(), ips.title+'-Histogram', hist)
def load(self, ips): titles = WindowsManager.get_titles() self.para['red'] = titles[0] self.para['green'] = titles[0] self.para['blue'] = titles[0] Merge.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
def on_back(self, event): self.com_back.SetItems(['None'] + ImageManager.get_titles()) cur = WindowsManager.get() if not cur is None: cur = cur.back if not cur is None: cur = cur.title self.com_back.SetValue(str(cur)) modes = ['set', 'max', 'min', 'msk', 0.2, 0.4, 0.5, 0.6, 0.8] ips = ImageManager.get() if ips is None: self.com_mode.Select(0) else: self.com_mode.Select(modes.index(ips.chan_mode))
def run(self, ips, imgs, para=None): print(ips.imgtype, ips.imgtype == '8-bit') if ips.imgtype == 'rgb': hist = [ np.histogram(ips.img[:, :, i], np.arange(257))[0] for i in (0, 1, 2) ] else: hist = np.histogram(ips.lookup(), np.arange(257))[0] show_hist(WindowsManager.get(), ips.title + '-Histogram', hist)
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()
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'
def run(self, ips, imgs, para = None): inten = WindowsManager.get(para['inten']).ips if not para['slice']: imgs = [inten.img] msks = [ips.img] else: msks = ips.imgs if len(msks)==1: msks *= len(imgs) buf = imgs[0].astype(np.uint16) strc = ndimage.generate_binary_structure(2, 1 if para['con']=='4-connect' else 2) idct = ['Max','Min','Mean','Variance','Standard','Sum'] key = {'Max':'max','Min':'min','Mean':'mean', 'Variance':'var','Standard':'std','Sum':'sum'} idct = [i for i in idct if para[key[i]]] titles = ['Slice', 'ID'][0 if para['slice'] else 1:] if para['center']: titles.extend(['Center-X','Center-Y']) if para['extent']: titles.extend(['Min-Y','Min-X','Max-Y','Max-X']) titles.extend(idct) k = ips.unit[0] data, mark = [], [] for i in range(len(imgs)): n = ndimage.label(msks[i], strc, output=buf) index = range(1, n+1) dt = [] if para['slice']:dt.append([i]*n) dt.append(range(n)) xy = ndimage.center_of_mass(imgs[i], buf, index) xy = np.array(xy).round(2).T if para['center']:dt.extend([xy[1]*k, xy[0]*k]) boxs = [None] * n if para['extent']: boxs = ndimage.find_objects(buf) boxs = [(i[0].start, i[1].start, i[0].stop, i[1].stop) for i in boxs] for j in (0,1,2,3): dt.append([i[j]*k for i in boxs]) if para['max']:dt.append(ndimage.maximum(imgs[i], buf, index).round(2)) if para['min']:dt.append(ndimage.minimum(imgs[i], buf, index).round(2)) if para['mean']:dt.append(ndimage.mean(imgs[i], buf, index).round(2)) if para['var']:dt.append(ndimage.variance(imgs[i], buf, index).round(2)) if para['std']:dt.append(ndimage.standard_deviation(imgs[i], buf, index).round(2)) if para['sum']:dt.append(ndimage.sum(imgs[i], buf, index).round(2)) mark.append([(center, cov) for center,cov in zip(xy.T, boxs)]) data.extend(list(zip(*dt))) IPy.table(inten.title+'-region statistic', data, titles) inten.mark = Mark(mark) inten.update = True
def run(self, ips, imgs, para=None): ips1 = WindowsManager.get(para['img1']).ips ips2 = WindowsManager.get(para['img2']).ips detector = CVSURF(hessianThreshold=para['thr'], nOctaves=para['oct'], nOctaveLayers=para['int'], upright=para['upright'], extended=para['ext']) kps1, feats1 = detector.detectAndCompute(ips1.img, None) kps2, feats2 = detector.detectAndCompute(ips2.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
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
def run(self, para=None): if para['name'] == 'All': for i in WindowsManager.get_titles(): WindowsManager.close(i) else: WindowsManager.close(para['name'])
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
def on_setback(self, event): name = self.com_back.GetValue() if name is None: return curwin = WindowsManager.get() curwin.set_back(ImageManager.get(name)) curwin.ips.update()
def run(self, ips, imgs, para = None): temp = WindowsManager.get(para['temp']).ips rst = gmt.match_multi(imgs, temp.img.getbox()) IPy.show_img([rst], ips.title+'-match')
def run(self, ips, imgs, para = None): WindowsManager.get().canvas.save_buffer(para['path'])