A neighborhood tells us which pixels are nearby. Connectivity goes one step further: it tells us whether foreground pixels can form a path to one another and therefore belong to the same connected object.
1. From Neighborhood to Connectivity
A neighborhood defines which positions are nearby. Connectivity uses those local relationships to determine whether foreground pixels can reach one another.
2. Binary Foreground and Background
Connectivity is easiest to introduce using a binary image.
3. 4-Connectivity
Under 4-connectivity, a pixel can be adjacent to its immediate horizontal and vertical neighbors.
If \(q\) is one of these four foreground neighbors, we can write
4. 8-Connectivity
Under 8-connectivity, the four diagonal neighbors are included as well.
5. Same Image, Different Connectivity
The foreground pixels can remain exactly the same while the number of connected components changes.
4-Connectivity
8-Connectivity
6. Connected Paths
Two pixels do not have to be immediate neighbors to be connected. They can be joined through a sequence of adjacent foreground pixels.
where consecutive pixels satisfy
means that a valid foreground path exists from \(p\) to \(q\).
7. Connected Components
A connected component is a maximal group of foreground pixels connected under the selected adjacency rule.
8. Connected-Component Labeling
Connected-component labeling gives each connected foreground component a unique integer identifier.
For \(K\) components,
9. Why Does Connectivity Matter?
10. Boundary Pixels
A foreground pixel is a boundary pixel if its selected neighborhood contains at least one background position.
11. Interactive Example
The visualizer below lets you edit a binary image and directly compare 4-connectivity with 8-connectivity.
Explore Connectivity
Edit the binary image, switch to Select Component, and click a foreground pixel.
Every foreground pixel connected to that seed is highlighted.
Change between 4- and 8-connectivity to see how the component changes.
Label Components
Run connected-component labeling on the same binary image.
Use Step to reveal one pixel at a time or Auto to watch the labels appear.
Each connected component receives its own integer identifier.
Summary
| Concept | Meaning |
|---|---|
| \(N_4(p)\) | Immediate horizontal and vertical neighbors. |
| \(N_8(p)\) | Immediate horizontal, vertical, and diagonal neighbors. |
| \(p\sim_4q\) | \(p\) and \(q\) are 4-adjacent. |
| \(p\sim_8q\) | \(p\) and \(q\) are 8-adjacent. |
| Path | A sequence of foreground pixels whose consecutive members are adjacent. |
| Connected | A valid foreground path exists between the pixels. |
| Connected Component | A maximal connected group of foreground pixels. |
| Connected-Component Labeling | Assign a unique integer identifier to each connected foreground component. |
| Boundary Pixel | A foreground pixel whose selected neighborhood contains at least one background position. |
Be First to Comment