# Pixel connectivity

In image processing and image recognition, pixel connectivity is the way in which pixels in 2-dimensional (or voxels in 3-dimensional) images relate to their neighbors.

## Types of connectivity

### 2-dimensional

Example of neighborhood of pixels - association of eight and four pixels

#### 4-connected

4-connected pixels are neighbors to every pixel that touches one of their edges. These pixels are connected horizontally and vertically. In terms of pixel coordinates, every pixel that has the coordinates

${\displaystyle \textstyle (x\pm 1,y)}$ or ${\displaystyle \textstyle (x,y\pm 1)}$

is connected to the pixel at ${\displaystyle \textstyle (x,y)}$.

#### 6-connected

6-connected pixels are neighbors to every pixel that touches one of their corners (which includes pixels that touch one of their edges) in a hexagonal grid or stretcher bond rectangular grid.

There are several ways to map hexagonal tiles to integer pixel coordinates. With one method, in addition to the 4-connected pixels, the two pixels at coordinates ${\displaystyle \textstyle (x+1,y+1)}$ and ${\displaystyle \textstyle (x-1,y-1)}$ are connected to the pixel at ${\displaystyle \textstyle (x,y)}$.

#### 8-connected

8-connected pixels are neighbors to every pixel that touches one of their edges or corners. These pixels are connected horizontally, vertically, and diagonally. In addition to 4-connected pixels, each pixel with coordinates ${\displaystyle \textstyle (x\pm 1,y\pm 1)}$ is connected to the pixel at ${\displaystyle \textstyle (x,y)}$.

### 3-dimensional

#### 6-connected

6-connected pixels are neighbors to every pixel that touches one of their faces. These pixels are connected along one of the primary axes. Each pixel with coordinates ${\displaystyle \textstyle (x\pm 1,y,z)}$, ${\displaystyle \textstyle (x,y\pm 1,z)}$, or ${\displaystyle \textstyle (x,y,z\pm 1)}$ is connected to the pixel at ${\displaystyle \textstyle (x,y,z)}$.

#### 18-connected

18-connected pixels are neighbors to every pixel that touches one of their faces or edges. These pixels are connected along either one or two of the primary axes. In addition to 6-connected pixels, each pixel with coordinates ${\displaystyle \textstyle (x\pm 1,y\pm 1,z)}$, ${\displaystyle \textstyle (x\pm 1,y\mp 1,z)}$, ${\displaystyle \textstyle (x\pm 1,y,z\pm 1)}$, ${\displaystyle \textstyle (x\pm 1,y,z\mp 1)}$, ${\displaystyle \textstyle (x,y\pm 1,z\pm 1)}$, or ${\displaystyle \textstyle (x,y\pm 1,z\mp 1)}$ is connected to the pixel at ${\displaystyle \textstyle (x,y,z)}$.

#### 26-connected

26-connected pixels are neighbors to every pixel that touches one of their faces, edges, or corners. These pixels are connected along either one, two, or all three of the primary axes. In addition to 18-connected pixels, each pixel with coordinates ${\displaystyle \textstyle (x\pm 1,y\pm 1,z\pm 1)}$, ${\displaystyle \textstyle (x\pm 1,y\pm 1,z\mp 1)}$, ${\displaystyle \textstyle (x\pm 1,y\mp 1,z\pm 1)}$, or ${\displaystyle \textstyle (x\mp 1,y\pm 1,z\pm 1)}$ is connected to the pixel at ${\displaystyle \textstyle (x,y,z)}$.