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()
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'] })
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'
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()
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()
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()
def run(self, ips, snap, img, para=None): img[ips.get_msk()] = ColorManager.get_front(snap.ndim==2)
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())
def run(self, ips, snap, img, para=None): img[ips.get_msk()] = ColorManager.get_front(ips.channels!=3)