Watershed image segmentation, part 2
Previously we discussed the watershed algorithm – and we examined where the name comes from. Suppose we have a function f(x,y) and a surface that is the graph of f.
![]()
Next, we flood the valley and build dams so that we don’t allow the water to flow from one valley to another. These dams will break the image into regions each containing a single valley.
In the standard settings when f(x,y) is the gray level (in the example on the right f(x,y)=sin(x)sin(y)), what is captured by these dams are the dark spots. Then the light areas are the peaks and the dark areas are the valleys. Then, for example, if you have an image of dark cells on a light background, you’ll have the cells enclosed inside these regions.
What if the cells are light and the background is dark? Then you’ll have to turn everything upside down. For example, you can replace the surface given by f(x,y) with the one given by 255-f(x,y). Not a problem but inconvenient. Why? Because you have to tell your program what you are looking for: light on dark or dark on light. It is better if you don’t have to use a priori information so that the analysis is independent of context, as much as possible.
This minor inconvenience becomes a problem when the image contains both kinds on features. The first and second images below are what watershed should be theoretically and the third is the watershed segmentation produced with ImageJ.
Another choice for f(x,y) is the variance, below.

Another one was discussed previously. In a binary image you set: f(x,y) = the distance from (x,y) to the nearest black pixel.
As a reminder, this is how Pixcavator handles the above example.





