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
def gray(self, hist): panel = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) back = wx.BoxSizer( wx.VERTICAL ) back.Add(panel, 1, wx.EXPAND) sizer = wx.BoxSizer( wx.VERTICAL ) histc = HistCanvas(panel) histc.set_hist(hist) txt = wx.StaticText( panel, wx.ID_ANY, 'Channel:'+'Gray', wx.DefaultPosition, wx.DefaultSize, 0 ) sizer.Add( txt, 0, wx.LEFT|wx.RIGHT, 8 ) sizer.Add( histc, 0, wx.LEFT|wx.RIGHT, 8 ) mean, lim = np.dot(hist, range(256))/hist.sum(), np.where(hist>0)[0] sta = 'Statistic: Mean:%s Min:%s Max:%s'%(mean.round(1), lim.min(), lim.max()) txt = wx.StaticText( panel, wx.ID_ANY, sta, wx.DefaultPosition, wx.DefaultSize, 0 ) sizer.Add( txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 8 ) panel.SetSizer( sizer ) self.SetSizer(back) self.Fit()
def rgb(self, hist): panel = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) back = wx.BoxSizer( wx.VERTICAL ) back.Add(panel, 1, wx.EXPAND) sizer = wx.BoxSizer( wx.VERTICAL ) rgb = ['Red', 'Green', 'Blue'] for i in (0,1,2): histc = HistCanvas(panel) histc.SetValue(hist[i]) txt = wx.StaticText( panel, wx.ID_ANY, 'Channel:'+ rgb[i], wx.DefaultPosition, wx.DefaultSize, 0 ) sizer.Add( txt, 0, wx.LEFT|wx.RIGHT, 8 ) sizer.Add( histc, 0, wx.LEFT|wx.RIGHT, 8 ) mean, lim = np.dot(hist[i], range(256))/hist[i].sum(), np.where(hist[i]>0)[0] sta = 'Statistic: Mean:%s Min:%s Max:%s'%(mean.round(1), lim.min(), lim.max()) txt = wx.StaticText( panel, wx.ID_ANY, sta, wx.DefaultPosition, wx.DefaultSize, 0 ) sizer.Add( txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 8 ) panel.SetSizer( sizer ) self.SetSizer(back) self.Fit()
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 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)
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
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)] 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
def init_view(self, items, para, hist, arange): self.range = arange self.histcvs = HistCanvas(self) self.histcvs.set_hist(hist) self.add_ctrl('hist', self.histcvs) ParaDialog.init_view(self, items, para, True)