Digital Image Processing: Image Segmentation

Theoretical Foundations and Mathematical Definition of Image Segmentation

Image segmentation partitions a digital image into its constituent, non-overlapping regions or objects. Formally, let RR represent the entire spatial region occupied by an image. Image segmentation is a process that partitions RR into nn sub-regions, R1,R2,…,RnR_1, R_2, \dots, R_n, such that the following five fundamental conditions are satisfied:

  1. Completeness:

⋃i=1nRi=R\bigcup_{i=1}^n R_i = R

Every pixel in the image must belong to a region; no pixels are left unassigned.

  1. Connectivity:

Ri is a connected set for i=1,2,…,nR_i \text{ is a connected set for } i = 1, 2, \dots, n

The pixels within each partitioned sub-region must form a connected component in terms of spatial adjacency.

  1. Disjointness (Mutually Exclusive Sub-regions):

Ri∩Rj=∅for all i≠jR_i \cap R_j = \emptyset \quad \text{for all } i \neq j

Regions must be strictly disjoint, meaning no pixel can simultaneously belong to more than one region.

  1. Regional Homogeneity (Predicate Satisfaction):

P(Ri)=TRUEfor i=1,2,…,nP(R_i) = \text{TRUE} \quad \text{for } i = 1, 2, \dots, n

A logical predicate P(Ri)P(R_i) evaluates the uniformity of pixels in region RiR_i (e.g., uniformity in intensity, texture, or color) and evaluates to TRUE\text{TRUE} if all pixels within RiR_i satisfy the specified homogeneity condition.

  1. Regional Distinctness:

P(Ri∪Rj)=FALSEfor any adjacent regions Ri and RjP(R_i \cup R_j) = \text{FALSE} \quad \text{for any adjacent regions } R_i \text{ and } R_j

Adjacent regions must differ significantly with respect to the predicate PP. Merging two adjacent distinct regions creates a composite region that fails the homogeneity criterion.


Segmentation based on intensity discontinuities versus region properties

Segmentation algorithms generally follow one of two basic approaches based on intensity properties:

  • Discontinuity-based segmentation: Partitions an image based on abrupt, local changes in intensity (such as isolated points, lines, and edges).

  • Similarity-based (region-based) segmentation: Partitions an image into regions that are similar according to a set of predefined criteria (such as thresholding, region growing, and region splitting/merging).

When segmenting a smooth region of constant intensity, edge detection based on intensity discontinuities reliably recovers the closed outer boundary. However, when segmenting textured or noisy regions, edge-based operations produce many spurious internal and external edges, preventing the formation of a clean, closed boundary. In such cases, segmentation based on region properties (e.g., texture descriptors) produces a coherent, segmented partition.

Digital Derivatives and Intensity Discontinuity Profiles

Abrupt local transitions in gray-level values are modeled mathematically using discrete first-order and second-order derivatives along 1D spatial profiles.

1D Discrete Derivatives

For a discrete 1D intensity function f(x)f(x), derivatives are approximated via finite differences:

  • First-order derivative (Forward difference):

∂f∂x=f′(x)=f(x+1)−f(x)\frac{\partial f}{\partial x} = f'(x) = f(x + 1) - f(x)

  • Second-order derivative (Central second difference):

∂2f∂x2=f′′(x)=f(x+1)+f(x−1)−2f(x)\frac{\partial^2 f}{\partial x^2} = f''(x) = f(x + 1) + f(x - 1) - 2f(x)

Numerical Analysis of Transition Profiles


Profile of image transitions and corresponding derivatives

The behavior of first and second derivatives across fundamental image features—such as ramps, isolated points, flat segments, lines, and steps—is illustrated by the following discrete profile:

  • Image Strip Intensity Values:

[5, 5, 4, 3, 2, 1, 0, 0, 0, 6, 0, 0, 0, 0, 1, 3, 1, 0, 0, 0, 0, 7, 7, 7, 7][5,\, 5,\, 4,\, 3,\, 2,\, 1,\, 0,\, 0,\, 0,\, 6,\, 0,\, 0,\, 0,\, 0,\, 1,\, 3,\, 1,\, 0,\, 0,\, 0,\, 0,\, 7,\, 7,\, 7,\, 7]

  • First-Order Derivative Values:

[−1, −1, −1, −1, −1, 0, 0, 6, −6, 0, 0, 0, 1, 2, −2, −1, 0, 0, 0, 7, 0, 0, 0][-1,\, -1,\, -1,\, -1,\, -1,\, 0,\, 0,\, 6,\, -6,\, 0,\, 0,\, 0,\, 1,\, 2,\, -2,\, -1,\, 0,\, 0,\, 0,\, 7,\, 0,\, 0,\, 0]

  • Second-Order Derivative Values:

[−1, 0, 0, 0, 0, 1, 0, 6, −12, 6, 0, 0, 1, 1, −4, 1, 1, 0, 0, 7, −7, 0, 0][-1,\, 0,\, 0,\, 0,\, 0,\, 1,\, 0,\, 6,\, -12,\, 6,\, 0,\, 0,\, 1,\, 1,\, -4,\, 1,\, 1,\, 0,\, 0,\, 7,\, -7,\, 0,\, 0]

Derivative Behaviors and Comparative Properties

  1. Edge Thickness: First-order derivatives produce thicker, constant-amplitude responses along ramps. Second-order derivatives produce a zero response along flat slopes of a ramp and non-zero responses only at the onset and termination of the ramp.

  2. Sensitivity to Fine Detail: Second-order derivatives have a significantly stronger response to fine details (isolated points, thin lines, impulse noise) than first-order derivatives.

  3. Double-Edge Response: Second-order derivatives produce a characteristic double-line effect at ramp and step transitions (a positive spike followed by a negative spike, or vice versa).

  4. Sign and Edge Transition Direction: The sign of the second derivative determines whether an intensity transition is from light to dark (positive then negative) or from dark to light (negative then positive).

  5. Zero-Crossing: The point where the second derivative changes sign passes through zero precisely at the center of a ramp edge, providing a reliable marker for edge localization.

Detection of Isolated Points and Lines

Point Detection

An isolated point differs significantly from its local background. Detecting an isolated point requires a spatial operator that responds strongly to sharp localized discontinuities in all directions. This is achieved using the 2D Laplacian operator.

Continuous and Discrete Formulation of the 2D Laplacian

The 2D continuous Laplacian is defined as:

∇2f(x,y)=∂2f∂x2+∂2f∂y2\nabla^2 f(x, y) = \frac{\partial^2 f}{\partial x^2} + \frac{\partial^2 f}{\partial y^2}

Using discrete finite differences along the xx and yy axes:

∂2f∂x2=f(x+1,y)+f(x−1,y)−2f(x,y)\frac{\partial^2 f}{\partial x^2} = f(x + 1, y) + f(x - 1, y) - 2f(x, y)

∂2f∂y2=f(x,y+1)+f(x,y−1)−2f(x,y)\frac{\partial^2 f}{\partial y^2} = f(x, y + 1) + f(x, y - 1) - 2f(x, y)

Combining these yields the standard 4-neighbor discrete Laplacian:

∇2f(x,y)=f(x+1,y)+f(x−1,y)+f(x,y+1)+f(x,y−1)−4f(x,y)\nabla^2 f(x, y) = f(x + 1, y) + f(x - 1, y) + f(x, y + 1) + f(x, y - 1) - 4f(x, y)

Including diagonal terms yields the isotropic 8-neighbor Laplacian mask:

[1111−81111]\begin{bmatrix} 1 & 1 & 1 \\ 1 & -8 & 1 \\ 1 & 1 & 1 \end{bmatrix}

Spatial Mask Filtering and Thresholding

For a 3×33 \times 3 neighborhood centered at (x,y)(x, y) with mask weights wkw_k and pixel intensities zkz_k:

R(x,y)=∑k=19wkzkR(x, y) = \sum_{k=1}^9 w_k z_k

A point at (x,y)(x, y) is classified as an isolated point if the absolute value of the response exceeds a specified non-negative threshold TT:

g(x,y)={1if ∣R(x,y)∣≥T0otherwiseg(x, y) = \begin{cases} 1 & \text{if } |R(x, y)| \ge T \\ 0 & \text{otherwise} \end{cases}


Point detection mask and turbine blade porosity application

In industrial non-destructive testing, such as examining X-ray images of turbine blades, manufacturing porosity often appears as a single dark pixel. Convolving the image with the point detection mask and thresholding the output isolates the porosity.

Line Detection

Second derivatives produce a stronger response and thinner lines than first derivatives. However, the double-line effect of the second derivative must be handled by taking either the absolute value or only the positive values of the Laplacian.

Direction-Specific Line Detectors


Directional line detection masks

To detect lines oriented in specific directions, four 3×33 \times 3 masks are used:

  • Horizontal Mask (R1R_1):

[−1−1−1222−1−1−1]\begin{bmatrix} -1 & -1 & -1 \\ 2 & 2 & 2 \\ -1 & -1 & -1 \end{bmatrix}

  • +45∘+45^\circ Diagonal Mask (R2R_2):

[2−1−1−12−1−1−12]\begin{bmatrix} 2 & -1 & -1 \\ -1 & 2 & -1 \\ -1 & -1 & 2 \end{bmatrix}

  • Vertical Mask (R3R_3):

[−12−1−12−1−12−1]\begin{bmatrix} -1 & 2 & -1 \\ -1 & 2 & -1 \\ -1 & 2 & -1 \end{bmatrix}

  • −45∘-45^\circ Diagonal Mask (R4R_4):

[−1−12−12−12−1−1]\begin{bmatrix} -1 & -1 & 2 \\ -1 & 2 & -1 \\ 2 & -1 & -1 \end{bmatrix}

Each mask sums to zero, ensuring a zero response over regions of constant intensity.

Directional Selection Rule

Let R1,R2,R3,R4R_1, R_2, R_3, R_4 be the responses of the four masks at a given point (x,y)(x, y). The point is associated with the direction of mask kk if:

∣Rk∣>∣Rj∣for all j≠k|R_k| > |R_j| \quad \text{for all } j \neq k

To find lines of a specific orientation (e.g., +45∘+45^\circ), the image is filtered with that mask, negative values are set to zero, and the result is thresholded at g≥Tg \ge T.


Wire-bond template line detection

Edge Detection Principles and Models

An edge is a set of connected pixels that lie on the boundary between two regions characterized by distinct intensity levels.

Edge Models


Ideal representations of step, ramp, and roof edges

Edges are classified into three geometric models:

  1. Step Edge: An abrupt, instantaneous change in intensity occurring over a distance of 1 pixel. Step edges occur at clean physical boundaries and borders in range imaging.

  2. Ramp Edge: An intensity transition that increases or decreases gradually over a finite distance (several pixels). Real-world optical blurring, lighting transitions, and finite sensor sampling render most edges as ramps.

  3. Roof Edge: An intensity profile that rises and falls over a narrow region. Roof edges appear in range imaging when objects are closer to the sensor than the background, in thin line digitizations, and as roadways in satellite imagery.

In natural images, edge widths vary considerably. For instance, in a 1508×19701508 \times 1970 pixel scene, practical ramp edge profiles can span 9 pixels, step-like transitions can span 2 pixels, and the base of a roof edge may span 3 pixels.

Mathematical Behavior Across a Ramp Edge


Ramp edge profile and derivative signatures

Across an ideal ramp transition:

  • Intensity Profile f(x)f(x): Constant low value, linear ramp slope, constant high value.

  • First Derivative f′(x)f'(x): Constant zero on both flat sides, constant positive value across the ramp transition (producing a thick pulse proportional to edge width).

  • Second Derivative f′′(x)f''(x): Zero in flat regions, a positive impulse at the onset of the ramp, zero along the linear slope, a negative impulse at the end of the ramp, and a zero crossing precisely at the inflection point.

The Three-Stage Edge Detection Pipeline

Edge detection requires three sequential operations:

  1. Image Smoothing for Noise Reduction: High-frequency noise corrupts derivative operators. Smoothing filters suppress noise prior to differentiation.

  2. Detection of Edge Points: Local spatial operators (gradient or Laplacian) identify all candidate edge points.

  3. Edge Localization: Thresholding and nonmaxima suppression extract true edge points while discarding false responses.

Impact of Additive Gaussian Noise


Effects of Gaussian noise on ramp edge derivatives

Noise degrades derivative operations. When zero-mean additive Gaussian noise is added to a ramp edge:

  • At σ=0.0\sigma = 0.0, derivatives are clean and unambiguous.

  • At σ=0.1\sigma = 0.1, slight ripples appear in derivative profiles.

  • At σ=1.0\sigma = 1.0, noise peaks match derivative amplitudes.

  • At σ=10.0\sigma = 10.0, derivative profiles are dominated by noise, obscuring true zero-crossings and first-derivative peaks.

lFirst-Order Gradient Operators and Vector Analysis

First-order edge detection relies on the gradient of a 2D continuous or discrete image function f(x,y)f(x, y).

Vector Definition, Magnitude, and Direction

The gradient is a 2D column vector pointing in the direction of the maximum rate of change of ff:

∇f≡grad(f)=[gxgy]=[∂f∂x∂f∂y]\nabla f \equiv \text{grad}(f) = \begin{bmatrix} g_x \\ g_y \end{bmatrix} = \begin{bmatrix} \frac{\partial f}{\partial x} \\ \frac{\partial f}{\partial y} \end{bmatrix}

  • Magnitude of the Gradient:

M(x,y)=mag(∇f)=gx2+gy2M(x, y) = \text{mag}(\nabla f) = \sqrt{g_x^2 + g_y^2}

  • Computational Approximations:

mag(∇f)≈∣gx∣+∣gy∣\text{mag}(\nabla f) \approx |g_x| + |g_y|

mag(∇f)≈max⁡(∣gx∣, ∣gy∣)\text{mag}(\nabla f) \approx \max(|g_x|,\, |g_y|)

  • Direction of the Gradient Vector:

α(x,y)=tan⁡−1[gxgy]\alpha(x, y) = \tan^{-1}\left[\frac{g_x}{g_y}\right]

  • Direction of the Edge:

The physical direction of an edge at (x,y)(x, y) is perpendicular to the gradient vector:

ϕ=α−90∘\phi = \alpha - 90^\circ


Relationship between gradient vector and edge orientation

Spatial Gradient Masks

For a 3×33 \times 3 neighborhood labeled as follows:

[z1z2z3z4z5z6z7z8z9]\begin{bmatrix} z_1 & z_2 & z_3 \\ z_4 & z_5 & z_6 \\ z_7 & z_8 & z_9 \end{bmatrix}

1D Finite Difference Masks
  • Vertical component gxg_x: [−11]\begin{bmatrix} -1 \\ 1 \end{bmatrix}

  • Horizontal component gyg_y: [−11]\begin{bmatrix} -1 & 1 \end{bmatrix}

Roberts Cross-Gradient Operators (2×22 \times 2)

gx=(z9−z5)  ⟹  [−1001]g_x = (z_9 - z_5) \implies \begin{bmatrix} -1 & 0 \\ 0 & 1 \end{bmatrix}

gy=(z8−z6)  ⟹  [0−110]g_y = (z_8 - z_6) \implies \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}

Prewitt Operators (3×33 \times 3)
  • Horizontal (gxg_x):

[−1−1−1000111]\begin{bmatrix} -1 & -1 & -1 \\ 0 & 0 & 0 \\ 1 & 1 & 1 \end{bmatrix}

  • Vertical (gyg_y):

[−101−101−101]\begin{bmatrix} -1 & 0 & 1 \\ -1 & 0 & 1 \\ -1 & 0 & 1 \end{bmatrix}

Sobel Operators (3×33 \times 3)

Sobel operators apply a weight of 2 to the central coefficient to smooth along the direction orthogonal to differentiation, reducing noise sensitivity:

  • Horizontal (gxg_x):

[−1−2−1000121]\begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \end{bmatrix}

  • Vertical (gyg_y):

[−101−202−101]\begin{bmatrix} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 \end{bmatrix}

Diagonal Edge Operators


Prewitt and Sobel diagonal edge detection masks
  • Prewitt Diagonal Masks:

[011−101−1−10]and[−1−10−101011]\begin{bmatrix} 0 & 1 & 1 \\ -1 & 0 & 1 \\ -1 & -1 & 0 \end{bmatrix} \quad \text{and} \quad \begin{bmatrix} -1 & -1 & 0 \\ -1 & 0 & 1 \\ 0 & 1 & 1 \end{bmatrix}

  • Sobel Diagonal Masks:

[012−101−2−10]and[−2−10−101012]\begin{bmatrix} 0 & 1 & 2 \\ -1 & 0 & 1 \\ -2 & -1 & 0 \end{bmatrix} \quad \text{and} \quad \begin{bmatrix} -2 & -1 & 0 \\ -1 & 0 & 1 \\ 0 & 1 & 2 \end{bmatrix}

Practical Filtering Pipeline on Complex Scenes

In complex scenes (such as an 834×1114834 \times 1114 pixel image scaled to [0,1][0, 1]):

  1. Raw gradient filtering via Sobel masks yields directional components ∣gx∣|g_x| and ∣gy∣|g_y|, and composite gradient ∣gx∣+∣gy∣|g_x| + |g_y|.

  2. Smoothing with a 5×55 \times 5 averaging filter prior to computing gradients eliminates micro-texture (e.g., mortar lines in brick walls) while preserving structural edges.

  3. Setting a global gradient threshold at 33%33\% of the maximum value isolates dominant structural boundaries.

Advanced Edge Detectors: Marr-Hildreth and Canny

The Marr-Hildreth Edge Detector

The Marr-Hildreth algorithm filters an image with a Gaussian to control detail scale, followed by a second-order Laplacian operator to locate edges via zero-crossings.

The Laplacian of Gaussian (LoG)

The 2D Gaussian function is:

G(x,y)=e−x2+y22σ2G(x, y) = e^{-\frac{x^2 + y^2}{2\sigma^2}}

where σ\sigma is the space constant (standard deviation).

Applying the Laplacian operator yields the Laplacian of Gaussian (LoG):

∇2G(x,y)=∂2G∂x2+∂2G∂y2=[x2+y2−2σ2σ4]e−x2+y22σ2\nabla^2 G(x, y) = \frac{\partial^2 G}{\partial x^2} + \frac{\partial^2 G}{\partial y^2} = \left[\frac{x^2 + y^2 - 2\sigma^2}{\sigma^4}\right] e^{-\frac{x^2 + y^2}{2\sigma^2}}


Three-dimensional profile and cross section of the LoG function

The cross-section exhibits a central lobe flanked by negative lobes ("Mexican hat"). The distance between its zero-crossings is:

w=22σw = 2\sqrt{2}\sigma

A discrete 5×55 \times 5 integer approximation to the negative of this shape is:

[00−1000−1−2−10−1−216−2−10−1−2−1000−100]\begin{bmatrix} 0 & 0 & -1 & 0 & 0 \\ 0 & -1 & -2 & -1 & 0 \\ -1 & -2 & 16 & -2 & -1 \\ 0 & -1 & -2 & -1 & 0 \\ 0 & 0 & -1 & 0 & 0 \end{bmatrix}

Marr-Hildreth Algorithm Steps
  1. Filter the input image f(x,y)f(x, y) with an n×nn \times n Gaussian lowpass filter, where nn is chosen as the smallest odd integer greater than or equal to 6σ6\sigma:

n≥6σn \ge 6\sigma

  1. Compute the Laplacian of the smoothed image:

g(x,y)=∇2[G(x,y)⋆f(x,y)]=[∇2G(x,y)]⋆f(x,y)g(x, y) = \nabla^2 [G(x, y) \star f(x, y)] = [\nabla^2 G(x, y)] \star f(x, y)

  1. Determine the zero-crossings of g(x,y)g(x, y). A pixel is marked as a zero-crossing if the signs of opposing neighbors differ and their absolute difference exceeds a threshold.

Thresholding zero-crossings at 00 yields closed-loop edges ("spaghetti effect"). Setting the threshold to 4%4\% of the maximum value of the LoG response suppresses weak zero-crossings and preserves thin, meaningful edges.

The Canny Edge Detector

The Canny detector satisfies three key performance criteria for step edges corrupted by white noise:

  • Low Error Rate: All true edges should be detected, and no false edges should be created.

  • Localization: The distance between detected edge pixels and actual physical edge centers must be minimized.

  • Single Edge Response: The detector must return only a single point for each edge pixel, suppressing false multiple responses across broad profiles.

Canny Edge Detection Algorithm
Step 1: Gaussian Smoothing

Smooth the input image f(x,y)f(x, y) using a Gaussian filter G(x,y)G(x, y):

fs(x,y)=G(x,y)⋆f(x,y)f_s(x, y) = G(x, y) \star f(x, y)

Step 2: Gradient Vector Computation

Compute the gradient magnitude M(x,y)M(x, y) and direction α(x,y)\alpha(x, y) using Sobel masks:

M(x,y)=gx2+gy2M(x, y) = \sqrt{g_x^2 + g_y^2}

α(x,y)=arctan⁡(gygx)\alpha(x, y) = \arctan\left(\frac{g_y}{g_x}\right)

Step 3: Nonmaxima Suppression (NMS)

Gradient magnitude arrays display wide ridges around local maxima. Nonmaxima suppression thins these ridges to 1-pixel-wide lines.


Angle ranges for the four basic edge directions in a 3x3 neighborhood

Define four basic discrete edge directions in a 3×33 \times 3 neighborhood:

  • d1d_1: Horizontal (0∘0^\circ)

  • d2d_2: −45∘-45^\circ

  • d3d_3: Vertical (90∘90^\circ)

  • d4d_4: +45∘+45^\circ

The normal direction α\alpha is mapped into one of four sectors:

  1. If α∈[−22.5∘,22.5∘]\alpha \in [-22.5^\circ, 22.5^\circ] or α∈[157.5∘,−157.5∘]\alpha \in [157.5^\circ, -157.5^\circ], the edge normal is horizontal, corresponding to a vertical edge (d3d_3).

  2. If α∈[22.5∘,67.5∘]\alpha \in [22.5^\circ, 67.5^\circ] or α∈[−157.5∘,−112.5∘]\alpha \in [-157.5^\circ, -112.5^\circ], the edge direction is −45∘-45^\circ (d2d_2).

  3. If α∈[67.5∘,112.5∘]\alpha \in [67.5^\circ, 112.5^\circ] or α∈[−112.5∘,−67.5∘]\alpha \in [-112.5^\circ, -67.5^\circ], the edge normal is vertical, corresponding to a horizontal edge (d1d_1).

  4. If α∈[112.5∘,157.5∘]\alpha \in [112.5^\circ, 157.5^\circ] or α∈[−67.5∘,−22.5∘]\alpha \in [-67.5^\circ, -22.5^\circ], the edge direction is +45∘+45^\circ (d4d_4).

Let pp be the current pixel. Inspect its two neighbors along the mapped normal direction dkd_k. If M(x,y)M(x, y) is strictly less than at least one of these two neighbors, set gN(x,y)=0g_N(x, y) = 0; otherwise, retain gN(x,y)=M(x,y)g_N(x, y) = M(x, y).

Step 4: Hysteresis Thresholding

Suppress false edge points using two thresholds: a high threshold THT_H and a low threshold TLT_L (typically with a ratio TH/TLT_H / T_L between 2:12:1 and 3:13:1):

gNH(x,y)=gN(x,y)≥THg_{NH}(x, y) = g_N(x, y) \ge T_H

gNL(x,y)=gN(x,y)≥TLg_{NL}(x, y) = g_N(x, y) \ge T_L

Subtract strong edges from weak edges to form an isolated weak-edge image:

gNL(x,y)=gNL(x,y)−gNH(x,y)g_{NL}(x, y) = g_{NL}(x, y) - g_{NH}(x, y)

Step 5: Connectivity Analysis and Edge Linking
  1. Locate the next unvisited strong edge pixel pp in gNH(x,y)g_{NH}(x, y).

  2. Mark as valid edge pixels all weak pixels in gNL(x,y)g_{NL}(x, y) that are connected to pp via an 8-connected path.

  3. Repeat until all non-zero pixels in gNH(x,y)g_{NH}(x, y) have been visited.

  4. Set all unmarked pixels in gNL(x,y)g_{NL}(x, y) to zero.


Comparative performance of edge detection methods


Canny and Marr-Hildreth performance on head CT scan

Edge Linking and Boundary Detection

Edge detection often yields broken boundaries due to noise, uneven illumination, and non-uniform material properties. Edge linking algorithms assemble edge pixels into continuous, closed boundaries.

Local Processing

Local processing inspects a small neighborhood SxyS_{xy} centered at every declared edge point (x,y)(x, y). A neighboring edge pixel at (s,t)∈Sxy(s, t) \in S_{xy} is linked to (x,y)(x, y) if both magnitude and directional similarity criteria are met:

  • Magnitude Similarity:

∣M(s,t)−M(x,y)∣≤E|M(s, t) - M(x, y)| \le E

  • Angle Similarity:

∣α(s,t)−α(x,y)∣≤A|\alpha(s, t) - \alpha(x, y)| \le A

Alternatively, a binary linked image g(x,y)g(x, y) is constructed directly using thresholds on gradient magnitude and angle:

g(x,y)={1if M(x,y)>TM and α(x,y)=A±TA0otherwiseg(x, y) = \begin{cases} 1 & \text{if } M(x, y) > T_M \text{ and } \alpha(x, y) = A \pm T_A \\ 0 & \text{otherwise} \end{cases}

where TMT_M is the magnitude threshold, AA is the specified angle, and TAT_A defines an acceptable angular band about AA.

Rows or columns are subsequently scanned to fill isolated gaps of zeros that do not exceed a length KK.

Regional Processing: Iterative Polygonal Fit


Iterative polygonal fit algorithm mechanics

When edge points delimit a closed or open boundary of a known region, polygonal approximations simplify the boundary representation.

The Polygonal Fit Algorithm

Let PP be an ordered sequence of distinct 1-valued contour pixels. Define two stacks: OPEN\text{OPEN} and CLOSED\text{CLOSED}, and specify a tolerance threshold TT.

  1. Initialization:

    • If the curve is closed: select starting vertices AA and BB. Push AA into OPEN\text{OPEN}, and push BB into both OPEN\text{OPEN} and CLOSED\text{CLOSED}.

    • If the curve is open: push AA into OPEN\text{OPEN} and BB into CLOSED\text{CLOSED}.

  2. Line Fitting: Compute the parameters of a straight line connecting the top vertex of CLOSED\text{CLOSED} to the top vertex of OPEN\text{OPEN}.

  3. Distance Evaluation: Compute the perpendicular distances from this line to all points in PP located between these two vertices. Find the point Vmax⁡V_{\max} with the maximum distance Dmax⁡D_{\max}.

  4. Branching Condition:

    • If Dmax⁡>TD_{\max} > T, push Vmax⁡V_{\max} onto OPEN\text{OPEN} as a new vertex. Return to Step 2.

    • If Dmax⁡≤TD_{\max} \le T, pop the top vertex from OPEN\text{OPEN} and push it onto CLOSED\text{CLOSED}.

  5. Termination: If OPEN\text{OPEN} is not empty, return to Step 2. If OPEN\text{OPEN} is empty, exit. The points in CLOSED\text{CLOSED} form the vertices of the polygonal approximation.

Execution Trace for a Closed Curve

CLOSED Stack

OPEN Stack

Curve Segment Processed

Vertex Generated

BB

B,AB, A

—

A,BA, B

BB

B,AB, A

(BA)(BA)

CC

BB

B,A,CB, A, C

(BC)(BC)

—

B,CB, C

B,AB, A

(CA)(CA)

—

B,C,AB, C, A

BB

(AB)(AB)

DD

B,C,AB, C, A

B,DB, D

(AD)(AD)

—

B,C,A,DB, C, A, D

BB

(DB)(DB)

—

B,C,A,D,BB, C, A, D, B

Empty

—

—

Global Processing: The Hough Transform

When broken edge points cannot be grouped locally, global arrangements are extracted using the Hough Transform, developed by Paul Hough in 1962.

Parameterization of Lines

Representing lines in Cartesian form (y=ax+by = ax + b) fails for vertical lines because the slope a→∞a \rightarrow \infty. The normal (polar) parameterization resolves this issue:

xcos⁡θ+ysin⁡θ=ρx \cos\theta + y \sin\theta = \rho

where:

  • ρ\rho is the perpendicular distance from the coordinate origin to the line.

  • θ\theta is the angle of the normal vector relative to the horizontal axis.


Hough transform geometry and accumulator cell subdivision
Properties of Parameter Space
  1. A single point (xi,yi)(x_i, y_i) in the spatial plane maps to a sinusoidal curve in the ρθ\rho\theta-parameter plane:

ρ=xicos⁡θ+yisin⁡θ\rho = x_i \cos\theta + y_i \sin\theta

  1. Collinear spatial points correspond to sinusoidal curves that intersect at a single parameter point (ρ′,θ′)(\rho', \theta').

  2. The parameter space is discretized into accumulator cells spanning θ∈[−90∘,90∘]\theta \in [-90^\circ, 90^\circ] and ρ∈[−M2+N2, M2+N2]\rho \in [-\sqrt{M^2 + N^2},\, \sqrt{M^2 + N^2}] for an M×NM \times N image.

Edge Linking Algorithm Based on the Hough Transform
  1. Compute a binary edge image (e.g., using Canny or Sobel operators).

  2. Divide the ρθ\rho\theta-plane into accumulator cells A(ρ,θ)A(\rho, \theta) initialized to zero.

  3. For each non-zero edge pixel (xk,yk)(x_k, y_k), compute ρ\rho for every quantized θ\theta value and increment the corresponding cell: A(ρ,θ)=A(ρ,θ)+1A(\rho, \theta) = A(\rho, \theta) + 1.

  4. Find the local maxima in A(ρ,θ)A(\rho, \theta) that exceed a count threshold.

  5. Map peak cells back to lines in image space and link collinear edge segments by bridging gaps that are smaller than a specified pixel distance.


Hough transform runway extraction from an aerial image

Intensity Thresholding and Noise Degradation

Formulations of Thresholding

  • Single Global Thresholding:

g(x,y)={1if f(x,y)>T(object point)0if f(x,y)≤T(background point)g(x, y) = \begin{cases} 1 & \text{if } f(x, y) > T \quad \text{(object point)} \\ 0 & \text{if } f(x, y) \le T \quad \text{(background point)} \end{cases}

  • Multiple Thresholding:

g(x,y)={aif f(x,y)>T2bif T1<f(x,y)≤T2cif f(x,y)≤T1g(x, y) = \begin{cases} a & \text{if } f(x, y) > T_2 \\ b & \text{if } T_1 < f(x, y) \le T_2 \\ c & \text{if } f(x, y) \le T_1 \end{cases}

Role of Noise and Illumination Non-Uniformity


Degradation of bimodal histograms by additive noise


Degradation of histograms due to an illumination ramp

In ideal noiseless images, histograms of bimodal scenes exhibit distinct spikes separated by broad valleys. However, two phenomena compromise global thresholding:

  1. Additive Gaussian Noise: As noise variance increases (from σ=0\sigma = 0 to σ=10\sigma = 10 and σ=50\sigma = 50), the valley separating the foreground and background modes broadens, flattens, and eventually merges into a single unimodal distribution.

  2. Spatial Illumination Variations: Multiplying a scene by an intensity gradient (e.g., a spatial ramp from 0.20.2 to 0.60.6) shifts the local reflectance values, causing the modes to spread across the intensity spectrum and obscuring the valley.

Basic Global Thresholding (Iterative Algorithm)

  1. Select an initial estimate for the global threshold TT (typically the average intensity of the image).

  2. Segment the image using TT, producing two pixel groups:

    • G1G_1: pixels with f(x,y)>Tf(x, y) > T

    • G2G_2: pixels with f(x,y)≤Tf(x, y) \le T

  3. Compute the average intensities m1m_1 and m2m_2 of regions G1G_1 and G2G_2:

m1=1∣G1∣∑(x,y)∈G1f(x,y)m_1 = \frac{1}{|G_1|} \sum_{(x, y) \in G_1} f(x, y)

m2=1∣G2∣∑(x,y)∈G2f(x,y)m_2 = \frac{1}{|G_2|} \sum_{(x, y) \in G_2} f(x, y)

  1. Compute an updated threshold value:

Tnew=12(m1+m2)T_{\text{new}} = \frac{1}{2}(m_1 + m_2)

  1. Repeat Steps 2 through 4 until the difference between successive thresholds satisfies:

∣Tnew−Told∣<ΔT|T_{\text{new}} - T_{\text{old}}| < \Delta T

where ΔT\Delta T is a predefined convergence threshold.

Optimal Global Thresholding: Otsu's Method

Otsu's method (1979) selects a global threshold by maximizing the between-class variance σB2\sigma_B^2, which measures the statistical separability of classes.

Statistical Formulation

Let an image of size M×NM \times N have LL distinct gray levels {0,1,2,…,L−1}\{0, 1, 2, \dots, L - 1\}. Let nin_i denote the count of pixels with intensity ii.

The normalized histogram represents the probability distribution of gray levels:

pi=niMNsuch that∑i=0L−1pi=1p_i = \frac{n_i}{MN} \quad \text{such that} \quad \sum_{i=0}^{L-1} p_i = 1

Partition the pixels into two classes using a threshold kk (0≤k≤L−10 \le k \le L - 1):

  • C1C_1: gray levels in [0,k][0, k]

  • C2C_2: gray levels in [k+1,L−1][k + 1, L - 1]

Cumulative Probabilities of Occurrence

P1(k)=∑i=0kpiP_1(k) = \sum_{i=0}^k p_i

P2(k)=∑i=k+1L−1pi=1−P1(k)P_2(k) = \sum_{i=k+1}^{L-1} p_i = 1 - P_1(k)

Class Means

m1(k)=∑i=0kiP(i∣C1)=1P1(k)∑i=0kipim_1(k) = \sum_{i=0}^k i P(i \mid C_1) = \frac{1}{P_1(k)} \sum_{i=0}^k i p_i

m2(k)=∑i=k+1L−1iP(i∣C2)=1P2(k)∑i=k+1L−1ipim_2(k) = \sum_{i=k+1}^{L-1} i P(i \mid C_2) = \frac{1}{P_2(k)} \sum_{i=k+1}^{L-1} i p_i

Global Mean and Cumulative Mean

The cumulative mean up to intensity level kk is:

m(k)=∑i=0kipi=P1(k)m1(k)m(k) = \sum_{i=0}^k i p_i = P_1(k) m_1(k)

The global mean intensity across the entire image is:

mG=∑i=0L−1ipi=P1m1+P2m2m_G = \sum_{i=0}^{L-1} i p_i = P_1 m_1 + P_2 m_2

Between-Class Variance Derivation

The between-class variance σB2\sigma_B^2 is defined as:

σB2(k)=P1(m1−mG)2+P2(m2−mG)2\sigma_B^2(k) = P_1(m_1 - m_G)^2 + P_2(m_2 - m_G)^2

Substituting mG=P1m1+P2m2m_G = P_1 m_1 + P_2 m_2 and P2=1−P1P_2 = 1 - P_1 yields:

σB2(k)=P1P2(m1−m2)2=[mGP1(k)−m(k)]2P1(k)[1−P1(k)]\sigma_B^2(k) = P_1 P_2 (m_1 - m_2)^2 = \frac{[m_G P_1(k) - m(k)]^2}{P_1(k)[1 - P_1(k)]}

Threshold Optimization and Separability Measure

The optimal threshold k∗k^* is the index that maximizes σB2(k)\sigma_B^2(k):

σB2(k∗)=max⁡0≤k<L−1σB2(k)\sigma_B^2(k^*) = \max_{0 \le k < L-1} \sigma_B^2(k)

If the maximum is not unique, the optimal threshold is calculated as the average of the maximizing indices.

The global variance of the image is:

σG2=∑i=0L−1(i−mG)2pi\sigma_G^2 = \sum_{i=0}^{L-1} (i - m_G)^2 p_i

The separability measure η\eta evaluates the quality of the thresholding (0≤η≤10 \le \eta \le 1):

η=σB2(k∗)σG2\eta = \frac{\sigma_B^2(k^*)}{\sigma_G^2}

Algorithmic Summary of Otsu's Method

  1. Compute the normalized histogram pip_i for i=0,1,…,L−1i = 0, 1, \dots, L - 1.

  2. Compute the cumulative sums P1(k)P_1(k) for k=0,1,…,L−1k = 0, 1, \dots, L - 1.

  3. Compute the cumulative means m(k)m(k) for k=0,1,…,L−1k = 0, 1, \dots, L - 1.

  4. Compute the global intensity mean mGm_G.

  5. Compute the between-class variance σB2(k)\sigma_B^2(k) for all kk.

  6. Find k∗k^* that maximizes σB2(k)\sigma_B^2(k).

  7. Segment the image into background and foreground using k∗k^*:

g(x,y)={1if f(x,y)>k∗0if f(x,y)≤k∗g(x, y) = \begin{cases} 1 & \text{if } f(x, y) > k^* \\ 0 & \text{if } f(x, y) \le k^* \end{cases}

Enhancements for Challenging Conditions

Image Smoothing to Restore Bimodality

When heavy additive noise blurs histogram peaks into a unimodal distribution, Otsu's method on the raw image often fails. Pre-filtering with a 5×55 \times 5 spatial averaging mask attenuates noise variance, re-establishing a bimodal profile and enabling successful thresholding.

Edge-Assisted Global Thresholding

When an object is small relative to the image area, background pixels dominate the histogram, suppressing the object mode into an imperceptible tail and causing Otsu's method to fail.


Edge-assisted histogram construction and thresholding

To correct for skewed class proportions:

  1. Compute an edge image using either the gradient magnitude or the absolute Laplacian of f(x,y)f(x, y).

  2. Threshold the edge image at a high percentile (e.g., the 99.7th99.7^{\text{th}} percentile) to produce a sparse binary edge mask.

  3. Compute an intensity histogram using only the pixels in f(x,y)f(x, y) that coincide with the non-zero mask pixels.

  4. Apply Otsu's algorithm to this edge-conditioned histogram to determine the optimal threshold (e.g., T=134T = 134), which will lie midway between the object and background peaks.

  5. Segment the entire original image globally using this threshold.

Multiple Thresholds for Multimodal Distributions

For KK distinct classes C1,C2,…,CKC_1, C_2, \dots, C_K, the between-class variance generalized to K−1K - 1 thresholds {k1,k2,…,kK−1}\{k_1, k_2, \dots, k_{K-1}\} is:

σB2=∑k=1KPk(mk−mG)2\sigma_B^2 = \sum_{k=1}^K P_k (m_k - m_G)^2

where:

Pk=∑i∈Ckpiandmk=1Pk∑i∈CkipiP_k = \sum_{i \in C_k} p_i \quad \text{and} \quad m_k = \frac{1}{P_k} \sum_{i \in C_k} i p_i

The optimal thresholds satisfy:

σB2(k1∗,k2∗,…,kK−1∗)=max⁡0≤k1<k2<⋯<L−1σB2(k1,k2,…,kK−1)\sigma_B^2(k_1^*, k_2^*, \dots, k_{K-1}^*) = \max_{0 \le k_1 < k_2 < \dots < L-1} \sigma_B^2(k_1, k_2, \dots, k_{K-1})

Spatially Adaptive and Variable Thresholding

When background illumination varies across an image, global thresholding fails. Spatially adaptive methods vary the threshold T(x,y)T(x, y) as a function of local coordinates.

Image Partitioning

The image is subdivided into non-overlapping rectangular blocks chosen small enough that illumination across each block is approximately uniform. Otsu's method is then applied to each subimage individually.

Variable Thresholding Based on Local Image Properties

Let σxy\sigma_{xy} and mxym_{xy} denote the local standard deviation and local mean within a neighborhood SxyS_{xy} centered at (x,y)(x, y). The local threshold is defined as:

Txy=aσxy+bmxyT_{xy} = a\sigma_{xy} + bm_{xy}

If the background intensity is nearly constant across the scene, the global mean mGm_G can replace the local mean:

Txy=aσxy+bmGT_{xy} = a\sigma_{xy} + bm_G

The image is thresholded according to:

g(x,y)={1if f(x,y)>Txy0if f(x,y)≤Txyg(x, y) = \begin{cases} 1 & \text{if } f(x, y) > T_{xy} \\ 0 & \text{if } f(x, y) \le T_{xy} \end{cases}

Dual Predicate Formulation

Alternatively, local parameters can be evaluated using a logical predicate QQ:

g(x,y)={1if Q(local parameters) is TRUE0otherwiseg(x, y) = \begin{cases} 1 & \text{if } Q(\text{local parameters}) \text{ is TRUE} \\ 0 & \text{otherwise} \end{cases}

For example:

Q(σxy,mxy)={TRUEif f(x,y)>aσxy AND f(x,y)>bmxyFALSEotherwiseQ(\sigma_{xy}, m_{xy}) = \begin{cases} \text{TRUE} & \text{if } f(x, y) > a\sigma_{xy} \text{ AND } f(x, y) > bm_{xy} \\ \text{FALSE} & \text{otherwise} \end{cases}

Variable Thresholding Using Moving Averages

For text document processing and scenes containing small features affected by illumination gradients, local thresholding based on moving averages provides efficient, real-time segmentation. To prevent spatial bias, images are scanned row-by-row in a continuous zigzag pattern.

Recursive Moving Average Computation

Let zk+1z_{k+1} denote the intensity of the pixel encountered at step k+1k + 1 along the scan path. The moving average over a window of length nn is updated recursively:

m(k+1)=1n∑i=k+2−nk+1zi=m(k)+1n(zk+1−zk)m(k + 1) = \frac{1}{n} \sum_{i=k+2-n}^{k+1} z_i = m(k) + \frac{1}{n}(z_{k+1} - z_k)

Border pixels are padded with n−1n - 1 zeros, and the initial value is m(1)=z1/nm(1) = z_1 / n.

Segmentation Criterion

The local threshold at (x,y)(x, y) is scaled using a constant multiplier bb:

Txy=b⋅mxyT_{xy} = b \cdot m_{xy}

g(x,y)={1if f(x,y)>Txy0if f(x,y)≤Txyg(x, y) = \begin{cases} 1 & \text{if } f(x, y) > T_{xy} \\ 0 & \text{if } f(x, y) \le T_{xy} \end{cases}

In document restoration corrupted by spot or sinusoidal shading, parameters such as n=20n = 20 and b=0.5b = 0.5 consistently isolate dark characters from non-uniform backgrounds.

Region-Based Segmentation: Growing, Splitting, and Merging

Region Growing by Pixel Aggregation

Region growing groups pixels into larger spatial regions based on predefined criteria. Starting from a set of "seed" points, regions grow by iteratively appending adjacent pixels that satisfy a similarity predicate (e.g., intensity, texture, color, or shape).

Algorithm Based on 8-Connectivity

Let f(x,y)f(x, y) be the input image array, S(x,y)S(x, y) be a binary seed array (11 for seeds, 00 otherwise), and QQ be the similarity predicate:

  1. Find all connected components in S(x,y)S(x, y) and erode each component down to a single pixel; label each resulting seed pixel as 11, and all others as 00.

  2. Create a binary image fQ(x,y)f_Q(x, y) evaluating the predicate QQ for every pixel:

fQ(x,y)={1if Q(x,y) is satisfied0otherwisef_Q(x, y) = \begin{cases} 1 & \text{if } Q(x, y) \text{ is satisfied} \\ 0 & \text{otherwise} \end{cases}

  1. Form the segmented image gg by appending to each seed point in SS all 1-valued points in fQf_Q that are 8-connected to that seed point.

  2. Label each disjoint connected component in gg with a distinct region label.

A common similarity predicate uses an absolute intensity difference threshold TT:

Q={TRUEif ∣f(x,y)−f(seed)∣≤TFALSEotherwiseQ = \begin{cases} \text{TRUE} & \text{if } |f(x, y) - f(\text{seed})| \le T \\ \text{FALSE} & \text{otherwise} \end{cases}

Worked Numerical Example: 4-Connectivity vs. 8-Connectivity

Consider the following 7×77 \times 7 digital image array, where the initial seed point is the center pixel at coordinates (4,4)(4, 4) (value 6060), and the similarity predicate is ∣f(x,y)−f(4,4)∣≤5|f(x, y) - f(4, 4)| \le 5:

Row 1: [10, 10, 10, 10, 10, 10, 10]
Row 2: [10, 10, 10, 69, 70, 10, 10]
Row 3: [59, 10, 60, 64, 59, 56, 60]
Row 4: [10, 59, 10, 60, 70, 10, 62]
Row 5: [10, 60, 59, 65, 67, 10, 65]
Row 6: [10, 10, 10, 10, 10, 10, 10]
Row 7: [10, 10, 10, 10, 10, 10, 10]

The acceptable intensity range for region inclusion is [60−5, 60+5]=[55, 65][60 - 5,\, 60 + 5] = [55,\, 65].

  • Under 4-Connectivity:

    • From (4,4)(4, 4) (value 6060):

    • North neighbor (3,4)(3, 4) has value 64  ⟹  64 \implies accepted.

    • South neighbor (5,4)(5, 4) has value 65  ⟹  65 \implies accepted.

    • East neighbor (4,5)(4, 5) has value 70  ⟹  70 \implies rejected.

    • West neighbor (4,3)(4, 3) has value 10  ⟹  10 \implies rejected.

    • From (3,4)(3, 4) (6464):

    • North neighbor (2,4)(2, 4) has value 69  ⟹  69 \implies rejected.

    • East neighbor (3,5)(3, 5) has value 59  ⟹  59 \implies accepted.

    • West neighbor (3,3)(3, 3) has value 60  ⟹  60 \implies accepted.

    • From (3,5)(3, 5) (5959):

    • East neighbor (3,6)(3, 6) has value 56  ⟹  56 \implies accepted.

    • From (3,6)(3, 6) (5656):

    • East neighbor (3,7)(3, 7) has value 60  ⟹  60 \implies accepted.

    • From (5,4)(5, 4) (6565):

    • West neighbor (5,3)(5, 3) has value 59  ⟹  59 \implies accepted.

    • East neighbor (5,5)(5, 5) has value 67  ⟹  67 \implies rejected.

    • From (5,3)(5, 3) (5959):

    • West neighbor (5,2)(5, 2) has value 60  ⟹  60 \implies accepted.

    • Pixels at (3,1)(3, 1) (5959), (4,2)(4, 2) (5959), and (4,7)(4, 7) (6262) are isolated from 4-connected growth by surrounding values of 1010.

  • Under 8-Connectivity:

    • The pixel at (4,2)(4, 2) (5959) is diagonally 8-connected to (3,3)(3, 3) (6060) and (5,3)(5, 3) (5959), so it is included in the grown region.

    • Pixel (3,1)(3, 1) (5959) connects to (4,2)(4, 2) (5959).

    • Pixel (4,7)(4, 7) (6262) connects diagonally to (3,6)(3, 6) (5656) and (5,7)(5, 7) (6565).

    • Thus, 8-connectivity bridges diagonal paths across background barriers that halt 4-connected aggregation.

Region Splitting and Merging

When appropriate seed points are unavailable, an image can be segmented by recursively splitting it into quadrants and merging adjacent homogeneous blocks using a quadtree data structure.


Quadtree partitioning and tree graph representation
The Split-and-Merge Algorithm

Let RR denote the root image region. Define a homogeneity predicate QQ:

  1. Splitting: If Q(Ri)=FALSEQ(R_i) = \text{FALSE}, split region RiR_i into four disjoint quadrants.

  2. Merging: When no further splits can occur, merge any two adjacent regions RjR_j and RkR_k if they satisfy the joint predicate:

Q(Rj∪Rk)=TRUEQ(R_j \cup R_k) = \text{TRUE}

  1. Termination: Continue until no further split or merge operations are possible.

Statistical Predicate Example

In astronomical imaging (e.g., Hubble space telescope X-ray images of the Cygnus Loop supernova), regions are segmented based on local mean and standard deviation:

Q={TRUEif σ>a and 0<m<bFALSEotherwiseQ = \begin{cases} \text{TRUE} & \text{if } \sigma > a \text{ and } 0 < m < b \\ \text{FALSE} & \text{otherwise} \end{cases}

Limiting the minimum quadrant size (e.g., to 32×3232 \times 32, 16×1616 \times 16, or 8×88 \times 8 pixels) controls the spatial resolution and boundary precision of the final segmentation.

Morphological Watershed Segmentation

Morphological watershed segmentation visualizes a grayscale image as a 3D topographic surface, where pixel coordinates represent spatial location and intensity values represent altitude. The algorithm is typically applied to gradient magnitude images, where high values mark object edges and low values mark uniform interiors.

Topographic Surface Terminology


Topographic profile and flooding stages in watershed segmentation
  1. Regional Minima: Continuous spatial areas of uniform, minimal altitude.

  2. Catchment Basins (Watersheds): Geographic regions where a falling drop of water drains to a specific regional minimum.

  3. Watershed Lines (Divide Lines): Crests and ridges where raindrops are equally likely to flow into more than one catchment basin. These dividing ridges form the final closed boundary segments.

Flooding Simulation and Dam Construction

  1. Pierce a hole at each regional minimum across the topographic surface.

  2. Submerge the surface into a reservoir from below, allowing water to fill each catchment basin at a uniform rate.

  3. As water rises, catchment basins from adjacent minima will approach each other. When water from two distinct basins is about to merge, build a dam along the ridge line to prevent mixing.

  4. Dam construction is implemented using morphological dilation with a 3×33 \times 3 symmetric cross structuring element. Expanding the flooded components until they collide defines the coordinates where dam pixels must be placed.

  5. When the water level reaches the maximum elevation (L−1L - 1), the resulting network of dams forms the watershed lines.

The Over-Segmentation Problem and Marker Control


Over-segmentation resulting from raw gradient noise

Due to sensor noise and micro-texture in the image gradient, standard watershed algorithms identify hundreds of extraneous regional minima, causing severe over-segmentation. To prevent this, marker-controlled watershed segmentation limits catchment basins to predefined regions:

  1. Internal Markers: Connected components associated with target objects, generated via morphological opening/closing or adaptive thresholding.

  2. External Markers: Connected components representing the background, generated by computing watershed divide lines between internal markers.

  3. Minima Imposition: The gradient image is modified so that local minima occur only at marker locations, eliminating all extraneous minima.

  4. The watershed transform is then applied to the modified gradient surface, yielding clean, closed boundaries.

Motion-Based and Clustering-Based Segmentation

Motion Segmentation via Static Reference Differences


Reference image subtraction for motion segmentation

In video streams and image sequences, motion provides a strong cue for isolating foreground objects from static backgrounds. A static reference background image R(x,y)R(x, y) is maintained across frames.

When a moving vehicle passes through a frame at time t1t_1, taking the absolute frame difference isolates the moving target:

d(x,y)=∣f(x,y,t1)−R(x,y)∣d(x, y) = |f(x, y, t_1) - R(x, y)|

Areas occluded by the moving target can be restored in the reference background by copying pixels from a non-occluded subsequent frame at time t2t_2.

K-Means Clustering

K-means is an iterative, unsupervised clustering algorithm that partitions NN data points into KK distinct clusters in feature space (e.g., intensity, color coordinates RGB\text{RGB}, or spatial texture descriptors).

The K-Means Algorithm
  1. Initialization: Choose KK cluster centers (centroids) m1,m2,…,mK\mathbf{m}_1, \mathbf{m}_2, \dots, \mathbf{m}_K randomly or using initial seed heuristics.

  2. Assignment: Assign each data point xp\mathbf{x}_p to the cluster CjC_j whose centroid has the minimum Euclidean distance:

xp∈Cjif∥xp−mj∥=min⁡1≤i≤K∥xp−mi∥\mathbf{x}_p \in C_j \quad \text{if} \quad \|\mathbf{x}_p - \mathbf{m}_j\| = \min_{1 \le i \le K} \|\mathbf{x}_p - \mathbf{m}_i\|

  1. Centroid Update: Recalculate each centroid as the mean of all data points assigned to that cluster:

mj=1∣Cj∣∑x∈Cjx\mathbf{m}_j = \frac{1}{|C_j|} \sum_{\mathbf{x} \in C_j} \mathbf{x}

  1. Convergence Check: Repeat Steps 2 and 3 until the cluster assignments or centroid positions do not change between iterations:

∑j=1K∥mj(t+1)−mj(t)∥<ϵ\sum_{j=1}^K \|\mathbf{m}_j^{(t+1)} - \mathbf{m}_j^{(t)}\| < \epsilon

In color segmentation, K-means clusters pixels based on their joint color feature vectors (e.g., RGB\text{RGB} or L∗a∗b∗\text{L}^*\text{a}^*\text{b}^*), grouping pixels with similar color properties regardless of spatial connectivity.

Summary Comparison of Segmentation Techniques

Segmentation Technique

Operating Domain

Primary Advantages

Common Failure Modes / Limitations

First-Order Edge Detection (Sobel/Prewitt)

Local spatial derivatives

Simple implementation; low computational cost; directional sensitivity

Wide/thick edges; sensitive to noise; requires heuristic thresholding

Marr-Hildreth (LoG)

Multi-scale Gaussian second derivatives

Clean zero crossings; controllable detail scale using σ\sigma; isotropic

Computationally intensive; produces closed-loop "spaghetti" edges

Canny Edge Detector

Multi-stage optimal directional gradient

Single-pixel edge width; superior noise handling; adaptive hysteresis linking

Sensitive to fine-tuning of parameters (σ,TH,TL\sigma, T_H, T_L)

Hough Transform

Global parameter space

Links disconnected segments; resilient to partial occlusions and high noise

Limited to parametric shapes (lines, circles); high memory footprint

Otsu’s Global Thresholding

Histogram-based variance optimization

Non-parametric; fully automatic; optimal between-class separability

Fails on unimodal distributions, small objects, and non-uniform lighting

Adaptive / Local Thresholding

Moving averages / local window statistics

Robust to severe illumination ramps and variable shading

Requires empirical tuning of window size nn and scaling multiplier bb

Region Growing

Local similarity / pixel aggregation

Guarantees closed, connected regions; effective on noisy images

Sensitive to seed selection; vulnerable to regional leakage

Region Splitting & Merging

Hierarchical quadtree partitioning

Does not require initial seeds; flexible statistical predicates

Blocky boundaries along split quadtree grid lines

Morphological Watersheds

Topographic gradient surface flooding

Produces closed, thin boundaries; captures complex organic structures

Severe over-segmentation unless controlled by markers