After completing this lesson, learners should be able to:
Understand the concept of watersheds in image analysis.
Understand that a watershed algorithm is often applied to a distance map to split objects by their shape.
Be able to run a watershed algorithm in an image analysis platform.
Motivation
The segmentation of touching objects often is a challenge in image analysis. The watershed algorithm is a very common operation to split touching objects and is available in most image analysis frameworks.
Concept map
graph TD
T("Image") --> W("Watershed transform")
SP("Seed points (at local intensity minima)") --> W
W --> S("Segmented image")
S --- B("Boundaries / Watersheds (at intensity ridges)")
Figure
Illustration of the watershed transform. a) Image with three objects that cannot be separated by a simple threshold. b) Foreground/background segmentation of (a). c) Inverse of (a). d) Intensity line profile along the line depicted in (c) with illustration of filling up the basins up to a the level where the yellow and blue regions meet and a first watershed is build. e) As (d) but filling up the basins to a higher level where a second watershed is build between the blue and red region. f) Watershed transform of (c). g) (f) masked with (b).
Appreciate that you cannot segment the objects using a simple threshold.
Appreciate that a watershed transform on the intensity signal does not help here, because there is no “intensity ridge” bewteen the two touching objects.
Create a binary mask.
Create a distance map within objects.
Invert the distance map.
Slightly blur the distance map to avoid spurious minima (water basins).
Apply a watershed transform.
Combine the binary mask and the watershed image to segment the two objects.
Using the watershed transform try to segment the nuclei.
Hints:
Directly applying a watershed on the inverted image will likely fail as there are too many intensity maxima even within one nucleus. Thus, one will need to binarise the image and perform a watershed on the distance transform.
Using the three preprocessed images perform a seeded watershed to segment the cells.
Show exercise/solution for:
ImageJ Macro: MorpholibJ shape watershed
/*
* Shape watershed (with distance transform) in Fiji
*
* Requirements:
* - IJPB-Plugins update site
*/run("Close All");setOption("BlackBackground",true);open("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xy_8bit__several_touching_nuclei.tif");rename("input");// create maskrun("Duplicate...","title=mask");setThreshold(61,255);run("Convert to Mask");run("Chamfer Distance Map","distances=[Chessknight (5,7,11)] output=[16 bits] normalize");rename("dist");run("Invert");// remove spurious minima in distance map (choose sigma smaller than object radii)run("Mean...","sigma=2");// watershed with maskrun("Classic Watershed","input=dist mask=mask use min=0 max=255");
ImageJ Macro: MorpholibJ seeded watershed
/*
* Seeded watershed in Fiji
*
* Requirements:
* - IJPB-Plugins update site
*/run("Close All");setOption("BlackBackground",true);// open and rename the imagesopen("https://github.com/NEUBIAS/training-resources/raw/master/image_data/watershed/xy_8bit_binary__tubulin.tif");rename("tubulin_mask");open("https://github.com/NEUBIAS/training-resources/raw/master/image_data/watershed/xy_8bit_binary__nuclei.tif");rename("nuclei_mask");open("https://github.com/NEUBIAS/training-resources/raw/master/image_data/watershed/xy_16bit__tubulin_smooth.tif");rename("tubulin_smooth");// invert tubulin image for watershedselectWindow("tubulin_smooth");run("Invert");// watershed on inverted tubulin with nuclei as seeds and binary tubulin as maskrun("Marker-controlled Watershed","input=tubulin_smooth marker=nuclei_mask mask=tubulin_mask compactness=0 binary");
Assessment
Fill in the blanks
The output of watershed transform is a ___ .
Before applying the watershed transform on a flurorescence image, one often __ and __ the image.
When providing the watershed basins one speaks of a ___ watershed transform.
Solution
label mask image
inverts and smoothes
seeded (or marker controlled)
Key points
A watershed transform can separate touching objects if there are intensity valleys (or ridges) between touching objects. In case of intensity ridges the image needs to be inverted before being subjected to the watershed transform.
To separate object by their shape, use a distance transform on the binary image and inject this into the watershed transform. It is often good to smooth the distance transform to remove spurious minima, which could serve as wrong seed points and thus lead to an over-segmentation.