def _show_img(self, img, title=None): cframe = CanvasFrame(self, True) canvas = cframe.canvas if not title is None: canvas.set_imgs(img) canvas.image.name = title else: canvas.set_img(img) cframe.Bind(wx.EVT_ACTIVATE, self.on_new_img) cframe.Bind(wx.EVT_CLOSE, self.on_close_img) cframe.Show()
def _show_img(self, img, title=None): cframe = CanvasFrame(self, True) canvas = cframe.canvas if not isinstance(img, Image): img = Image(img, title) App.show_img(self, img, img.title) cframe.Bind(wx.EVT_ACTIVATE, self.on_active_img) cframe.Bind(wx.EVT_CLOSE, self.on_close_img) canvas.set_img(img) cframe.SetIcon(self.GetIcon()) cframe.Show()
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()
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()
import sys sys.path.append('../../') from sciapp.object import mark2shp, Layer, json2shp from sciapp.action import PolygonROI, LineROI, PointROI, EllipseROI, RectangleROI, FreeLineROI, FreePolygonROI from sciwx.canvas import CanvasFrame from skimage.data import astronaut, camera from sciapp.object import ROI, Line import wx ellipse = {'type':'ellipse', 'body':(100,100,100,-50,1)} rectangles = {'type':'rectangles', 'body':[(100,100,80,50),(200,200,80,100)]} layer = {'type':'layer', 'num':-1, 'color':(0,0,255), 'fill':False, 'body':[rectangles, ellipse]} if __name__ == '__main__': app = wx.App() frame = CanvasFrame(None) frame.canvas.set_img(camera()) roi = ROI([Line([(0,0),(100,100),(300,500)])]) frame.canvas.image.roi = roi bar = frame.add_toolbar() bar = frame.add_toolbar() bar.add_tool('P', PointROI) bar.add_tool('L', LineROI) bar.add_tool('M', PolygonROI) bar.add_tool('R', RectangleROI) bar.add_tool('O', EllipseROI) bar.add_tool('S', FreeLineROI) bar.add_tool('&', FreePolygonROI) frame.Show() app.MainLoop()
def __init__ (self, parent): CanvasFrame.__init__(self, parent) App.__init__(self) self.Bind(wx.EVT_ACTIVATE, self.init_image)
def canvas_frame_test(): cf = CanvasFrame(None, autofit=True) cf.set_imgs([camera(), 255 - camera()]) cf.Show()