The Watershed Transform: Strategies for Image Segmentation (2024)

By Steve Eddins, MathWorks

The term watershed refers to a ridge that divides areas drained by different river systems. A catchment basin is the geographical area draining into a river or reservoir.

So how are watersheds and catchment basins related to analyzing biological tissue, studying galaxies, or researching new semiconductor technology? And what is the connection to image processing?

The connection is through computer analysis of objects in digital images. The objects could be anything: blood cells, stars, toner spots on a printed page, DNA microarray elements, or even quantum semiconductor dots, as in this image.

The Watershed Transform: Strategies for Image Segmentation (1)

Computer analysis of image objects starts with finding them-deciding which pixels belong to each object. This is called image segmentation, the process of separating objects from the background, as well as from each other. R. Gonzalez and R. Woods write in their widely used textbook (Digital Image Processing) that "segmentation of nontrivial images is one of the most difficult tasks in image processing. Segmentation accuracy determines the success or failure of computerized analysis procedures."

The latest release (Version 3) of the Image Processing Toolbox includes new functions for computing and applying the watershed transform, a powerful tool for solving image segmentation problems.

Understanding the watershed transform requires that you think of an image as a surface. For example, consider the image below:

The Watershed Transform: Strategies for Image Segmentation (2)
The Watershed Transform: Strategies for Image Segmentation (3)

Multidimensional Image Processing
Many of the new Image Processing Toolbox functions support multidimensional image processing. The surfaces illustrated on the cover expand this binary image example to three dimensions. The graphics show two spherical touching objects, transparent isosurfaces of the distance transform, and the segmented result computed with the 3-D watershed transform. The new deblurring, spatial transformation, morphology, and filtering tools in the Toolbox also support multidimensional image processing.

Example 1: Segmenting a Binary Image

Consider the task of separating the two touching objects in this binary image. How can we modify this image so its catchment basins are two circular objects?

The Watershed Transform: Strategies for Image Segmentation (4)

To do this we'll use another new tool in the Image Processing Toolbox: bwdist, which computes the distance transform. The distance transform of a binary image is the distance from every pixel to the nearest nonzero-valued pixel, as this example shows.

The Watershed Transform: Strategies for Image Segmentation (6)

The distance transform of the binary image, computed using bwdist(BW), looks like image A (left).

This image is not very useful, because there is only one catchment basin spanning the entire image. Instead, try computing the distance transform of the image's complement:

D = bwdist(~BW); % image B (above)

This image is closer, but we need to negate the distance transform to turn the two bright areas into catchment basins.

D = -bwdist(~BW); % image C (above)

Now there is one catchment basin for each object, so we call the watershed function. L =

watershed(D);

L is called a label matrix, and it contains positive integers corresponding to the locations of each catchment basin. We can use the zero-valued elements of L, which are located along the watershed lines, to separate the objects in the original image.

BW(L == 0) = 0;imshow(BW) % Segmented image D (above)

Example 2: Segmenting the Quantum Dots

The Watershed Transform: Strategies for Image Segmentation (7)

The quantum dots image requires more work to make it suitable for watershed segmentation. First, we convert the image to grayscale and use a morphological top-hat operator (one of many new grayscale morphological tools) with a disk-shaped structuring element to smooth out the uneven illumination.

I = rgb2gray(RGB);I2 = imtophat(I, strel('disk', 10));
The Watershed Transform: Strategies for Image Segmentation (8)

Second, we use a new function called graythresh to determine a good threshold for converting the image to binary.

level = graythresh(I2);BW = im2bw(I2,level);
The Watershed Transform: Strategies for Image Segmentation (9)

Finally, we compute the distance transform of the complemented binary image, modify it to force the background to be its own catchment basin, and compute the watershed transform. The new function label2rgb is used to display the segmented objects using different colors.

D = -bwdist(~BW);D(~BW) = -Inf;L = watershed(D);imshow(label2rgb(L,'jet','w'))

Example 3: Segmenting Steel Grains

Our final example, a microscope image of steel grains, looks like a natural for watershed segmentation, since the light areas are already fairly well separated by dark lines.

The Watershed Transform: Strategies for Image Segmentation (10)

We could simply compute the watershed of the complemented image.

L = watershed(imcomplement(I));
The Watershed Transform: Strategies for Image Segmentation (11)

Unfortunately that doesn't work so well, as you can see below:

The result, oversegmentation, is a well-known phenomenon in watershed segmentation. Oversegmentation occurs because every regional minimum, even if tiny and insignificant, forms its own catchment basin. One solution is to modify the image to remove minima that are too shallow. That is exactly what the h-minima transform (imhmin) does.

I2 = imcomplement(I);I3 = imhmin(I2,20); %20 is the height threshold for suppressing shallow minimaL = watershed(I3);

Here is the much improved result.

The Watershed Transform: Strategies for Image Segmentation (12)

You have read about several ways to segment an image using the watershed transform. Another technique, known as marker-controlled watershed segmentation, is described on the Image Processing Toolbox page. To learn more about how to use the watershed transform in your own work, check out For Further Reading.

What's New in Image Processing Toolbox 3

The 63 new toolbox functions substantially extend its capabilities in these major areas:

  • Grayscale morphology
  • Spatial transformations
  • Image registration
  • Image deblurring
  • DICOM import
  • Multidimensional image processing
  • Integer image arithmetic and filtering
  • Tools that facilitate instrument control in an easy-to-use graphical environment
  • Functions for determining your computer's available hardware
  • Communication with multiple instruments within one MATLAB session

For more information about the new release, see theImage Processing Toolbox page.

Published 2002

References

  • Digital Image Processing, by Rafael C. Gonzalez and Richard E. Woods, Prentice-Hall, 2002

  • The Image Processing Handbook, by John Russ, CRC Press, 1998

  • Morphological Image Analysis: Principles and Applications, by Pierre Soille, Springer-Verlag Berlin Heidelberg, 1999

Products Used

  • Image Processing Toolbox

Learn More

    • Image Processing Toolbox User's Guide

    The Watershed Transform: Strategies for Image Segmentation (2024)
    Top Articles
    Latest Posts
    Article information

    Author: Msgr. Refugio Daniel

    Last Updated:

    Views: 6588

    Rating: 4.3 / 5 (54 voted)

    Reviews: 93% of readers found this page helpful

    Author information

    Name: Msgr. Refugio Daniel

    Birthday: 1999-09-15

    Address: 8416 Beatty Center, Derekfort, VA 72092-0500

    Phone: +6838967160603

    Job: Mining Executive

    Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

    Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.