def jaccard_index(source1 : Image, source2 : Image): """Determines the overlap of two binary images using the Jaccard index. A value of 0 suggests no overlap, 1 means perfect overlap. The resulting Jaccard index is saved to the results table in the 'Jaccard_Index' column. Note that the Sorensen-Dice coefficient can be calculated from the Jaccard index j using this formula: <pre>s = f(j) = 2 j / (j + 1)</pre> Parameters ---------- source1 : Image source2 : Image References ---------- .. [1] https://clij.github.io/clij2-docs/reference_jaccardIndex """ intersection = create_like(source1) binary_and(source1, source2, intersection) union = create_like(source1) binary_or(source1, source2, union) return sum_of_all_pixels(intersection) / sum_of_all_pixels(union)
def difference_of_gaussian(input: Image, destination: Image = None, sigma1_x: float = 2, sigma1_y: float = 2, sigma1_z: float = 2, sigma2_x: float = 2, sigma2_y: float = 2, sigma2_z: float = 2) -> Image: """Applies Gaussian blur to the input image twice with different sigma values resulting in two images which are then subtracted from each other. It is recommended to apply this operation to images of type Float (32 bit) as results might be negative. Parameters ---------- input : Image The input image to be processed. destination : Image The output image where results are written into. sigma1_x : float Sigma of the first Gaussian filter in x sigma1_y : float Sigma of the first Gaussian filter in y sigma1_z : float Sigma of the first Gaussian filter in z sigma2_x : float Sigma of the second Gaussian filter in x sigma2_y : float Sigma of the second Gaussian filter in y sigma2_z : float Sigma of the second Gaussian filter in z Returns ------- destination Examples -------- >>> import pyclesperanto_prototype as cle >>> cle.difference_of_gaussian(input, destination, sigma1x, sigma1y, sigma1z, sigma2x, sigma2y, sigma2z) References ---------- .. [1] https://clij.github.io/clij2-docs/reference_differenceOfGaussian3D """ temp1 = create_like(destination) temp2 = create_like(destination) gaussian_blur(input, temp1, sigma1_x, sigma1_y, sigma1_z) gaussian_blur(input, temp2, sigma2_x, sigma2_y, sigma2_z) return subtract_images(temp1, temp2, destination)
def squared_difference(source1: Image, source2: Image, destination: Image = None): """Determines the squared difference pixel by pixel between two images. Parameters ---------- source1 : Image source2 : Image destination : Image Returns ------- destination References ---------- .. [1] https://clij.github.io/clij2-docs/reference_squaredDifference """ temp = create_like(destination) subtract_images(source1, source2, temp) return power(temp, destination, 2)
def subtract_gaussian_background(input: Image, destination: Image = None, sigma_x: float = 2, sigma_y: float = 2, sigma_z: float = 2) -> Image: """Applies Gaussian blur to the input image and subtracts the result from the original. Parameters ---------- input : Image destination : Image sigmaX : Number sigmaY : Number sigmaZ : Number Returns ------- destination References ---------- ..[1] https://clij.github.io/clij2-docs/reference_subtractGaussianBackground """ temp1 = create_like(destination) gaussian_blur(input, temp1, sigma_x, sigma_y, sigma_z) return subtract_images(input, temp1, destination)
def absolute_difference(source1 : Image, source2 : Image, destination : Image = None): """Determines the absolute difference pixel by pixel between two images. <pre>f(x, y) = |x - y| </pre> Parameters ---------- source1 : Image The input image to be subtracted from. source2 : Image The input image which is subtracted. destination : Image The output image where results are written into. Returns ------- destination References ---------- .. [1] https://clij.github.io/clij2-docs/reference_absoluteDifference """ temp = create_like(destination) subtract_images(source1, source2, temp) return absolute(temp, destination)
def squared_difference(source1 : Image, source2 : Image, destination : Image = None) -> Image: """Determines the squared difference pixel by pixel between two images. Parameters ---------- source1 : Image source2 : Image destination : Image Returns ------- destination Examples -------- >>> import pyclesperanto_prototype as cle >>> cle.squared_difference(source1, source2, destination) References ---------- .. [1] https://clij.github.io/clij2-docs/reference_squaredDifference """ temp = create_like(destination) subtract_images(source1, source2, temp) return power(temp, destination, 2)