Esempio n. 1
0
 def mouse_up(self, ips, x, y, btn, **key):
     if btn == 1 and (y, x) == self.pickp and key['ctrl']:
         x = int(round(min(max(x, 0), ips.img.shape[1])))
         y = int(round(min(max(y, 0), ips.img.shape[0])))
         ColorManager.set_front(ips.img[y, x])
     self.status = None
     ips.mark = None
     ips.update()
Esempio n. 2
0
 def mouse_down(self, ips, x, y, btn, **key):
     FloodFill3D().start({
         'seed': (ips.cur, int(y), int(x)),
         'color': np.mean(ColorManager.get_front()),
         'conn': (self.para['con'] == '8-connect') + 1,
         'tor': self.para['tor']
     })
Esempio n. 3
0
 def mouse_move(self, ips, x, y, btn, **key):
     if not self.status:return
     w = self.para['width']
     value = ColorManager.get_front()
     drawline(ips.img, self.oldp, (y, x), w, value)
     self.oldp = (y, x)
     ips.update()
Esempio n. 4
0
 def on_clear(self, event):
     ips = IPy.get_ips()
     if ips is None: return
     hist = ips.histogram()
     self.curvepan.set_hist(hist)
     ips.lut = ColorManager.get_lut()
     ips.update = 'pix'
Esempio n. 5
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'
Esempio n. 6
0
	def run(self, tps, data, snap, para = None):
		rs = data[para['rs']] * para['s'] if para['rs'] != 'None' else para['s']
		cs = data[para['cs']] if para['cs'] != 'None' else '#%.2x%.2x%.2x'%para['c']
		cm = ColorManager.get_lut(para['cm'])/255.0
		cm = None if para['cs'] == 'None' else colors.ListedColormap(cm, N=256)
		data.plot.scatter(x=para['x'], y=para['y'], s=rs, c=cs, alpha=para['alpha'], 
			cmap=cm, grid=para['grid'], title=para['title'])
		plt.show()
Esempio n. 7
0
 def mouse_down(self, ips, x, y, btn, **key):
     ips.snapshot()
     msk = floodfill(ips.img, x, y, self.para['tor'], self.para['con']=='8-connect')
     #plt.imshow(msk)
     #plt.show()
     color = ColorManager.get_front()
     if ips.get_nchannels()==1:color = np.mean(color)
     ips.img[msk] = color
     ips.update = 'pix'
Esempio n. 8
0
    def mouse_move(self, ips, x, y, btn, **key):
        if self.status == None and ips.mark != None:
            ips.mark = None
            ips.update()
        if not self.status in [
                'local_pen', 'local_brush', 'local_sketch', 'local_in',
                'local_out', 'move'
        ]:
            return
        img, color = ips.img, ColorManager.get_front()
        x = int(round(min(max(x, 0), img.shape[1])))
        y = int(round(min(max(y, 0), img.shape[0])))

        if self.status == 'move':
            x, y = key['canvas'].to_panel_coor(x, y)
            key['canvas'].move(x - self.oldp[0], y - self.oldp[1])
            self.oldp = x, y
            ips.update()
            print('move')
            return

        rs, cs = line(*[int(round(i)) for i in self.oldp + (y, x)])
        np.clip(rs, 0, img.shape[0] - 1, out=rs)
        np.clip(cs, 0, img.shape[1] - 1, out=cs)

        color = (np.mean(color), color)[img.ndim == 3]

        for r, c in zip(rs, cs):
            start = time()
            w = self.para['win']
            sr = (max(0, r - w), min(img.shape[0], r + w))
            sc = (max(0, c - w), min(img.shape[1], c + w))
            r, c = min(r, w), min(c, w)
            backclip = imgclip = img[slice(*sr), slice(*sc)]
            if not ips.back is None:
                backclip = ips.back.img[slice(*sr), slice(*sc)]

            if self.status == 'local_pen':
                local_pen(imgclip, r, c, self.para['r'], color)
            if self.status == 'local_brush':
                if (imgclip[r, c] - color).sum() == 0: continue
                local_brush(imgclip, backclip, r, c, color, 0, self.para['ms'])
            if self.status == 'local_in':
                local_in_fill(imgclip, r, c, self.para['r'], self.pickcolor,
                              color)
            if self.status == 'local_sketch':
                local_sketch(imgclip, r, c, self.para['r'], self.pickcolor,
                             color)
            if self.status == 'local_out':
                local_out_fill(imgclip, r, c, self.para['r'], self.pickcolor,
                               color)

        ips.mark = self.make_mark(x, y)
        self.oldp = (y, x)
        ips.update()
Esempio n. 9
0
 def run(self, ips, imgs, para = None):
     shp = ips.img.shape[:2]
     imgs = [np.zeros(shp, dtype=np.uint8) for i in range([1, len(imgs)][para['slice']])]
     newips = ImagePlus(imgs, ips.title+'-mark')
     newips.back = ips
     idx = ['None', 'Max', 'Min', 'Mask', '2-8mix', '4-6mix', '5-5mix', '6-4mix', '8-2mix']
     modes = ['set', 'max', 'min', 'msk', 0.2, 0.4, 0.5, 0.6, 0.8]
     newips.lut = ColorManager.get_lut(para['cm'])
     newips.chan_mode = modes[idx.index(para['mode'])]
     #newips.range = (0, para['n'])
     IPy.show_ips(newips)
Esempio n. 10
0
 def mouse_down(self, ips, x, y, btn, **key):
     ips.snapshot()
     img, color = ips.img, ColorManager.get_front()
     connectivity=(self.para['con']=='8-connect')+1
     img = ips.img.reshape((ips.img.shape+(1,))[:3])
     msk = np.ones(img.shape[:2], dtype=np.bool)
     for i in range(img.shape[2]):
         msk &= flood(img[:,:,i], (int(y),int(x)), 
             connectivity=connectivity, tolerance=self.para['tor'])
     img[msk] = np.mean(color) if img.shape[2]==1 else color
     ips.update()
Esempio n. 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
Esempio n. 12
0
    def on_cmapsel(self, event):
        key = self.cmapsel.GetValue()
        lut = ColorManager.get_lut(key)
        n = self.spn_num.GetValue() + 1
        idx = np.linspace(0, 255, n).astype(int)
        cs = list(lut[idx]) + [(128, 128, 128)] * (16 - n)
        for btn, c in zip(self.btns, cs):
            btn.SetBackgroundColour(c)

        ips = ImageManager.get()
        if ips is None: return
        newlut = lut * 0
        newlut[:n] = lut[idx]
        ips.lut = newlut
        ips.update()
Esempio n. 13
0
    def mouse_down(self, ips, x, y, btn, **key):
        if btn == 2:
            self.oldp = key['canvas'].to_panel_coor(x, y)
            self.status = 'move'
            return

        self.oldp = self.pickp = (y, x)
        color = ColorManager.get_front()
        x = int(round(min(max(x, 0), ips.img.shape[1])))
        y = int(round(min(max(y, 0), ips.img.shape[0])))
        color = (np.mean(color), color)[ips.img.ndim == 3]
        self.pickcolor = ips.img[y, x]
        ips.snapshot()

        if btn == 1 and key['ctrl'] and key['alt']:
            self.status = 'local_out'
        elif btn == 1 and key['ctrl']:
            self.status = 'local_pen'
        elif btn == 1 and key['alt']:
            self.status = 'local_sketch'
        elif btn == 1 and key['shift']:
            self.status = 'local_in'
        elif btn == 1:
            self.status = 'local_brush'
        elif btn == 3 and key['ctrl'] and key['alt']:
            self.status = 'global_out_fill'
            global_out_fill(ips.img, y, x, color)
            ips.update()
        elif btn == 3 and key['ctrl']:
            self.status = 'global_out_line'
            global_out_line(ips.img, y, x, color)
            ips.update()
        elif btn == 3 and key['alt']:
            self.status = 'global_in_line'
            global_in_line(ips.img, y, x, color)
            ips.update()
        elif btn == 3 and key['shift']:
            self.status = 'global_in_fill'
            global_in_fill(ips.img, y, x, color)
            ips.update()
        elif btn == 3:
            if (ips.img[y, x] - color).sum() == 0: return
            conn = {'4-connect': 1, '8-connect': 2}
            conn = conn[self.para['con']]
            tor = self.para['tor']
            fill_normal(ips.img, y, x, color, conn, tor)
            ips.update()
Esempio n. 14
0
    def run(self, ips, snap, img, para = None):
        strc = generate_binary_structure(2, 1 if para['con']=='4-connect' else 2)

        lab, n = label(snap, strc, output=np.uint32)
        idx = (np.zeros(n+1)).astype(np.uint8)
        ls = regionprops(lab)
        
        if para['pro'] == 'area': ps = [i.area for i in ls]
        if para['pro'] == 'perimeter': ps = [i.perimeter for i in ls]
        if para['pro'] == 'solid': ps = [i.solidity for i in ls]
        if para['pro'] == 'eccentricity': ps = [i.major_axis_length/i.minor_axis_length for i in ls]

        ps = np.array(ps)
        if ps.max() != ps.min():
            ps = (ps - ps.min()) / (ps.max() - ps.min())
        else: ps = ps / ps.max()
        idx[1:] = ps * 245 + 10
        img[:] = idx[lab]
        ips.lut = ColorManager.get_lut(para['cm'])
Esempio n. 15
0
 def on_color(self, event):
     ColorManager.set_front(self.btns.index(event.GetEventObject()))
Esempio n. 16
0
 def run(self, ips, snap, img, para=None):
     img[ips.get_msk()] = ColorManager.get_front(ips.channels!=3)
Esempio n. 17
0
 def run(self, ips, snap, img, para=None):
     img[ips.get_msk('out')] = ColorManager.get_back(ips.channels!=3)
Esempio n. 18
0
 def run(self, para=None):
     plus = IPy.get_ips()
     plus.lut = ColorManager.get_lut(self.title)
     plus.update = 'pix'
Esempio n. 19
0
 def run(self, ips, snap, img, para=None):
     img[ips.get_msk('out')] = ColorManager.get_back(snap.ndim==2)
Esempio n. 20
0
 def run(self, ips, snap, img, para=None):
     img[ips.get_msk()] = ColorManager.get_front(snap.ndim==2)
Esempio n. 21
0
 def mouse_down(self, ips, x, y, btn, **key):
     if btn == 1: ColorManager.set_front(ips.img[int(y), int(x)])
     if btn == 3: ColorManager.set_back(ips.img[int(y), int(x)])
     print(ips.img[int(y), int(x)])
     print(ColorManager.get_front())
Esempio n. 22
0
	def on_cmapsel(self):
		ips = IPy.get_ips()
		if ips is None: return
		key = self.cmapsel.GetValue()
		ips.lut = ColorManager.get_lut(key)
		ips.update = 'pix'
Esempio n. 23
0
 def config(self):
     ColorManager.set_front(self.para['front'])
     ColorManager.set_back(self.para['back'])