Image Processing Toolbox | ![]() ![]() |
4- and 8-Connected Neighborhoods
For many operations, distinguishing objects depends on the convention used to decide whether pixels are connected. There are two different conventions typically used: 4-connected or 8-connected neighborhoods.
In an 8-connected neighborhood, all of the pixels that touch the pixel of interest are considered, including those on the diagonals. This means that if two adjoining pixels are on
, they are part of the same object, regardless of whether they are connected along the horizontal, vertical, or diagonal direction.
Figure 9-4: An 8-Connected Neighborhood
In a 4-connected neighborhood, the pixels along the diagonals are not considered. This means that a pair of adjoining pixels are part of the same object only if they are both on
and are connected along the horizontal or vertical direction.
Figure 9-5: A 4-Connected Neighborhood
The type of neighborhood you choose affects the number of objects found in an image and the boundaries of those objects. Therefore, the results of the object-based operations often differ for the two types of neighborhoods.
For example, this matrix represents a binary image that has one 8-connected object or two 4-connected objects.
0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0
![]() | Object-Based Operations | Perimeter Determination | ![]() |