def _projection(input1: Layer, operation_name: str = cle.maximum_z_projection.__name__, myself=None): if input1 is not None: # execute operation cle_input1 = cle.push(input1.data) output = None operation = cle.operation(operation_name) output = _call_operation_ignoring_to_many_arguments( operation, [cle_input1, output]) output = cle.pull(output).astype(int) # show result in napari if not hasattr(myself, 'layer'): if isinstance(input1, Labels): myself.viewer.add_labels(output, translate=input1.translate[1:3]) else: myself.viewer.add_image(output, translate=input1.translate[1:3]) else: myself.layer.data = output myself.layer.contrast_limits = input1.contrast_limits myself.layer.name = "Result of " + operation.__name__ myself.layer.translate = input1.translate[1:3]
def _denoise(input1: Image, operation_name: str = cle.gaussian_blur.__name__, x: float = 1, y: float = 1, z: float = 0, myself=None): if input1: # execute operation cle_input = cle.push(input1.data) output = cle.create_like(cle_input) operation = cle.operation(operation_name) # update GUI label_parameters(operation, [myself.gui.x, myself.gui.y, myself.gui.z]) _call_operation_ignoring_to_many_arguments( operation, [cle_input, output, x, y, z]) max_intensity = cle.maximum_of_all_pixels(output) if max_intensity == 0: max_intensity = 1 # prevent division by zero in vispy output = cle.pull(output) # show result in napari if not hasattr(myself, 'layer'): myself.viewer.add_image(output, colormap=input1.colormap, translate=input1.translate) else: myself.layer.data = output myself.layer.name = "Result of " + operation.__name__ myself.layer.contrast_limits = (0, max_intensity) myself.layer.translate = input1.translate
def _map(input1: Labels, operation_name: str = cle.label_pixel_count_map.__name__, n: float = 1, myself=None): if input1 is not None: # execute operation cle_input1 = cle.push(input1.data) output = cle.create_like(cle_input1) operation = cle.operation(operation_name) # update GUI label_parameters(operation, [myself.gui.n]) _call_operation_ignoring_to_many_arguments(operation, [cle_input1, output, n]) max_intensity = cle.maximum_of_all_pixels(output) if max_intensity == 0: max_intensity = 1 # prevent division by zero in vispy output = cle.pull(output) # show result in napari if not hasattr(myself, 'layer'): myself.viewer.add_image(output, colormap='turbo', interpolation='nearest', translate=input1.translate) else: myself.layer.data = output myself.layer.name = "Result of " + operation.__name__ myself.layer.contrast_limits = (0, max_intensity) myself.layer.translate = input1.translate
def _mesh(input1: Labels, operation_name: str = cle.draw_mesh_between_touching_labels.__name__, n: float = 1, myself=None): if input1 is not None: # execute operation cle_input1 = cle.push(input1.data) output = cle.create_like(cle_input1) operation = cle.operation(operation_name) # update GUI label_parameters(operation, [myself.gui.n]) _call_operation_ignoring_to_many_arguments(operation, [cle_input1, output, n]) min_intensity = cle.minimum_of_all_pixels(output) max_intensity = cle.maximum_of_all_pixels(output) if max_intensity - min_intensity == 0: max_intensity = min_intensity + 1 # prevent division by zero in vispy output = cle.pull(output) # show result in napari if not hasattr(myself, 'layer'): myself.viewer.add_image(output, colormap='green', blending='additive', translate=input1.translate) else: myself.layer.data = output myself.layer.name = "Result of " + operation.__name__ myself.layer.contrast_limits = (min_intensity, max_intensity) myself.layer.translate = input1.translate
def _combine(input1: Layer, input2: Layer = None, operation_name: str = cle.binary_and.__name__, myself=None): if input1 is not None: if (input2 is None): input2 = input1 # execute operation cle_input1 = cle.push(input1.data) cle_input2 = cle.push(input2.data) output = cle.create_like(cle_input1) operation = cle.operation(operation_name) _call_operation_ignoring_to_many_arguments( operation, [cle_input1, cle_input2, output]) max_intensity = cle.maximum_of_all_pixels(output) if max_intensity == 0: max_intensity = 1 # prevent division by zero in vispy output = cle.pull(output) # show result in napari if not hasattr(myself, 'layer'): myself.viewer.add_image(output, colormap=input1.colormap, translate=input1.translate) else: myself.layer.data = output myself.layer.name = "Result of " + operation.__name__ myself.layer.contrast_limits = (0, max_intensity) myself.layer.translate = input1.translate
def _binarize(input1: Layer, operation_name: str = cle.threshold_otsu.__name__, radius_x: int = 1, radius_y: int = 1, radius_z: int = 0, myself=None): if input1 is not None: # execute operation cle_input1 = cle.push(input1.data) output = cle.create_like(cle_input1) operation = cle.operation(operation_name) # update GUI label_parameters( operation, [myself.gui.radius_x, myself.gui.radius_y, myself.gui.radius_z]) _call_operation_ignoring_to_many_arguments( operation, [cle_input1, output, radius_x, radius_y, radius_z]) output = cle.pull(output).astype(int) # show result in napari if not hasattr(myself, 'layer'): myself.viewer.add_labels(output, translate=input1.translate) else: myself.layer.data = output myself.layer.contrast_limits = (0, 1) myself.layer.name = "Result of " + operation.__name__ myself.layer.translate = input1.translate
def _execute(self, layer, layer_number): command = "" try: method = cle.operation(layer.metadata['dialog'].filter_gui.operation_name.value) parameter_names = method.fullargspec.args method_name = "cle." + method.__name__ method_name = method_name.replace("please_select", "copy") except AttributeError: method = layer.metadata['dialog'].filter_gui._function # let's chat about this, probably a better way import inspect parameter_names = inspect.getfullargspec(method).args method_name = method.__name__ command = command + "from " + method.__module__ + " import " + method.__qualname__ + "\n" command = command + method_name + "(" first_image_parameter = None put_comma = False for i, parameter_name in enumerate([x.name for x in layer.metadata['dialog'].filter_gui]): if (i < len(parameter_names)): comma = "" if put_comma: comma = ", " put_comma = True widget = layer.metadata['dialog'].filter_gui[parameter_name] value = widget.value if isinstance(value, Image) or isinstance(value, Labels): image_str = "image" + str(self._get_index_of_layer(value)) if first_image_parameter is None: first_image_parameter = image_str command = command + comma + image_str elif isinstance(value, str): if parameter_name != "operation_name": command = command + comma + "'" + value + "'" else: command = command + comma + "image" + str(layer_number) else: command = command + comma + str(value) command = command + ")\n" if first_image_parameter is not None: command = "image" + str(layer_number) + " = cle.create_like(" + first_image_parameter + ")\n" + \ "image" + str(layer_number) + " = " + command command = "\n" + self._comment(" Layer " + layer.name) + "\n" + command return command
def _transform(input1: Layer, operation_name: str = cle.sub_stack.__name__, a: float = 0, b: float = 0, c: float = 0, d: bool = False, e: bool = False, myself=None): if input1 is not None: # determine shift; todo: to this in a generic way import numpy as np translate = np.copy(input1.translate) if operation_name == cle.sub_stack.__name__: translate[0] += a # a corresponds to start_z elif operation_name == cle.reduce_stack.__name__: translate[0] += b # b corresponds to offset # execute operation cle_input1 = cle.push(input1.data) output = None operation = cle.operation(operation_name) # update GUI label_parameters(operation, [ myself.gui.a, myself.gui.b, myself.gui.c, myself.gui.d, myself.gui.e ]) output = _call_operation_ignoring_to_many_arguments( operation, [cle_input1, output, a, b, c, d, e]) output = cle.pull(output).astype(int) # show result in napari if not hasattr(myself, 'layer'): if isinstance(input1, Labels): myself.viewer.add_labels(output, translate=translate) else: myself.viewer.add_image(output, translate=translate) else: myself.layer.data = output myself.layer.contrast_limits = input1.contrast_limits myself.layer.name = "Result of " + operation.__name__ myself.layer.translate = translate
def _label_processing( input1: Labels, operation_name: str = cle.exclude_labels_on_edges.__name__, min: float = 0, max: float = 100, myself=None): if input1 is not None: # execute operation cle_input1 = cle.push(input1.data) output = cle.create_like(cle_input1) operation = cle.operation(operation_name) # update GUI label_parameters(operation, [myself.gui.min, myself.gui.max]) _call_operation_ignoring_to_many_arguments( operation, [cle_input1, output, min, max]) output = cle.pull(output).astype(int) # show result in napari if not hasattr(myself, 'layer'): myself.viewer.add_labels(output, translate=input1.translate) else: myself.layer.data = output myself.layer.name = "Result of " + operation.__name__ myself.layer.translate = input1.translate
def _label( input1: Layer, operation_name: str = cle.connected_components_labeling_box.__name__, a: float = 2, b: float = 2, myself=None): if input1 is not None: # execute operation cle_input1 = cle.push(input1.data) operation = cle.operation(operation_name) # update GUI label_parameters(operation, [myself.gui.a, myself.gui.b]) output = cle.create_like(cle_input1) _call_operation_ignoring_to_many_arguments(operation, [cle_input1, output, a, b]) output = cle.pull(output).astype(int) # show result in napari if not hasattr(myself, 'layer'): myself.viewer.add_labels(output, translate=input1.translate) else: myself.layer.data = output myself.layer.name = "Result of " + operation.__name__ myself.layer.translate = input1.translate
def test_operation(): import pyclesperanto_prototype as cle op = cle.operation("gaussian_blur") assert op is not None