def _process(self, overlay, key=None): if len(overlay) != 2: raise Exception("colorizeHSV required an overlay of two Image elements as input.") if (len(overlay[0].value_dimensions), len(overlay[1].value_dimensions)) != (1,1): raise Exception("Each Image element must have single value dimension.") if overlay[0].shape != overlay[1].shape: raise Exception("Mismatch in the shapes of the data in the Image elements.") hue = overlay[1] Hdim = hue.value_dimensions[0] H = hue.clone(hue.data.copy(), value_dimensions=[Hdim(cyclic=True, range=hue.range(Hdim.name))]) normfn = raster_normalization.instance() if self.p.input_ranges: S = normfn.process_element(overlay[0], key, *self.p.input_ranges) else: S = normfn.process_element(overlay[0], key) C = Image(np.ones(hue.data.shape), bounds=self.get_overlay_bounds(overlay), group='F', label='G') C.value_dimensions[0].range = (0,1) S.value_dimensions[0].range = (0,1) return HSV(H * C * S).relabel(group=self.p.group)
def _process(self, overlay, key=None): if len(overlay) != 2: raise Exception( "colorizeHSV required an overlay of two Image elements as input." ) if (len(overlay.get(0).vdims), len(overlay.get(1).vdims)) != (1, 1): raise Exception( "Each Image element must have single value dimension.") if overlay.get(0).shape != overlay.get(1).shape: raise Exception( "Mismatch in the shapes of the data in the Image elements.") hue = overlay.get(1) Hdim = hue.vdims[0] H = hue.clone(hue.data.copy(), vdims=[Hdim(cyclic=True, range=hue.range(Hdim.name))]) normfn = raster_normalization.instance() if self.p.input_ranges: S = normfn.process_element(overlay.get(0), key, *self.p.input_ranges) else: S = normfn.process_element(overlay.get(0), key) C = Image(np.ones(hue.data.shape), bounds=self.get_overlay_bounds(overlay), group='F', label='G') C.vdims[0].range = (0, 1) S.vdims[0].range = (0, 1) return HSV(H * C * S).relabel(group=self.p.group)
def _process(self, overlay, key=None): normfn = raster_normalization.instance() if self.p.input_ranges: overlay = normfn.process_element(overlay, key, *self.p.input_ranges) else: overlay = normfn.process_element(overlay, key) hue, confidence = overlay.get(0), overlay.get(1) strength_data = overlay.get(2).data if (len(overlay) == 3) else np.ones(hue.shape) hue_data = hue.data hue_range = hue.value_dimensions[0].range if (not hue.value_dimensions[0].cyclic) or (None in hue_range): raise Exception("The input hue channel must be declared cyclic with a defined range.") if hue.shape != confidence.shape: raise Exception("Cannot combine input Matrices with different shapes.") (h,s,v)= (hue_data, (confidence.data * self.p.C_multiplier).clip(0.0, 1.0), (strength_data * self.p.S_multiplier).clip(0.0, 1.0)) if self.p.flipSC: (h,s,v) = (h,v,s.clip(0,1.0)) return RGB(np.dstack(hsv_to_rgb(h,s,v)), bounds = self.get_overlay_bounds(overlay), label = self.get_overlay_label(overlay), group = self.p.group)
def _process(self, matrix, key=None): normfn = raster_normalization.instance() if self.p.input_ranges: matrix = normfn.process_element(matrix, key, *self.p.input_ranges) else: matrix = normfn.process_element(matrix, key) fft_spectrum = abs(np.fft.fftshift(np.fft.fft2(matrix.data - 0.5, s=None, axes=(-2, -1)))) fft_spectrum = 1 - fft_spectrum # Inverted spectrum by convention zero_min_spectrum = fft_spectrum - fft_spectrum.min() spectrum_range = fft_spectrum.max() - fft_spectrum.min() spectrum = (self.p.max_power * zero_min_spectrum) / spectrum_range l, b, r, t = matrix.bounds.lbrt() density = matrix.xdensity bounds = BoundingBox(radius=(density/2)/(r-l)) return Image(spectrum, bounds=bounds, label=matrix.label, group=self.p.group)
def _process(self, overlay, key=None): if len(overlay) != 2: raise Exception("The similarity index may only be computed" "using overlays of Image Views.") mat1, mat2 = overlay.get(0), overlay.get(1) val_dims = [mat1.value_dimensions, mat2.value_dimensions] if tuple(len(el) for el in val_dims) != (1,1): raise Exception("Both input Matrices must have single value dimension.") if False in [val_dims[0][0].cyclic, val_dims[1][0].cyclic]: raise Exception("Both input Matrices must be defined as cyclic.") normfn = raster_normalization.instance() overlay = normfn.process_element(overlay, key) return Image(self.difference(overlay.get(0).data, overlay.get(1).data), bounds=self.get_overlay_bounds(overlay), group=self.p.value)