se = self.oldp + (y, x) rs, cs = line(*[int(i) for i in se]) rs.clip(0, ips.shape[1], out=rs) cs.clip(0, ips.shape[0], out=cs) ips.img[rs, cs] = 255 self.oldp = (y, x) key['canvas'].update() def mouse_wheel(self, ips, x, y, d, **key): pass if __name__ == '__main__': from skimage.data import camera, astronaut from skimage.io import imread app = wx.App() cf = CanvasFrame(None, autofit=False) cf.set_imgs([camera(), 255 - camera()]) cf.set_cn(0) bar = cf.add_menubar() bar.load(('menu', [ ('Filter', [('Gaussian', Gaussian), ('Unto', Undo)]), ])) bar = cf.add_toolbar() bar.add_tool('M', DefaultTool) bar.add_tool('P', Pencil) cf.Show() app.MainLoop()
np.clip(cs, 0, img.shape[1] - 1, out=cs) color = (np.mean(color), color)[img.ndim == 3] w = self.para['win'] for r, c in zip(rs, cs): 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) clip = img[slice(*sr), slice(*sc)] if (clip[r, c] - color).sum() == 0: continue lab = felzenszwalb(clip, 1, 0, self.para['ms']) clip[flood(lab, (r, c), connectivity=2)] = color self.oldp = (y, x) ips.update() if __name__ == '__main__': from skimage.data import camera, astronaut from skimage.io import imread app = wx.App() cf = CanvasFrame(None, autofit=False) cf.set_imgs([astronaut(), 255 - astronaut()]) cf.set_cn((0, 1, 2)) bar = cf.add_toolbar() bar.add_tool('M', DefaultTool) bar.add_tool('A', AIPen) cf.Show() app.MainLoop()
def canvas_frame_test(): cf = CanvasFrame(None, autofit=True) cf.set_imgs([camera(), 255 - camera()]) cf.Show()