def z_position_projection(source_stack: Image, z_position: Image, destination: Image = None) -> Image: """Project a defined Z-slice of a 3D stack into a 2D image. Which Z-slice is defined as the z_position image, which represents an altitude map. Parameters ---------- source_stack : Image Input image stack z_position : Image altitude map destination : Image, optional Projected image Returns ------- destination See Also -------- ..[1] https://clij.github.io/clij2-docs/reference_zPositionProjection """ parameters = { "dst": destination, "position": z_position, "src": source_stack, } execute(__file__, 'z_position_projection_x.cl', 'z_position_projection', destination.shape, parameters) return destination
def z_position_of_minimum_z_projection(source: Image, destination: Image = None) -> Image: """Determines a Z-position of the minimum intensity along Z and writes it into the resulting image. If there are multiple z-slices with the same value, the smallest Z will be chosen. Parameters ---------- source : Image Input image stack destination : Image, optional altitude map Returns ------- destination See Also -------- ..[1] https://clij.github.io/clij2-docs/reference_zPositionOfMinimumZProjection """ parameters = { "dst_arg": destination, "src": source, } execute(__file__, 'z_position_of_minimum_z_projection_x.cl', 'z_position_of_minimum_z_projection', destination.shape, parameters) return destination
def variance_box(source: Image, destination: Image = None, radius_x: int = 1, radius_y: int = 1, radius_z: int = 1) -> Image: """Computes the local variance of a pixels box neighborhood. \n\nThe box size is specified by its half-width, half-height and half-depth (radius). If 2D images are given, radius_z will be ignored. Parameters ---------- source : Image destination : Image radius_x : int radius_y : int radius_z : int Returns ------- destination Examples -------- >>> import pyclesperanto_prototype as cle >>> cle.variance_box(source, destination, 10, 10, 10) References ---------- .. [1] https://clij.github.io/clij2-docs/reference_varianceBox """ parameters = { "dst": destination, "src": source, "Nx": radius_to_kernel_size(radius_x), "Ny": radius_to_kernel_size(radius_y), } if (len(destination.shape) == 3): parameters.update({"Nz": radius_to_kernel_size(radius_z)}) execute(__file__, 'variance_box_' + str(len(destination.shape)) + 'd_x.cl', 'variance_box_' + str(len(destination.shape)) + 'd', destination.shape, parameters) return destination
def exclude_labels_on_edges(labels_source: Image, labels_destination: Image = None): num_labels = int(maximum_of_all_pixels(labels_source)) label_indices = range(0, num_labels + 1) label_index_map = push(np.asarray(label_indices)) print(label_index_map) parameters = {"src": labels_source, "label_index_dst": label_index_map} if (len(labels_source.shape) == 3): dimensions = [ labels_source.shape[0], labels_source.shape[1], labels_source.shape[2] ] else: dimensions = [1, labels_source.shape[0], labels_source.shape[1]] if (len(labels_source.shape) == 3): global_sizes = [1, dimensions[1], dimensions[2]] execute(__file__, "exclude_labels_on_edges_3d_x.cl", "exclude_on_edges_z_3d", global_sizes, parameters) global_sizes = [dimensions[0], 1, dimensions[2]] execute(__file__, "exclude_labels_on_edges_3d_x.cl", "exclude_on_edges_y_3d", global_sizes, parameters) global_sizes = [dimensions[0], dimensions[1], 1] execute(__file__, "exclude_labels_on_edges_3d_x.cl", "exclude_on_edges_x_3d", global_sizes, parameters) label_indices = pull(label_index_map) count = 1 for i in range(1, num_labels + 1): if (label_indices[i] > 0): label_indices[i] = count count = count + 1 label_index_map = push(np.asarray(label_indices)) print(label_index_map) replace_intensities(labels_source, label_index_map, labels_destination) return labels_destination
def exclude_labels_on_edges(label_map_input : Image, label_map_destination : Image = None) -> Image: """Removes all labels from a label map which touch the edges of the image (in X, Y and Z if the image is 3D). Remaining label elements are renumbered afterwards. Parameters ---------- label_map_input : Image label_map_destination : Image Returns ------- label_map_destination Examples -------- >>> import pyclesperanto_prototype as cle >>> cle.exclude_labels_on_edges(label_map_input, label_map_destination) References ---------- .. [1] https://clij.github.io/clij2-docs/reference_excludeLabelsOnEdges """ num_labels = int(maximum_of_all_pixels(label_map_input)) label_indices = range(0, num_labels + 1) label_index_map = push(np.asarray(label_indices)) parameters = { "src":label_map_input, "label_index_dst":label_index_map } if (len(label_map_input.shape) == 3): dimensions = [ label_map_input.shape[0], label_map_input.shape[1], label_map_input.shape[2] ] else: dimensions = [ 1, label_map_input.shape[0], label_map_input.shape[1] ] if (len(label_map_input.shape) == 3): global_sizes = [1, dimensions[1], dimensions[2]] execute(__file__, "../clij-opencl-kernels/kernels/exclude_labels_on_edges_3d_x.cl", "exclude_on_edges_z_3d", global_sizes, parameters) global_sizes = [dimensions[0], 1 ,dimensions[2]] execute(__file__, "../clij-opencl-kernels/kernels/exclude_labels_on_edges_3d_x.cl", "exclude_on_edges_y_3d", global_sizes, parameters) global_sizes = [dimensions[0], dimensions[1], 1] execute(__file__, "../clij-opencl-kernels/kernels/exclude_labels_on_edges_3d_x.cl", "exclude_on_edges_x_3d", global_sizes, parameters) label_indices = pull(label_index_map) count = 1 for i in range(1, num_labels + 1): if (label_indices[i] > 0): label_indices[i] = count count = count + 1 label_index_map = push(np.asarray(label_indices)) replace_intensities(label_map_input, label_index_map, label_map_destination) return label_map_destination