예제 #1
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
예제 #2
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)
예제 #3
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)