## Prerequisites

Before starting this lesson, you should be familiar with:

## Learning Objectives

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)")

## Activities

• Basic watershed
• Open xy_8bit__touching_objects.tif.
• Appreciate that you cannot segment the three objects using a simple threshold.
• Anyway find a threshold that segments the image into foreground (objects) and background.
• Keep this binary mask, we will need it later.
• Invert the original image and apply the watershed transform.
• Appreciate that the image is now split into three regions.
• Combine the binary mask and the watershed image to segment the three objects.
• Shape watershed
• Open xy_8bit__touching_objects_same_intensity.tif.
• 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.
• Seeded watershed for noisy data
• Open xy_8bit__noisy_touching_objects.tif.
• Invert the image and apply the watershed transform.
• Appreciate that this does not work because there are too many basin due to the noise.
• Note that one could tackle this by applying a smoothing filter, but we want to explore another route now.
• Open xy_8bit_binary__touching_objects_markers.tif.
• This image marks the centers of the three objects.
• Combing the two images run a seeded watershed transform to split the image into three regions.
• For segmenting the three objects one would have to apply a mask to the resulting image (see activities above).

Show activity for:

## ImageJ GUI: MorpholibJ basic watershed

• Open the input image, and invert it using [Edit > Invert] or [Ctrl+Shift+I]
• Apply watershed transform on inverted image using [Plugins > MorpholibJ > Segmentation > Classic Watershed]
• `Input = xy_8bit__touching_objects.tif`
• `Mask = none`
• `[X] use diagonal connectivity`
• `Min h = 0`
• `Max h = 255`
• Duplicate the input image using [Image > Duplicate] `Title = mask`
• Find/apply threshold using [Image >Adjust > Threshold…] (e.g. `Lower Threshold Level = 9`) and press `Apply`
• Apply watershed transform on inverted image and selecting mask using [Plugins > MorpholibJ > Segmentation > Classic Watershed]
• `Input = xy_8bit__touching_objects.tif`
• `Mask = mask`
• `[X] use diagonal connectivity`
• `Min h = 0`
• `Max h = 255`

## Exercises

• Shape watershed
• Open xy_8bit__several_touching_nuclei.tif
• 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.
• Seeded watershed
Show exercise/solution for:

## 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.

## Follow-up material

Recommended follow-up modules: