Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Region-based and watershed segmentation

Region-based segmentation groups pixels into connected regions by a homogeneity rule (region growing, split-and-merge) while watershed segmentation treats the image as a topographic surface and finds watershed lines that separate catchment basins, useful for separating touching objects and marker-ba

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Region-based and watershed segmentation are used when objects are best described by connected areas of similar intensity or when objects touch so that edge-based methods fail. Engineers use region methods in industrial inspection, medical image region extraction, and pre-processing for object recognition and tracking.

Key ideas

Start from first principles and short definitions you must remember.

  • Image: a discrete function I(x,y) defined on a grid of pixels. Pixel coordinates are integers; intensity values are scalar (grayscale) or vectors (colour). Intensities are unitless numbers (often 0–255).

  • Region: a set R of pixels such that R is connected and satisfies a homogeneity predicate P(R). Connected means there is a path between any two pixels in R following the chosen connectivity (4- or 8-neighbourhood).

  • Homogeneity predicate: a boolean function P(R) that returns true when pixels in R are sufficiently similar by some criterion (e.g., intensity variance ≤ T). The predicate is a design choice.

  • Segmentation: a partition of the image domain into regions {R1, R2, ... , Rn} such that each Ri satisfies P(Ri) and the union covers the image (possible with a background region). A segmentation is usually required to be maximal: no two adjacent regions can be merged without violating P.

  • Region growing (seeded): start with one or more seed pixels; iteratively add neighbouring pixels that satisfy the predicate (usually similarity to region mean or seed) until no more pixels can be added. Key assumptions: finite image grid, deterministic predicate, chosen connectivity.

    Formal stopping: region grows monotonically; because image has finite pixels and you do not remove pixels once added, algorithm terminates.

  • Split-and-merge: start with full image region; recursively split regions that are non-homogeneous (quadtree or binary splits) until all leaf regions are homogeneous. Then merge adjacent leaf regions which together satisfy the predicate. Assumptions: splitting strategy (usually square split), termination when regions reach single pixel.

  • Watershed segmentation: view the grayscale image as a topographic surface where pixel intensity is elevation (low values = valleys). Water poured on the surface collects in minima forming catchment basins. Watershed lines are the boundaries where water from different minima would meet. Two common implementations: flooding (immersion) and graph/MST-based watershed (e.g., minimum-spanning forest); marker-controlled watershed is a control strategy applied to either implementation to suppress spurious minima.

    Formal definitions used in universities:

    • Let f(p) be image intensity at pixel p. Define the catchment basin of a regional minimum m as the set of pixels p for which a path of non-increasing intensity from p reaches m and not any other minimum.

    • Watershed lines are pixels that are not assigned to any single catchment basin because they lie on boundaries where basins meet. In digital implementations, use complementary connectivities (e.g., 8-connected basins and 4-connected watershed lines) to avoid topological paradoxes and ensure thin boundaries.

  • Gradient image: often segmentation uses the gradient magnitude |∇I| as the topographic surface to make object boundaries into ridges; compute derivatives by Sobel or finite differences.

  • Marker-controlled watershed: to avoid over-segmentation, first compute markers (internal markers inside objects and external markers for background), then apply watershed on a modified gradient where only minima at marker positions are allowed; this yields stable segments corresponding to objects.

What to draw for exams: for region growing, draw a small pixel grid (5×5 or 7×7), mark seed pixel(s) and show arrows of neighbour inclusion until a final connected region shown with a boundary. For watershed, draw a 3D topographic surface sketch: two valleys separated by a ridge; draw water levels rising and show basins and the watershed line at the ridge. Label minima, catchment basins and watershed lines.

Derivation universities ask for (why watershed separates touching objects):

  1. Replace image I by gradient magnitude g = |∇I| so edges are high ridges; minima lie in homogeneous interiors.
  2. Perform immersion: submerge the landscape from low levels upward; when water from two basins would merge, place a dam (watershed line). Because g is high on true edges, dams form along edges, separating objects.
  3. Marker control forces only selected minima to act as basins, preventing many small minima from producing over-segmentation.

Assumptions: gradient well represents edges; markers placed correctly.

Formulas

g(x,y) = sqrt( (∂I/∂x)^2 + (∂I/∂y)^2 ) — g is gradient magnitude at pixel (x,y); derivatives have units of intensity per pixel (if intensity is unitless, units are 1/pixel); applies when you compute gradient to convert edges into ridges.

MorphGrad = dilate(I, B) - erode(I, B) — morphological gradient using structuring element B; intensities unitless; applies when computing thickened edges for watershed input.

DT(p) = min_{q in Background} d(p,q) — distance transform: DT at pixel p equals minimum distance d to any background pixel q. d may be Euclidean (units: pixels) or city-block. Applies when using distance to find markers from binary objects.

Region homogeneity: for region R, Var(R) = (1/|R|) * sum_{p in R} (I(p) - mean_R)^2 <= T — variance-based predicate; mean_R is region mean intensity, T is threshold (unitless). Applies for split-and-merge and growing.

Topographic distance D_T(p,q) = min_{paths P from p to q} max_{s in P} f(s) — used in formal watershed definitions: the minimum over paths of the maximum elevation along the path. Units: intensity units. Applies in formal proofs of catchment basins.

Worked examples

Example 1 — Region growing (numerical, exam-style)

Given a 5×5 grayscale image I (values 0–255):

Row1: 10 11 10 50 52 Row2: 11 10 12 51 49 Row3: 10 12 10 48 50 Row4: 200 202 198 205 204 Row5: 201 199 203 206 200

Seed at (2,2) (row 2, column 2) with intensity 10. Use 4-connectivity and threshold T = 2 such that a pixel p joins region R if |I(p) - mean_R| ≤ T.

Steps:

  1. Initialize R = {(2,2)}. mean_R = 10.
  2. Check 4-neighbours of (2,2): (1,2)=11, (3,2)=12, (2,1)=11, (2,3)=12. For each, compute |I - mean_R|: |11-10|=1 ≤2 → add (1,2); |12-10|=2 → add (3,2); |11-10|=1 → add (2,1); |12-10|=2 → add (2,3).
  3. Now R = {(2,2),(1,2),(3,2),(2,1),(2,3)}. mean_R = (10+11+12+11+12)/5 = 11.2.
  4. Examine neighbours of new border pixels not yet in R: e.g., (1,1)=10 → |10-11.2|=1.2 ≤2 → add; (1,3)=10 → |10-11.2|=1.2 ≤2 → add; (3,1)=10 → add; (3,3)=10 → add. Also check (1,4)=50 etc: |50-11.2|=38.8 >2 → not added.
  5. After adding four pixels, R has 9 pixels of intensity mostly 10–12; new mean = (96/9) ≈ 10.67. No further neighbouring pixels meet |I-mean_R| ≤2. Growth stops.

Final region mask (1 = in region, 0 = out): Row1: 1 1 1 0 0 Row2: 1 1 1 0 0 Row3: 1 1 1 0 0 Row4: 0 0 0 0 0 Row5: 0 0 0 0 0

Final answer: the region grown from the seed is the 3×3 block in the top-left — these 9 pixels.

Example 2 — Model answer: Describe marker-controlled watershed for two touching circular objects in a noisy image (theory long question)

Question: Explain marker-controlled watershed segmentation, why it reduces over-segmentation, and list steps to segment two touching circular objects. Draw diagrams of the gradient and markers.

Model answer (structured, exam style):

  1. Problem: Watershed on gradient often creates many catchment basins because noise and small intensity fluctuations create many local minima. This over-segmentation must be controlled.
  2. Idea of marker control: supply a small set of reliable markers inside each true object (internal markers) and one or more markers for background (external markers). Force watershed to flood only from these markers; other minima are suppressed.
  3. Steps: a) Smooth the image (e.g., Gaussian) to reduce noise (reference: spatial filtering topic). b) Compute gradient magnitude g = |∇I| to make object boundaries high ridges. c) Compute internal markers: e.g., threshold the distance transform of the binarised objects to find local maxima of distance (peaks at object centers) and label them as markers. d) Compute external marker: complement or find background markers (e.g., border) and assign one label. e) Modify g so that only marker positions are minima. A common operation: impose minima at marker locations by setting g(marker)=min(g)-1 and for other minima raise values (minima imposition via morphological reconstruction). f) Run flooding-based watershed on modified g. Because there are only as many minima as markers, the number of basins equals number of markers, producing desired segmentation.
  4. Explain with diagram: draw two touching circles intensity profile; show gradient image with high values along contact; show markers in centers; show flooded basins meeting at watershed line along contact; label basins B1, B2 and watershed W.
  5. Justify: Marker control eliminates spurious minima produced by noise. Correct marker placement is critical: wrong markers merge or split objects incorrectly.

Conclusion: Marker-controlled watershed is widely used in cell segmentation, industrial part separation, and any task where touching objects must be separated.

Common mistakes

  • Using raw intensity as watershed surface instead of gradient; this often fails to place separators on boundaries.
  • Ignoring over-segmentation issue in watershed and not describing marker selection/creation.
  • Confusing morphological gradient with image gradient (one is morphological, other is derivative-based).
  • In split-and-merge, failing to describe stopping condition (e.g., minimum region size).

For your exam

Question types you will see: definitions (define region, homogeneity predicate, watershed), short notes (compare region growing and split-and-merge), derivations (prove region growing terminates; derive why watershed lines form along ridges), numericals (perform region grow on small matrix), diagram questions (draw topographic surface and watershed), and algorithm descriptions (pseudocode for seeded region growing; steps for marker-controlled watershed).

Full-marks answers include: clear definitions with bold terms, explicit connectivity choice, step-by-step algorithm, termination/complexity remarks, diagrams with labels (pixels, seeds, basins, watershed), and explanation of assumptions and limitations (noise, marker placement).

Quick check

  1. What is a homogeneity predicate?
  2. Why do we apply watershed on the gradient image rather than on raw intensity?
  3. Name two ways to reduce over-segmentation in watershed.

Answers: A homogeneity predicate is a boolean test P(R) that decides whether a pixel set R is uniform enough to be a region; we use the gradient so boundaries become high ridges making watershed lines fall on edges; reduce over-segmentation by marker-controlled watershed and by smoothing (or minima suppression / morphological reconstruction).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?