Connected Components and Object Measurements
Once you have a binary mask, how do you count separate objects? Connected-component labeling groups foreground pixels according to a neighborhood rule.
Connected Components and Object Measurements explained visually
Once you have a binary mask, how do you count separate objects? Connected-component labeling groups foreground pixels according to a neighborhood rule. English captions are optional and start off. The complete transcript follows the written lesson.
What you will learn
Once you have a binary mask, how do you count separate objects? Connected-component labeling groups foreground pixels according to a neighborhood rule.
Group neighboring pixels
The cleaned mask contains several screws. To count them, we group connected foreground pixels and assign each group its own label. But 'connected' requires a rule. With four-neighbor connectivity, only shared sides join. With eight-neighbor connectivity, diagonal touches join too.
Choose connectivity
Draw two pixels that meet at one corner. Four-neighbor labeling counts two groups; eight-neighbor labeling counts one. On the real mask, this choice can turn touching objects into one component even though the pixel values haven't changed. Check a few ambiguous contacts against the original image.
Measure in the right units
For each region, we can count foreground pixels for area, average their coordinates for a centroid, and enclose them in an axis-aligned bounding box. These are measurements of the mask, not automatically physical sizes. If a region covers fifty pixels and calibration gives zero point two millimeter per pixel in each direction, its area is fifty times zero point zero four, or two square millimeters, under that planar scale.
A worked example
Keep the connectivity and calibration beside the result. Next, we'll look at repeated image patterns in the frequency domain.
Worked example
A rectangular component covering ten columns and five rows contains 50 pixels if every location is foreground. If an appropriate planar calibration gives 0.2 millimeters per pixel in both directions, the area is 50 times 0.04, or two square millimeters.
Quick check: test your understanding
Try it yourself: Two pixels touch only at a corner. How many components do four-connectivity and eight-connectivity produce?
Check the reasoning
Four-connectivity produces two components; eight-connectivity produces one.
Does a component ID guarantee that the region is one real object?
No. Segmentation can merge several objects or split one object into multiple components.
How would you solve the practice case?
Four-connectivity produces two components; eight-connectivity produces one.
What does the worked example show?
A rectangular component covering ten columns and five rows contains 50 pixels if every location is foreground. If an appropriate planar calibration gives 0.2 millimeters per pixel in both directions, the area is 50 times 0.04, or two square millimeters.
Further reading
Digital Image Processing, 4th edition — Rafael C. Gonzalez and Richard E. Woods.
Original ToolsInVision teaching examples. Editorial approach · Suggest a correction
Accessible referenceLesson 12 transcript174 words · Video transcript · Matches the published narration and captionsOpen transcript
The cleaned mask contains several screws. To count them, we group connected foreground pixels and assign each group its own label. But 'connected' requires a rule. With four-neighbor connectivity, only shared sides join. With eight-neighbor connectivity, diagonal touches join too.
Draw two pixels that meet at one corner. Four-neighbor labeling counts two groups; eight-neighbor labeling counts one. On the real mask, this choice can turn touching objects into one component even though the pixel values haven't changed. Check a few ambiguous contacts against the original image.
For each region, we can count foreground pixels for area, average their coordinates for a centroid, and enclose them in an axis-aligned bounding box. These are measurements of the mask, not automatically physical sizes. If a region covers fifty pixels and calibration gives zero point two millimeter per pixel in each direction, its area is fifty times zero point zero four, or two square millimeters, under that planar scale.
Keep the connectivity and calibration beside the result. Next, we'll look at repeated image patterns in the frequency domain.