def process(self): intensity = self.intensity_spin.value() invert = self.invert_check.isChecked() equalize = self.equalize_check.isChecked() blue_mode = self.blue_combo.currentIndex() dx, dy = cv.spatialGradient(cv.cvtColor(self.image, cv.COLOR_BGR2GRAY)) if invert: dx = -dx dy = -dy red = ((dx.astype(np.float32) / np.max(np.abs(dx)) * 127) + 127).astype(np.uint8) green = ((dy.astype(np.float32) / np.max(np.abs(dy)) * 127) + 127).astype(np.uint8) if blue_mode == 0: blue = np.zeros_like(red) elif blue_mode == 1: blue = np.full_like(red, 255) elif blue_mode == 2: blue = normalize_mat(np.linalg.norm(cv.merge((red, green)), axis=2)) else: blue = None gradient = cv.merge([blue, green, red]) if intensity > 0: gradient = cv.LUT(gradient, create_lut(intensity, intensity)) if equalize: gradient = equalize_image(gradient) self.grad_viewer.update_processed(gradient)
def process(self): minmax = np.zeros_like(self.image) minimum = self.min_combo.currentIndex() maximum = self.max_combo.currentIndex() radius = self.filter_spin.value() if radius > 0: start = time() radius += 2 if minimum < 4: low = self.blk_filter(self.low, radius) if minimum <= 2: minmax[:, :, 2 - minimum] = low else: minmax = np.repeat(low[:, :, np.newaxis], 3, axis=2) if maximum < 4: high = self.blk_filter(self.high, radius) if maximum <= 2: minmax[:, :, 2 - maximum] += high else: minmax += np.repeat(high[:, :, np.newaxis], 3, axis=2) minmax = normalize_mat(minmax) self.info_message.emit( self.tr('Min/Max Filter = {}'.format(elapsed_time(start)))) else: if minimum == 0: minmax[self.low] = [0, 0, 255] elif minimum == 1: minmax[self.low] = [0, 255, 0] elif minimum == 2: minmax[self.low] = [255, 0, 0] elif minimum == 3: minmax[self.low] = [255, 255, 255] if maximum == 0: minmax[self.high] = [0, 0, 255] elif maximum == 1: minmax[self.high] = [0, 255, 0] elif maximum == 2: minmax[self.high] = [255, 0, 0] elif maximum == 3: minmax[self.high] = [255, 255, 255] self.viewer.update_processed(minmax)