def process(self, input_images, connected_outs): if 'Input' not in input_images: return FAIL if self.getParamContent("Log") == "Yes": do_log = True else: do_log = False if self.getParamContent("Normalize") == "Yes": normalize = True else: normalize = False if self.hist_fig is None: self.hist_fig = plt.figure(figsize=(4, 2), dpi=100) self.hist_axis = self.hist_fig.add_subplot(111) self.hist_axis.tick_params(labelsize=8) self.hist_axis.grid(True) width = self.getParamContent('Display width (pixels)') height = self.getParamContent('Display height (pixels)') if width != self.last_width: self.hist_fig.set_figwidth(width / 100) self.last_width = width if height != self.last_height: self.hist_fig.set_figheight(height / 100) self.last_height = height src = input_images['Input'] no_of_bins = int(self.getParamContent("# of bins")) if src.flags['C_CONTIGUOUS'] == False: src = numpy.ascontiguousarray(src, 'f') if src.dtype != 'f' and src.dtype != 'uint8': src = src.astype('f') mini = float(numpy.amin(src)) maxi = float(numpy.amax(src)) hist_vals = cv2.calcHist([src], [0], None, [no_of_bins], [mini, maxi]) x_vals = numpy.arange(mini, maxi, (maxi - mini) / no_of_bins) if do_log: hist_vals = numpy.log(hist_vals) if normalize: hist_vals = hist_vals / numpy.amax(hist_vals) if self.getParamContent("Plot histogram") == "Yes": x2plt, hist2plt = histOutline(hist_vals, x_vals) self.abortQuery() # self.hist_axis.clear() if self.hist_curve is None: self.hist_curve = self.hist_axis.plot(x2plt, hist2plt, 'k')[0] else: self.hist_curve.set_data(x2plt, hist2plt) self.hist_axis.set_xlim(x2plt.min(), x2plt.max()) self.hist_axis.set_ylim(hist2plt.min(), hist2plt.max()) # self.setParamContent("Histogram plot",self.hist_fig, emitSignal=True) self.abortQuery() self.pixmap = arr2pixmap(plotfig2image(self.hist_fig)) return {'Histogram': hist_vals, 'Bins': numpy.hstack((x_vals, [maxi]))}
def process(self, input_images, connected_outs): if 'Input' not in input_images: return FAIL if self.getParamContent("Log") == "Yes": do_log = True else: do_log = False if self.getParamContent("Normalize") == "Yes": normalize = True else: normalize = False if self.hist_fig is None: self.hist_fig = plt.figure(figsize=(4, 2), dpi=100) self.hist_axis = self.hist_fig.add_subplot(111) self.hist_axis.tick_params(labelsize=8) self.hist_axis.grid(True) width = self.getParamContent('Display width (pixels)') height = self.getParamContent('Display height (pixels)') if width!=self.last_width: self.hist_fig.set_figwidth(width/100) self.last_width=width if height!=self.last_height: self.hist_fig.set_figheight(height/100) self.last_height=height src = input_images['Input'] no_of_bins = int(self.getParamContent("# of bins")) if src.flags['C_CONTIGUOUS'] == False: src = numpy.ascontiguousarray(src, 'f') if src.dtype != 'f' and src.dtype != 'uint8': src = src.astype('f') mini = float(numpy.amin(src)) maxi = float(numpy.amax(src)) hist_vals = cv2.calcHist([src],[0],None,[no_of_bins],[mini,maxi]) x_vals = numpy.arange(mini,maxi,(maxi-mini)/no_of_bins) if do_log: hist_vals = numpy.log(hist_vals) if normalize: hist_vals = hist_vals/numpy.amax(hist_vals) if self.getParamContent("Plot histogram") == "Yes": x2plt,hist2plt = histOutline(hist_vals,x_vals) self.abortQuery() # self.hist_axis.clear() if self.hist_curve is None: self.hist_curve = self.hist_axis.plot(x2plt,hist2plt,'k')[0] else: self.hist_curve.set_data(x2plt,hist2plt) self.hist_axis.set_xlim(x2plt.min(),x2plt.max()) self.hist_axis.set_ylim(hist2plt.min(), hist2plt.max()) # self.setParamContent("Histogram plot",self.hist_fig, emitSignal=True) self.abortQuery() self.pixmap = arr2pixmap(plotfig2image(self.hist_fig)) return {'Histogram':hist_vals, 'Bins':numpy.hstack((x_vals,[maxi]))}
def process(self, input_images, connected_outs): """Return a black&white image if something is connected to the B&W input, otherwise return an RGB-image with unconnected channels zeroed (pure black). """ names = self.input_names if len(input_images) == 0: self.pixmap = None return {} processed_images = {} if names[0] in input_images: bw_rgb = input_images[names[0]] if not (bw_rgb.ndim == 3 and bw_rgb.shape[2] == 3) and bw_rgb.ndim > 2: print "In '%s': Multichannel image must have 3 channels to display." % self.name return FAIL else: processed_images[names[0]] = bw_rgb else: for i, channel in enumerate([self.i_ch1, self.i_ch2, self.i_ch3]): if channel in input_images: ch_im = input_images[channel] if ch_im.ndim == 3 and ch_im.shape[2] == 3: try: processed_images[channel] = ch_im[:, :, i] except ValueError: print "Can not display image in '%s' unless all channels have the same dimensions." % ( self.name) return FAIL elif ch_im.ndim > 2: print "In '%s': Multichannel image must have 3 channels to display." % self.name return FAIL else: processed_images[channel] = input_images[channel] res_images = self.resizeQuery(processed_images) disp_im = self.constructFinal(res_images) try: self.pixmap = arr2pixmap(disp_im) except Exception as e: print e return {}
def process(self, input_images, connected_outs): """Return a black&white image if something is connected to the B&W input, otherwise return an RGB-image with unconnected channels zeroed (pure black). """ names = self.input_names if len(input_images)==0: self.pixmap = None return {} processed_images = {} if names[0] in input_images: bw_rgb = input_images[names[0]] if not (bw_rgb.ndim == 3 and bw_rgb.shape[2] == 3) and bw_rgb.ndim > 2: print "In '%s': Multichannel image must have 3 channels to display." %self.name return FAIL else: processed_images[names[0]] = bw_rgb else: for i,channel in enumerate([self.i_ch1, self.i_ch2, self.i_ch3]): if channel in input_images: ch_im = input_images[channel] if ch_im.ndim == 3 and ch_im.shape[2] == 3: try: processed_images[channel] = ch_im[:,:,i] except ValueError: print "Can not display image in '%s' unless all channels have the same dimensions." %(self.name) return FAIL elif ch_im.ndim > 2: print "In '%s': Multichannel image must have 3 channels to display." %self.name return FAIL else: processed_images[channel] = input_images[channel] res_images = self.resizeQuery(processed_images) disp_im = self.constructFinal(res_images) try: self.pixmap = arr2pixmap(disp_im) except Exception as e: print e return {}