Department of E.C.
RELATIONSHIP BETWEEN PIXELS:
We consider several important relationships between pixels in a digital image.
NEIGHBORS OF A PIXEL
• A pixel p at coordinates (x, y) has four horizontal and vertical neighbors whose coordinates
are given by:
(x, y-1), (x, y+1), (x-1, y), (x+1, y),
P(x-1, y)
P(x,y-1) P(x, y) P(x,y+1)
P(x+1, y)
This set of pixels, called the 4-neighbors or p, is denoted by N4(p). Each pixel is one unit distance
from (x, y) and some of the neighbors of p lie outside the digital image if (x, y) is on the border of the image.
The four diagonal neighbors of p have coordinates and are denoted by ND (p).
(x-1, y-1), (x-1, y+1), (x+1, y-1), (x+1, y+1)
P(x-1,y-1) P(x-1, y+1)
P(x, y)
P(x+1, y-1) P(x+1,y+1)
These points, together with the 4-neighbors, are called the 8-neighbors of p, denoted by N8 (p).
P(x-1,y-1) P(x-1,y) P(x-1, y+1)
P(x, y-1) P(x, y) P(x, y+1)
P(x+1, y-1) P(x+1,y) P(x+1,y+1)
As before, some of the points in ND (p) and N8 (p) fall outside the image if (x, y) is on the border of the
image.
ADJACENCY AND CONNECTIVITY
Connectivity between pixels is a fundamental concept that simplifies the definition of numerous
digital image concepts, such as regions and boundaries. To establish if two pixels are connected, it must be
determined if they are neighbors and if their gray levels satisfy a specified criterion of similarity (say, if their
gray levels are equal). For instance, in a binary image with values 0 and 1, two pixels may be 4-neighbors,
but they are said to be connected only if they have the same value.
Let V be the set of gray –level values used to define adjacency, in a binary image, V={1}. In a gray-
scale image, the idea is the same, but V typically contains more elements, for example,
V = {180, 181, 182, …, 200}. If the possible intensity values 0 – 255, V set can be any subset of these 256
values if we are reference to adjacency of pixel with value.
Three types of adjacency
• 4- adjacency – two pixel p and q with value from V are 4 –adjacency if q is in the set N4(p)
• 8- adjacency – two pixel p and q with value from V are 8 –adjacency if q is in the set N8(p)
• m(mixed)-adjacency –two pixel p and q with value from V are m – adjacency if
(i) q is in N4(p) or (ii) q is in ND(p) and the set N4(p) ∩ N4(q) has no pixel whose values are
from V.
Mixed adjacency is a modification of 8-adjacency. It is introduced to eliminate the ambiguities that often
arise when 8-adjacency is used.
• For example:
Fig:1.8 (a) Arrangement of pixels; (b) pixels that are 8-adjacent (shown dashed) to the center pixel; (c) m-
adjacency.
Digital Image Processing
Department of E.C.E
Types of Adjacency:
• In this example, we can note that to connect between two pixels (finding a path between two pixels):
– In 8-adjacency way, you can find multiple paths between two pixels
– While, in m-adjacency, you can find only one path between two pixels
• So, m-adjacency has eliminated the multiple path connection that has been generated by the 8-
adjacency.
• Two subsets S1 and S2 are adjacent, if some pixel in S1 is adjacent to some pixel in S2. Adjacent
means, either 4-, 8- or m-adjacency.
• Two image subsets Si and Sj are adjacent if fp € Si and fq € Sj such that p and q adjacent.
• Adjacency for 2 image regions like this that if there are 2 image subsets - Si and Sj, we say that Si and
Sj will be adjacent if there exists a point p in image region Si and a point q in image region Sj such
that p and q are adjacent.
• So, consider image region Si and image region Sj; then if some point p in image Si and some other
point q in the image Sj so that this p and q, they are adjacent. So, if p and q are adjacent, then this
image region Si is adjacent to image region Sj. That means Si and Sj; they must appear one after the
other, one adjacent to the other. So, this is the adjacency relation.
A Digital Path:
• A digital path (or curve) from pixel p with coordinate (x, y) to pixel q with coordinate (s, t) is a sequence
of distinct pixels with coordinates
(x0, y0), (x1, y1), …, (xn, yn)
where (x0, y0)=(x, y) and (xn, yn) = (s, t) and pixels (xi, yi) and (xi-1, yi-1) are adjacent for
1≤i≤n
• n is the length of the path
• If (x0, y0) = (xn, yn), the path is closed.
We can specify 4-, 8- or m-paths depending on the type of adjacency specified.
• Return to the previous example:
Fig:1.8 (a) Arrangement of pixels; (b) pixels that are 8-adjacent(shown dashed) to the center pixel; (c) m-
adjacency.
The 8-path from (1,3) to (3,3): i) (1,3), (1,2), (2,2), (3,3) ii) (1,3), (2,2), (3,3)
The m-path from (1,3) to (3,3): --(1,3), (1,2), (2,2), (3,3)
In figure (b) the paths between the top right and bottom right pixels are 8-paths. And the path between the
same 2 pixels in figure (c) is m-path
Connectivity:
• Let S represent a subset of pixels in an image, two pixels p and q are said to be connected in S if there
exists a path between them consisting entirely of pixels in S.
• For any pixel p in S, the set of pixels that are connected to it in S is called a connected component of
S. If it only has one connected component, then set S is called a connected set.
Region and Boundary:
REGION: Let R be a subset of pixels in an image, we call R a region of the image if R is a connected set.
BOUNDARY: The boundary (also called border or contour) of a region R is the set of pixels in the region
that have one or more neighbors that are not in R.
If R happens to be an entire image, then its boundary is defined as the set of pixels in the first and last
rows and columns in the image. This extra definition is required because an image has no neighbors beyond
its borders. Normally, when we refer to a region, we are referring to subset of an image, and any pixels in the
boundary of the region that happen to coincide with the border of the image are included implicitly as part of
the region boundary.
Digital Image Processing
Department of E.C.E
Example: Consider the two image subsets, S1 and S2, shown in the following fig. For V={1}, determine
whether these two subsets are (a) 4-adjacent, (b) 8–adjacent, or (c) m-adjacent
Ans: Let p and q be as shown in fig. Then,
(a) S1 and S2 are not 4-connected because q is not in the set N4(p);
(b) S1 and S2 are 8-connected because q is in the set N8(p);
(c) S1 and S2 are m-connected because (i) q is in ND(p), and ii) the set N4(p) ∩ N4(q) is empty.
Distances Measures:
For pixel p, q and z with coordinate (x, y), (s, t) and (v, w) respectively D is a distance function or metric if
(a) D(p, q) ≥ 0 (D(p, q) =0 iff p=q),
(b) D(p, q) = D(q, p), and
(c) D(p, z) ≤ D(p, q) +D(q, z).
• The Euclidean Distance between p and q is defined as:
De (p, q) = [(x – s)2 + (y - t)2]1/2
Pixels having a distance less than or equal to some value r from (x, y) are the points contained in a disk of
radius ‘r’ centered at (x, y)
• The D4 distance (also called city-block distance) between p and q is defined as:
D4 (p, q) = | x – s | + | y – t |
Pixels having a D4 distance from (x, y), less than or equal to some value r form a Diamond centered at (x, y)
Example:
The pixels with distance D4 ≤ 2 from (x, y) form the following contours of constant distance.
The pixels with D4 = 1 are the 4-neighbors of (x, y)
• The D8 distance (also called chessboard distance) between p and q is defined as:
D8 (p, q) = max (| x – s |,| y – t |)
Pixels having a D8 distance from (x, y), less than or equal to some value r form a square Centered at (x, y).
Digital Image Processing
Department of E.C.E
Example:
D8 distance ≤ 2 from (x, y) form the following contours of constant distance.
• Dm distance:
It is defined as the shortest m-path between the points.
In this case, the distance between two pixels will depend on the values of the pixels along the path, as well as
the values of their neighbors.
• Example:
Consider the following arrangement of pixels and assume that p, p2, and p4 have value 1 and that p1 and p3 can
have can have a value of 0 or 1. Suppose that we consider the adjacency of pixels values 1 (i.e. V = {1})
Now, to compute the Dm between points p and p4
Here we have 4 cases:
Case1: If p1 =0 and p3 = 0
The length of the shortest m-path (the Dm distance) is 2 (p, p2, p4)
Case2: If p1 =1 and p3 = 0
now, p2 and p will no longer be adjacent (see m-adjacency definition)
then, the length of the shortest path will be 3 (p, p1, p2, p4)
Case3: If p1 =0 and p3 = 1
The same applies here, and the shortest –m-path will be 3 (p, p2, p3, p4)
Case4: If p1 =1 and p3 = 1
The length of the shortest m-path will be 4 (p, p1, p2, p3, p4)
Digital Image Processing