class ThresholdDialog(ParaDialog): def init_view(self, items, para, hist): self.histcvs = HistCanvas(self) self.histcvs.set_hist(hist) self.add_ctrl('hist', self.histcvs) ParaDialog.init_view(self, items, para, True) def para_check(self, para, key): mid = 128 - para['bright'] length = 255 / np.tan(para['contrast'] / 180.0 * np.pi) self.histcvs.set_lim(mid - length / 2, mid + length / 2) self.reset() return True
class ThresholdDialog(ParaDialog): def init_view(self, items, para, hist, lim): self.histcvs = HistCanvas(self) self.histcvs.set_hist(hist) self.lim = lim self.add_ctrl('hist', self.histcvs) ParaDialog.init_view(self, items, para, True) def para_check(self, para, key): if key=='thr1':para['thr2'] = max(para['thr1'], para['thr2']) if key=='thr2':para['thr1'] = min(para['thr1'], para['thr2']) lim1 = 1.0 * (para['thr1'] - self.lim[0])/(self.lim[1]-self.lim[0]) lim2 = 1.0 * (para['thr2'] - self.lim[0])/(self.lim[1]-self.lim[0]) self.histcvs.set_lim(lim1*255, lim2*255) self.reset() return True
class Balance_Dialog(ParaDialog): def init_view(self, para, view, img): hists = [ np.histogram(img[:, :, i], list(range(257)))[0] for i in (0, 1, 2) ] hists = [(i * (100.0 / i.max())).astype(np.uint8) for i in hists] self.redcvs = HistCanvas(self) self.redcvs.set_hist(hists[0]) self.greencvs = HistCanvas(self) self.greencvs.set_hist(hists[1]) self.bluecvs = HistCanvas(self) self.bluecvs.set_hist(hists[2]) self.add_ctrl('red', self.redcvs) self.parse(view[0]) self.parse(view[1]) self.add_ctrl('green', self.greencvs) self.parse(view[2]) self.parse(view[3]) self.add_ctrl('blue', self.bluecvs) self.parse(view[4]) self.parse(view[5]) self.add_check('Preview', 'preview') self.add_confirm(True) self.reset(para) self.pack() def para_check(self, para, key): self.redcvs.set_lim(para['t1_red'], para['t2_red']) self.greencvs.set_lim(para['t1_green'], para['t2_green']) self.bluecvs.set_lim(para['t1_blue'], para['t2_blue']) if key == 't1_red': para['t2_red'] = max(para['t2_red'], para['t1_red']) if key == 't2_red': para['t1_red'] = min(para['t2_red'], para['t1_red']) if key == 't1_green': para['t2_green'] = max(para['t2_green'], para['t1_green']) if key == 't2_green': para['t1_green'] = min(para['t2_green'], para['t1_green']) if key == 't1_blue': para['t2_blue'] = max(para['t2_blue'], para['t1_blue']) if key == 't2_blue': para['t1_blue'] = min(para['t2_blue'], para['t1_blue']) self.reset() return True
class Balance_Dialog(ParaDialog): def init_view(self, para, view, img): hists = [ np.histogram(img[:, :, i], list(range(257)))[0] for i in (0, 1, 2) ] hists = [(i * (100.0 / i.max())).astype(np.uint8) for i in hists] self.redcvs = HistCanvas(self) self.redcvs.set_hist(hists[0]) self.greencvs = HistCanvas(self) self.greencvs.set_hist(hists[1]) self.bluecvs = HistCanvas(self) self.bluecvs.set_hist(hists[2]) self.add_ctrl('red', self.redcvs) self.parse(view[0]) self.parse(view[1]) self.add_ctrl('green', self.greencvs) self.parse(view[2]) self.parse(view[3]) self.add_ctrl('blue', self.bluecvs) self.parse(view[4]) self.parse(view[5]) self.add_check('Preview', 'preview') self.add_confirm(True) self.reset(para) self.pack() def para_check(self, para, key): mid = 128 - para['b_red'] length = 255 / np.tan(para['c_red'] / 180.0 * np.pi) self.redcvs.set_lim(mid - length / 2, mid + length / 2) mid = 128 - para['b_green'] length = 255 / np.tan(para['c_green'] / 180.0 * np.pi) self.greencvs.set_lim(mid - length / 2, mid + length / 2) mid = 128 - para['b_blue'] length = 255 / np.tan(para['c_blue'] / 180.0 * np.pi) self.bluecvs.set_lim(mid - length / 2, mid + length / 2) self.reset() return True