fourconnected
Fourconnected, or 4-connectivity, is a neighborhood relation on a two-dimensional square lattice used in digital geometry and image processing. In a grid, two cells are 4-neighbors if their coordinates differ by exactly one unit in one axis and are equal in the other; the 4-neighborhood of a cell consists of its north, south, east, and west adjacent cells. A set of cells is 4-connected if every pair of cells can be joined by a path through 4-neighbors; a 4-connected component is a maximal 4-connected subset.
Compared with 8-connectivity, which also includes diagonal adjacencies, 4-connectivity can yield different component boundaries. Two pixels
Common implementations use a cross-shaped neighbor stencil. Algorithms for extracting 4-connected components include two-pass connected-component labeling,
In higher dimensions, the 4-connected notion generalizes to 6-connected in 3D spaces (face-adjacent cells). The term