Marker-based watershed
Grow labelled regions across an image until competing regions meet at boundaries.
Their binary foreground is connected, but two separate seeds can guide a split.
Mint and violet label separate objects. Blue supplies a background marker; unassigned locations begin as unknown.
The coloured fronts expand through the unknown area. This schematic uses symmetric fronts to expose where they meet.
The orange meeting line separates the labels. In OpenCV, image contrast governs the expansion and meeting boundaries are written as −1.
Mark meeting boundaries with −1 in the output marker matrix.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Create foreground seeds from a distance transform of the thresholded mask, then flood the colour image. Red marks watershed boundaries.
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
Separate touching objects when you can provide reliable foreground and background seeds.
How it works
- 01Create distinct positive marker labels and leave unknown pixels at zero.
- 02Expand markers through the image’s local contrast structure.
- 03Mark meeting boundaries with −1 in the output marker matrix.
known seeds → competing region growth → boundaries
What to tune
Use a 3-channel 8-bit image and a signed 32-bit marker matrix. The markers are modified in place.
Where it breaks down
Poor markers produce poor segments. Watershed boundaries alone do not solve object recognition.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.
Related methods
Global thresholding
Divide pixels using one intensity threshold, or choose it automatically with Otsu or the triangle method.
Adaptive thresholding
Compute a different intensity threshold for each local neighbourhood.
Connected components
Give every connected foreground region a distinct integer label.
Contour tracing
Trace the boundary of each binary region as an ordered sequence of points.