Exemple #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
Exemple #2
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)
Exemple #3
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)