Touching objects labeling#

When processing images from fluorescence microscopy, we are often confronted to objects sticking to each other that should be differentiated. However, if we apply connected-component labeling after thresholding, we retrieve one labeled object, where we believe there should be two. ImageJ-users would then use the “Watershed” algorithm that is capable of splitting objects if the shape of an object suggests the object contains of two. Some functions in SimpleITK allow us to do the same. Again, for programming convenience, we use the scriptable napari plugin napari-simpleitk-image-processing.

import numpy as np
from skimage.io import imread
from pyclesperanto_prototype import imshow
from napari_simpleitk_image_processing import threshold_otsu, touching_objects_labeling, gaussian_blur

Our starting point is a binary image with some 8-shaped objects, we would like to split.

blobs = imread('../../data/blobs.tif')
binary = threshold_otsu(blobs)
imshow(binary)
../_images/aac24fde3fd260040b5033ca92c02ff51dae5ae320de2449b8e8e86ef339dc9d.png

The touching_objects_labeling function takes a binary image as input and produces a label image, just like connected component labeling. The result differs though: The 8-shaped objects are split.

touching_labels = touching_objects_labeling(binary)
imshow(touching_labels, labels=True)
../_images/085fe1c8193f4184424dd2906f65a85e2b936768f3244a1076c369e8382f0cfb.png

Fine tuning the result#

If not all objects should be split, one can fine-tune the result of this process by modifying the binary image before passing it to touching_objects_labeling. For example if we apply a Gaussian blur filter before thesholding the image, we can retrieve a label image where less objects are split.

blurred = gaussian_blur(blobs, variance_x=25, variance_y=25)

binary2 = threshold_otsu(blurred)
imshow(binary2)
../_images/31cbe81776263a510c37583ed870c7788f40b99fe6c478cfd4cac4e432a36191.png
touching_labels = touching_objects_labeling(binary2)
imshow(touching_labels, labels=True)
../_images/4ce25d636a55076ac620b9fe73263ce5c71e27ddfe11dbd6049156659a975462.png