Exemplo n.º 1
0
 def run(self, ips, imgs, para = None):
     if ips.isarray: imgs = imgs.copy()
     else: imgs = [i.copy() for i in imgs]
     back = Image(imgs)
     back.cn, back.rg = ips.cn, ips.rg
     ips.back = back
     ips.mode = para['k'] if para['mode']=='ratial' else para['mode']
Exemplo n.º 2
0
    def run(self, ips, imgs, para=None, preview=False):
        if len(ips.imgs) == 1: ips.img[:] = ips.snap
        key = {'chans': None, 'grade': para['grade'], 'w': para['w']}
        key['items'] = [i for i in ['ori', 'blr', 'sob', 'eig'] if para[i]]
        slir, slic = ips.rect
        labs = [i[slir, slic] for i in imgs]
        ori = ips.back.imgs
        oris = [i[slir, slic] for i in ori]

        self.app.info('extract features...')
        feat, lab, key = feature.get_feature(oris,
                                             labs,
                                             key,
                                             callback=self.progress)

        self.app.info('training data...')
        # self.progress(None, 1)
        model = self.classify(para)
        model.fit(feat, lab)

        self.app.info('predict data...')
        if preview:
            return feature.get_predict(oris,
                                       model,
                                       key,
                                       labs,
                                       callback=self.progress)
        if len(imgs) == 1: ips.swap()
        outs = feature.get_predict(oris, model, key, callback=self.progress)
        nips = Image(outs, ips.title + 'rst')
        nips.range, nips.lut = ips.range, ips.lut
        nips.back, nips.mode = ips.back, 0.4
        self.app.show_img(nips)
        global model_para
        model_para = model, key
Exemplo n.º 3
0
 def run(self, para=None):
     first = generate(np.zeros((para['height'], para['width'])),
                      para['size'])
     imgs = [first.copy() for i in range(para['slice'])]
     ips = Image(imgs, para['name'])
     ips.tool = Painter(para['size'])
     self.app.show_img(ips)
Exemplo n.º 4
0
def image_canvas_test():
    obj = Image()
    obj.img = camera()
    obj.cn = 0

    frame = wx.Frame(None, title='gray test')
    canvas = ICanvas(frame, autofit=True)
    canvas.set_img(obj)
    frame.Show()
Exemplo n.º 5
0
def image_mcanvas_test():
    obj = Image()
    obj.imgs = [astronaut(), 255 - astronaut()]
    obj.cn = 0

    frame = wx.Frame(None, title='gray test')
    canvas = MCanvas(frame, autofit=True)
    canvas.set_img(obj)
    frame.Show()
Exemplo n.º 6
0
 def run(self, ips, imgs, para=None):
     if not para['slice']: imgs = [ips.img]
     shift = fftshift if para['shift'] else lambda x: x
     rst = []
     for i in range(len(imgs)):
         rst.append(shift(fft2(imgs[i])))
         self.progress(i, len(imgs))
     ips = Image(rst, '%s-fft' % ips.title)
     ips.log = True
     self.app.show_img(ips)
Exemplo n.º 7
0
 def run(self, ips, imgs, para=None):
     if '/' in para['predictor']: path = para['predictor']
     else: path = self.root + '/' + para['predictor']
     model, key = joblib.load(path)
     if not para['slice']: imgs = [ips.img]
     slir, slic = ips.rect
     imgs = [i[slir, slic] for i in imgs]
     rst = feature.get_predict(imgs, model, key, callback=self.progress)
     if rst is None:
         return self.app.alert('image channels dismatch this predictor!')
     ips = Image(rst, ips.title + '-mark')
     ips.range = ips.get_updown('all', 'one', step=512)
     self.app.show_img(ips)
Exemplo n.º 8
0
 def _show_img(self, img, title=None):
     print(img)
     canvas = self.canvasnb.add_canvas()
     if not isinstance(img, Image):
         img = Image(img, title)
     App.show_img(self, img, img.title)
     canvas.set_img(img)
Exemplo 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 = Image(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(para['cm'])
     newips.mode = modes[idx.index(para['mode'])]
     #newips.range = (0, para['n'])
     self.app.show_img(newips)
Exemplo n.º 10
0
def action_demo5():
    app = App()
    image = Image([camera()], 'camera')
    app.show_img(image, 'camera')
    Gaussian().start(app)

    plt.subplot(121).imshow(camera())
    plt.subplot(122).imshow(image.img)
    plt.show()
Exemplo n.º 11
0
    def run(self, ips, imgs, para = None):
        if not para['slice']:  imgs = [ips.img]
        labels = []
        for i in range(len(imgs)):
            self.progress(i, len(imgs))
            con = 1 if para['con']=='4-Connect' else 2
            idx = connect.connect_graph(imgs[i], con, para['back'])
            idx = connect.mapidx(idx)
            cmap = render.node_render(idx, para['colors'], 10)

            lut = np.ones(imgs[i].max()+1, dtype=np.uint8)
            lut[0] = 0
            for j in cmap: lut[j] = cmap[j]
            labels.append(lut[imgs[i]])

        ips = Image(labels, ips.title+'-render')
        ips.range = (0, para['colors'])
        self.app.show_img(ips) 
Exemplo n.º 12
0
 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()
Exemplo n.º 13
0
 def run(self, para=None):
     ips = self.app.get_img()
     if ips == None:
         img = np.arange(256 * 30, dtype=np.uint8).reshape((-1, 256))
         ips = Image([img], self.title)
         ips.lut = self.lut
         return self.app.show_img(ips)
     if ips.channels != 1:
         return self.app.alert(
             'only one channel image surport Lookup table!')
     ips.lut = self.lut
     ips.update()
Exemplo n.º 14
0
 def run(self, ips, imgs, para=None):
     if not para['stack']: imgs = [ips.img]
     sli = ips.rect
     imgs = [i[sli].copy() for i in imgs]
     if ips.isarray: imgs = np.array(imgs)
     new = Image(imgs, ips.name + '-duplicate')
     if not ips.roi is None:
         new.roi = ROI(mark2shp(ips.roi.to_mark()))
         offset(new.roi, new.roi.box[0] * -1, new.roi.box[1] * -1)
         new.roi.dirty = True
     if not ips.back is None and not ips.back.imgs is None:
         back = [i[sli].copy() for i in ips.back.imgs]
         if ips.isarray: back = np.array(back)
         back = Image(back, ips.back.name + '-duplicate')
         back.cn, back.rg, back.mode = ips.back.cn, ips.back.rg, ips.back.mode
         new.back, new.mode = back, ips.mode
         self.app.show_img(back)
     self.app.show_img(new)
Exemplo n.º 15
0
def object_test():
    '''
    there is a manager for every type of object.
    such as img_manager, we can call app's:
    show_img, close_img, active_img, get_img
    '''
    from sciapp.object import Image
    from skimage.data import camera

    app = App()
    image = Image([camera()], 'camera')
    app.show_img(image, 'camera')
    # >>> UINT8  512x512  S:1/1  C:0/1  0.25M
    print(app.get_img())
    # >>> <sciapp.object.image.Image object at 0x000002076A025780>
    print(app.img_names())
    # >>> ['camera']
    app.close_img('camera')
    # >>> close image: camera
    print(app.img_names())
Exemplo n.º 16
0
def complex_test():
    frame = wx.Frame(None, title='blend')
    canvas = Canvas(frame, autofit=True)
    canvas.set_img(fftshift(fft2(camera())))
    canvas.set_rg((0, 31015306))
    canvas.set_log(True)
    frame.Show()


if __name__ == '__main__':
    app = wx.App()
    #gray_test()
    #rgb_test()
    #rgb_gray_blend()
    #complex_test()
    frame = wx.Frame(None, title='blend')
    canvas = Canvas(frame, autofit=True)
    image = Image()
    image.img = camera()
    image.pos = (0, 0)
    canvas.images.append(image)

    image = Image()
    image.img = astronaut()
    image.pos = (100, 200)
    image.cn = (0, 1, 2)
    canvas.images.append(image)
    frame.Show()
    app.MainLoop()