Gauss-Otsu-labeling#

We have so far processed images using filters such as Gaussian blurring, threshold algorithms such as Otsu’s method and we labeled objects using connected component labeling. The combination of these three algorithms in particular is so common, that there are convenience functions available to exectue those three operations in one shot. This workflow for image segmentation is a very simple approach, e.g. for detecting and segmenting nuclei in fluorescence micropscopy images. It will work if the objects are not too dense.

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

To demonstrate the workflow, we’re using image data from the Broad Bio Image Challenge: We used image set BBBC022v1 Gustafsdottir et al., PLOS ONE, 2013, available from the Broad Bioimage Benchmark Collection Ljosa et al., Nature Methods, 2012.

We load the image and for visualisation purposes we crop out a sub-region:

input_image = imread("../../data/BBBC022/IXMtest_A02_s9.tif")[:,:,0]

input_crop = input_image[0:200, 200:400]

fig, axs = plt.subplots(1, 2, figsize=(15, 15))
cle.imshow(input_image, plot=axs[0])
cle.imshow(input_crop, plot=axs[1])
../_images/bf69dc66f331ad66f2ca4567db95415d6269d30eb08c53f71c25e93ad9d38fa7.png

Applying the algorithm#

Gauss-Otsu-labeling is a command in pyclesperanto and the scriptable napari plugin napari-segment-blobs-and-things-with-membranes. The operation has a outline_sigma parameter for controlling how precise segmented objects are outlined.

sigma_outline = 1

segmented = cle.gauss_otsu_labeling(input_image, outline_sigma=sigma_outline)
segmented_crop = segmented[0:200, 200:400]

fig, axs = plt.subplots(1, 2, figsize=(15, 15))
cle.imshow(segmented, labels=True, plot=axs[0])
cle.imshow(segmented_crop, labels=True, plot=axs[1])
../_images/c1f27c8e04384d1bf104941eae7d93ce954c476bc2d57fb97dae616877f57ad1.png
sigma_outline = 7

segmented = cle.gauss_otsu_labeling(input_image, outline_sigma=sigma_outline)
segmented_crop = segmented[0:200, 200:400]

fig, axs = plt.subplots(1, 2, figsize=(15, 15))
cle.imshow(segmented, labels=True, plot=axs[0])
cle.imshow(segmented_crop, labels=True, plot=axs[1])
../_images/1d60d721944f56daebfcd0a2b00e77225dc9272a8732e64debc948bba48dfb7f.png

As you can see, if objects are too close, they will be segmented together. In these cases it is recommended to try Voronoi-Otsu-Labeling.