Marker-controlled watershed¶
| Fact | Value |
|---|---|
| Also called | Seeded watershed, Watershed from markers |
| Status | Implemented and tested |
| Family | Segmentation and regions |
| Engine | Science engine |
| Type | Nonlinear, morphological, flooding from markers |
| Output | Labels |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/segmentation.py, marker_watershed |
| Operator code | engine/src/pixelnexus_engine/filters/segmentation.py, marker_watershed_representation |
| Packages | scikit-image, SciPy |
Overview¶
The marker-controlled watershed lets you choose where regions start. Select a small area inside each object you want, and each separate part of the selection becomes a marker. The image edge outside the selection can be one more marker, for the background. Water then rises from the markers only, over the gradient of the image, and regions meet at the edges between them. The regions go to the Features panel with their area, centroid and mean brightness, and are drawn over the image in their label colors. Click a row number in the panel to make that region the selection, or select all regions at once. The filter runs in the PixelNexus engine, with scikit-image.
How it works¶
- Blur the luma and take its Sobel gradient as the elevation.
- Turn each separate part of the selection into a marker, and the image edge into one more.
- Flood the elevation from the markers, in order of height.
- Each pixel joins the flood that reaches it first.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(E\): The elevation, the gradient magnitude
- \(L(x)\): The region of pixel x
The elevation E is the gradient magnitude of the blurred luma Y, so edges are ridges. The markers replace the minima of the plain watershed. Each 8-connected part of the selection is one marker, and with the border marker, the edge of the image outside the selection is another. Water rises from the markers only, so no region starts anywhere else. Each pixel joins the flood that reaches it first, and floods meet on the ridges between the markers. Meyer and Beucher made markers the way to tell the watershed which objects to find.
The plain watershed starts a region in every deep enough valley, so it needs a depth to stop noise. Markers replace that guess. Meyer and Beucher made markers the standard way to tell the watershed which objects to find: one marker per object, and one for the background.
The flood from a marker covers everything it can reach before it meets another flood. So every pixel ends up in some region. Without a background marker, the ground has no marker of its own and goes to whichever object floods it first.
Kernel or operator¶
There is no kernel. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Regions | Regions, Elevation (gradient), Boundaries over the image, Mean color of each region | The regions as a label map, drawn over the image and listed in the Features panel. Or the elevation that is flooded, the Sobel gradient, stretched. Or the boundaries in yellow over the image, or each region filled with its mean color. |
Smoothing sigma |
1 | 0 to 5 px | The sigma of a Gaussian blur of the luma before the Sobel gradient. 0 turns the blur off. |
Border marker borderMarker |
on | On or off | The pixels on the image edge outside the selection are one more marker, for the background. |
Compactness compactness |
0 | 0 to 10 | Above 0, the compact watershed of Neubert and Protzel, which also weighs the distance from each marker. scikit-image uses 0, the classic watershed. |
Implementation¶
marker_watershed in engine/src/pixelnexus_engine/filters/segmentation.py uses the same elevation as the watershed, the Sobel gradient of the blurred luma. The selection arrives as a mask, and each 8-connected part of its selected pixels, those above 127, is one marker. With the border marker on, the pixels on the image edge that are not selected form one more marker. Then skimage.segmentation.watershed floods from the markers. The filter stops with a message when the selection is empty, or when there is only one marker.
The selection is only an input here. Its catalog entry sets selectionRole: markers, so the studio runs the filter on the whole image.
The regions output is a label map. The engine sends it with a table of the regions, and the studio draws it over the image. See the science engine for how label maps travel.
Worked example¶
| Border marker | Region | Area (px) | Disk area (px) | Overlap |
|---|---|---|---|---|
| on | Left disk | 3074 | 3613 | 0.850 |
| on | Right disk | 2806 | 2270 | 0.804 |
| off | Left disk | 3074 | 3613 | 0.850 |
| off | Right disk | 22526 | 2270 | 0.101 |
The image of the figure, with the defaults. The disk area counts the pixels within the radius of each disk, where the right disk gives way to the left one. The overlap is the area of both together divided by the area of either.
With the border marker, each disk gets a region of about its own size. The overlap with the true disk is 0.85 for the left disk and 0.80 for the right one. The blur and the noise move the boundary a little, and the right region spills a little past its disk. Without the border marker, the ground has no marker, so the right disk's flood takes it, and its region becomes ten times too large.
Complexity¶
- Time: \(O(N log N)\)
- Memory: \(O(N)\)
N is the number of pixels.
Artifacts and limitations¶
Limitations
- Each object needs its own separate mark.
- A weak edge lets a flood leak into a neighboring object.
Artifacts
- Boundaries that jump to a stronger edge nearby.
Tests¶
On two squares with a marker in each, each square must become one region and the edge the third. The markers must be one per part of the selection plus one for the edge. An empty selection, or a single marker without the border marker, must stop with a message. The representation must have its three stages.
References¶
- Meyer, F., and Beucher, S. Morphological segmentation. Journal of Visual Communication and Image Representation 1(1), 21 to 46, 1990. DOI 10.1016/1047-3203(90)90014-M.
- Vincent, L., and Soille, P. Watersheds in digital spaces, an efficient algorithm based on immersion simulations. IEEE Transactions on Pattern Analysis and Machine Intelligence 13(6), 583 to 598, 1991. DOI 10.1109/34.87344.
- Neubert, P., and Protzel, P. Compact watershed and preemptive SLIC, on improving trade-offs of superpixel segmentation algorithms. International Conference on Pattern Recognition (ICPR), 996 to 1001, 2014. DOI 10.1109/ICPR.2014.181.
- scikit-image documentation, skimage.segmentation.watershed.