StrataQuest Home › StrataQuest Glossary › Connected Component Labeling
BOM Operation

Connected Component Labeling

Assigning unique IDs to contiguous foreground regions

View
Definition
Labeling scans a binary image, finds each group of touching foreground pixels, and gives that group a unique integer ID. The output is a coded image, and every per-object tracking, measurement and classification in StrataQuest starts from one. Much rides on the word “touching”: two pixels that meet only at a corner make one object or two, depending on the connectivity you choose.
The textbook two-pass method
Provisional labels first, then merge the aliases
Diagonals change the count
4-connected or 8-connected determines what touches
Output: a coded image
An anonymous mask becomes addressable objects
A morphological alternative
Grow from a seed, inside the foreground

How It Works

The textbook way to label takes two passes over a binary image, each one row by row. The StrataQuest reference does not say which method its Label operation uses.

  1. First pass. Scan rows top to bottom, left to right. At each foreground pixel, look at the neighbors already visited: left and above, plus upper-left and upper-right under 8-connectivity. If none of them is foreground, assign a new label; if one carries a label, copy it; if several carry different labels, assign one of them and record that the labels are equivalent.
  2. Second pass. Resolve the recorded equivalences with a union-find structure, replacing each temporary label with its canonical one. If later operations leave gaps in the numbering, Re-Label (missing) corrects the label list.

A morphological route reaches the same answer. Dilate from a seed pixel inside one component, constrained to the original foreground, until the growth stops changing; what it covers is the whole component. Clear that component from the working image, increment the label, and repeat until every component has a number.

Simplified

Thresholding leaves you a black-and-white image. Labeling works out which white pixels belong together. In the usual method, touching white pixels get the same number as the scan goes, and when two groups numbered separately turn out to connect, their numbers merge. Every separate object ends up with its own ID.

Image Processing Foundation

Three details determine what labeling produces.

Connectivity

4-connectivity tends to produce more, smaller objects. 8-connectivity tends to merge objects that barely touch at a corner. The choice is more than a matter of preference, because it changes the topology of the objects you detect.

Union-Find Data Structure

In the two-pass method, the second pass usually resolves equivalences with a union-find (disjoint-set) structure, often with path compression and union by rank. That keeps the pass near-linear in time, so labeling stays efficient with thousands of objects in the image.

Flood-Fill Variant

The morphological route above is a flood-fill: constrained dilation from a seed point, x_k = (x_{k-1} dilated by B) AND A, where A is the original image. The structuring element B must not be larger than the boundary thickness, or the fill leaks through thin walls.

Simplified

Labeling is how the computer gets from 'these pixels are bright' to 'this is object #1, this is object #2.' Without it, you can see structures in an image but can't count them, measure them one at a time, or follow them through the analysis. It is the bridge between pixel data and object data.

Parameters & Settings

ParameterTypeDescription
ImageBinary imageA thresholded image whose foreground (non-zero) pixels are the objects to label.
Connectivity4-conn (default) or 8-connWhich neighbors count as touching. 4: orthogonal neighbors only, giving more separate objects. 8: diagonals too, so pixels touching at a corner join one object.
Simplified

The main setting is Connectivity, and StrataQuest starts it at 4-connected. Keep 4-connected if objects that touch only diagonally should count separately, and switch to 8-connected if a diagonal touch makes them one object.

Connected Terms

Share This Term
Term Connections