Skip to content

Marker-based watershed

Algorithm atlasSegmentation

Grow labelled regions across an image until competing regions meet at boundaries.

Try it on your image ↓

VISUAL WALKTHROUGHSegmentation
REFERENCE INPUTTwo touching objects

Their binary foreground is connected, but two separate seeds can guide a split.

RESULTKeep a boundary where regions meet

The orange meeting line separates the labels. In OpenCV, image contrast governs the expansion and meeting boundaries are written as −1.

STEP 03 / 03

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

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

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.

Input448 × 320
OutputWaiting for a result

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
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Separate touching objects when you can provide reliable foreground and background seeds.

How it works

  1. 01Create distinct positive marker labels and leave unknown pixels at zero.
  2. 02Expand markers through the image’s local contrast structure.
  3. 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.