Edge detection#

In clesperanto, multiple filters for edge-detection are implemented.

See also

import pyclesperanto_prototype as cle
from skimage.io import imread
import matplotlib.pyplot as plt

cle.select_device("RTX")
<gfx90c on Platform: AMD Accelerated Parallel Processing (2 refs)>
blobs = imread("../../data/blobs.tif")
blobs.shape
(254, 256)
cle.imshow(blobs)
../_images/697332ed931701bd777704b279b47e121b548544b81f7a635c3783b21c04fb53.png

Sobel operator#

see also

blobs_sobel = cle.sobel(blobs)
cle.imshow(blobs_sobel)
../_images/6f78a059d541f817ce00965d380f7561c27cd8d61a9c1d0cd261392d819f8164.png

Laplace operator#

see also

blobs_laplace = cle.laplace_box(blobs)
cle.imshow(blobs_laplace)
../_images/97b9899f717c757b0ddca2c1bad676aaf671f2fa3697d9eb8cebc46be9099e88.png

Laplacian of Gaussian#

Also kown as the Mexican hat filter

blobs_laplacian_of_gaussian = cle.laplace_box(cle.gaussian_blur(blobs, sigma_x=1, sigma_y=1))
cle.imshow(blobs_laplacian_of_gaussian)
../_images/4039d3563c2a36f9db4b9be7e26ded824be8eda4d4037357dfcb945cf44ecf2e.png
blobs_laplacian_of_gaussian = cle.laplace_box(cle.gaussian_blur(blobs, sigma_x=5, sigma_y=5))
cle.imshow(blobs_laplacian_of_gaussian)
../_images/9bd4cce450e487d9177d0a1ecf7113bf18e721495aeb5da88645442a0d7ee226.png

Local Variance filter#

blobs_edges = cle.variance_box(blobs, radius_x=5, radius_y=5)
cle.imshow(blobs_edges)
../_images/3c75eedc70e388d2225c1cca24088c11ced4c7a4b45aee2b9c122af42578e3f4.png

Local standard deviation#

… is just the square root of the local variance

blobs_edges = cle.standard_deviation_box(blobs, radius_x=5, radius_y=5)
cle.imshow(blobs_edges)
../_images/39b5a73b96057262d6fab7a9d85d9f36478cb83ec7d58fdc22a773b40ac86f9e.png

Edge detection is not edge enhancement#

Intuitively, one could apply an edge detection filter to enhance edges in images showing edges. Let’s try with an image showing membranes. It’s a 3D image btw.

image = imread("../../data/EM_C_6_c0.tif")
image.shape
(256, 256, 256)
cle.imshow(image[60])
../_images/756fcdd11282e04ef342228a2a2fd94ed9875e723db8d3b7c1515358353a0ddc.png
image_sobel = cle.sobel(image)
cle.imshow(image_sobel[60])
../_images/105c5d8c02a5c62db015972a88654442b975ce4cfaeadb386cd35ccb857bf86b.png

When looking very carefully, you may observe that the edges are a bit thicker in the second image. The edge detection filter detects two edges, the increasing signal side of the membrane and the decreasing signal on the opposite side. Let’s zoom:

fig, axs = plt.subplots(1, 2)
cle.imshow(                image[60, 125:145, 135:155], plot=axs[0])
cle.imshow(cle.pull(image_sobel)[60, 125:145, 135:155], plot=axs[1])
../_images/d3fed6be6e92aa6bfb9b673f0b6147e393226ec22a5e933e2fdb494cfdd4402c.png

Enhancing edges#

Thus, to enhance edges in a membrane image, other filters are more useful. Enhancement may for example mean making membranes thicker and potentially closing gaps.

Local standard deviation#

image_std = cle.standard_deviation_box(image, radius_x=5, radius_y=5, radius_z=5)
cle.imshow(image_std[60])
../_images/b6e7b76ab9326c710c8a16b5244ff6f9bb497bc3294d2f85f4f0d2b36dac296b.png

Local maximum#

image_max = cle.maximum_box(image, radius_x=5, radius_y=5, radius_z=5)
cle.imshow(image_max[60])
../_images/61ca117a376d1a7f27388d3ad6474e499ccbcb215e05b5c7a24922d4af457597.png