Skip to content
CoreSource checked

Connected Component Labeling

Assigns labels to contiguous foreground regions in a binary or segmented image.

Quick Facts

Compact metadata for implementation and discovery.

Category
Image Processing
Difficulty
Intermediate
Family
Image Segmentation
Tier
Core
Status
Verified
Review
Source Checked
Sources
2
Formulas
0
Relationships
3
Code example
Ready
Visualization
Ready

Overview

Connected Component Labeling scans pixels and groups neighboring foreground pixels into distinct labeled components.

Core Concepts

foreground maskpixel connectivitylabel equivalencecomponent id

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(pixels)

Average

O(pixels)

Worst

O(pixels)

Space

O(pixels)

When to Use

  • Use when foreground regions need to be counted, measured, or filtered.
  • Use when object counting is a central requirement.

When Not to Use

  • Avoid when objects are not separable in the input mask.
  • Avoid when lighting, noise, or scale changes dominate the image signal.

What It Does

  • Scans foreground pixels
  • Merges neighboring labels
  • Outputs one label per connected region

Use Cases

  • Object counting
  • Segmentation cleanup
  • Blob measurement

Inputs

  • Binary or labeled image
  • Connectivity rule

Outputs

  • Component label image
  • Component statistics

Pseudocode

  1. 1.Scan pixels in row order
  2. 2.Assign a new label or reuse neighboring labels
  3. 3.Record equivalent labels
  4. 4.Resolve equivalences
  5. 5.Replace provisional labels with final component labels

Canonical Example

Input
binary image has two separate white blobs
Output
labels = blob1 and blob2
Explanation
Each connected foreground region receives its own id.

Implementation Notes

  • Use Union-Find to manage equivalent provisional labels in a two-pass implementation.
  • Start with grayscale or single-channel tests before applying the method to full images.
  • Keep a tiny example with expected output beside the implementation.

Common Pitfalls

  • Changing connectivity changes whether diagonal pixels belong to the same region.
  • Padding, threshold, and color-space choices can change the result dramatically.
  • Not defining boundary, empty, or degenerate inputs before implementation.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show separate foreground blobs receiving different colors or numeric labels.

Connected Component Labeling mechanism walkthrough step 1 of 5
Step 1 of 5: Scan pixels in row order
image-kernel

Notes

Four-connectivity and eight-connectivity can produce different components.

Sources (2)

What each reference supports for this entry.

Digital Image Processing

Book

Image-processing textbook support for connected-component labeling in binary images.

Sequential Operations in Digital Picture Processing

Paper

Reference for sequential connected-component labeling and equivalence handling.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Connected-component labeling can merge provisional labels efficiently with union-find.

Related Algorithms

Tags

Image ProcessingSegmentationGraph Connectivity