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 = True self.ips.update = True 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 = True self.ips.update = True 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 = True 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 = True self.ips2.update = True ips.mark.set_xy(x, y) ips.update = True
def run(self, ips, imgs, para = None): name = self.para['name'] if ips.get_nslices()==1 or self.para['stack']==False: if ips.roi == None: img = ips.get_img().copy() ipsd = ImagePlus([img], name) else: img = ips.get_subimg().copy() ipsd = ImagePlus([img], name) box = ips.roi.get_box() ipsd.roi = ips.roi.affine(np.eye(2), (-box[0], -box[1])) elif ips.get_nslices()>1 and self.para['stack']: if ips.roi == None: if ips.is3d:imgs=imgs.copy() else:imgs = [i.copy() for i in imgs] else: sc, sr = ips.get_rect() if ips.is3d: imgs=imgs[:, sc, sr].copy() else: imgs = [i[sc,sr].copy() for i in imgs] ipsd = ImagePlus(imgs, name) ipsd.roi = ips.roi.affine(np.eye(2), (-sr.start, -sc.start)) frame = CanvasFrame(IPy.curapp) frame.set_ips(ipsd) frame.Show()
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)
def show_img(imgs, title): from imageplus import ImagePlus from ui.canvasframe import CanvasFrame ips = ImagePlus(imgs, title) frame = CanvasFrame(curapp) frame.set_ips(ips) frame.Show()
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'
def run(self, para=None): w, h = para['width'], para['height'] chanels = (1, 3)[para['type'] == 'RGB'] slices = para['slice'] shape = (h, w, chanels) if chanels != 1 else (h, w) imgs = [np.zeros(shape, dtype=np.uint8) for i in range(slices)] ips = ImagePlus(imgs, para['name']) frame = CanvasFrame(IPy.curapp) frame.set_ips(ips) frame.Show()
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.uint16) nips = ImagePlus([msk[0]], ips.title + '-label') frame = CanvasFrame(IPy.curapp) frame.set_ips(nips) frame.Show()
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)
x = (x - self.box[0] - self.imgbox[0]) y = (y - self.box[1] - self.imgbox[1]) return (x / self.get_scale(), y / self.get_scale()) def to_panel_coor(self, x, y): x = x * self.get_scale() + self.imgbox[0] + self.box[0] y = y * self.get_scale() + self.imgbox[1] + self.box[1] return x, y if __name__ == '__main__': import sys sys.path.append('../') import numpy as np from imageplus import ImagePlus from scipy.misc import imread img = imread('../imgs/flower.jpg') app = wx.PySimpleApp() frame = wx.Frame(None) canvas = Canvas(frame) ips = ImagePlus(img) canvas.set_ips(ips) canvas.fit = frame canvas.set_handler(TestTool()) frame.Fit() frame.Show(True) app.MainLoop() #r1 = [0,0,20,10] #r2 = [1,2,10,10]
class Orthogonal(Tool): def __init__(self): self.view1, self.view2 = None, None self.ips1, self.ips2 = None, None self.ips = None title = 'Orthogonal View' def getimgs(self, img, x, y): return img[:, :, int(x)].transpose((1,0,2)[:len(img.shape)-1]).copy(), \ img[:, int(y), :].copy() 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 = True self.ips.update = True 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 = True self.ips.update = True 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 = True 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 = True self.ips2.update = True ips.mark.set_xy(x, y) ips.update = True def mouse_up(self, ips, x, y, btn, **key): pass def mouse_move(self, ips, x, y, btn, **key): if btn == 1: img1, img2 = self.getimgs(ips.imgs, x, y) self.ips1.set_imgs([img1]) self.ips2.set_imgs([img2]) self.ips1.update = True self.ips2.update = True ips.update = True ips.mark.set_xy(x, y) def mouse_wheel(self, ips, x, y, d, **key): pass
def show_img(imgs, title): from imageplus import ImagePlus ips = ImagePlus(imgs, title) showips(ips) '''MT
def show_img(imgs, title): ips = ImagePlus(imgs, title) showips(ips) '''MT