**Introduction**

In binary valued digital imaging, a pixel can either have a value of
1 -when it's part of the pattern- , or 0 -when it's part of the background-
i.e. there is no grayscale level. (We will assume that pixels with value
1 are black while zero valued pixels are white).

In order to identify ** objects** in a digital pattern, we
need to locate groups of black pixels that are "connected" to each other.
In other words, the

In general, a ** connected component **is a set of black pixels,

a) all pixels in the sequence are in the set

b) every 2 pixels that are

As a result, an important question arises: *When can we say that
2 pixels are "neighbors"?*

Since we are using square pixels, the answer to the previous question
is not trivial. The reason for that is: in a
square tessellation,
pixels either share an edge, a vertex, or neither. There are 8 pixels sharing
an edge or a vertex with any given pixel; these pixels make up the Moore
neighborhood of that pixel. Should we consider pixels having only a
common vertex as "neighbors" ? Or should 2 pixels have a common edge in
order for them to be considered "neighbors"?

This gives rise to 2 types of connectedness, namely: 4-connectivity
and 8-connectivity.

**4-Connectivity**

When can we say that a given set of black pixels is *4-connected
?*

First, we have to define the concept of a ** 4-neighbor **(also
known as a

**Definition of a 4-neighbor**:

A pixel, **Q,** is a ** 4-neighbor** of a given pixel,

The 4-neighbors of pixel

**Definition of a 4-connected component** :

A set of black pixels, **P**, is a ** 4-connected component **if
for every pair of pixels

a) all pixels in the sequence are in the set

b) every 2 pixels that are

**Examples of 4-connected patterns :**

The following diagrams are examples of patterns that are 4-connected:

**8-Connectivity**

When can we say that a given set of black pixels is *8-connected
?*

First, we have to define the concept of an ** 8-neighbor **(also
known as an

**Definition of an 8-neighbor**:

A pixel, **Q,** is an ** 8-neighbor** (or simply a

The 8-neighbors of a given pixel

**Definition of an 8-connected component**:

A set of black pixels, **P**, is an ** 8-connected component**
(or simply a

a) all pixels in the sequence are in the set

b) every 2 pixels that are

**NOTE**

All 4-connected patterns are 8-connected i.e. 4-connected patterns
are a subset of the set of 8-connected patterns.

On the other hand, an 8-connected pattern may not** **be 4-connected.

**Example of 8-connected pattern :**

The diagram below is an example of a pattern that is 8-connected but
not 4-connected:

**Example of a pattern that's not 8-connected:**

The diagram below is an example of a pattern that is not 8-connected
i.e. is made up of more than one connected component (there are 3 connected
components in the diagram below):