Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Image Processing

Chapter(3)
Part 1:Relationships between pixels

Prepared by: Hanan Hardan

Hanan Hardan 1
Ch3: Some basic Relationships between pixels

Neighbors of a pixel

some of the points in ND (p) and N8 (p) fall outside the


image if (x,y) is on the border of the image.
Hanan Hardan 2
Connectivity
 Two pixels are connected if:
– They are neighbors (i.e. adjacent in some
sense -- e.g. N4(p), N8(p), …)
– Their gray levels satisfy a specified criterion
of similarity (e.g. equality, …)
• V is the set of gray-level values used to
define adjacency (e.g. V={1} for adjacency
of pixels of value 1)
‫هذا يعتمد على مقدار القرب الذي تاخذه بعين االعتبار‬
Hanan Hardan 3
Adjacency and Connectivity
 Let V: a set of intensity values used to
define adjacency and connectivity.
 In a binary image, V = {1}, if we are
referring to adjacency of pixels with value
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
Hanan Hardan 4
Ch3: Some basic Relationships between pixels

Adjacency
V: set of gray level values (L), (V is a subset of L.)

3 types of adjacency

 4- adjacency: 2 pixels p and q with values from V are 4- adjacent if q is in the


set N4(p)
 8- adjacency: 2 pixels p and q with values from V are 8- adjacent if q is in the
set N8(p)
 m- adjacency: 2 pixels p and q with values from V are m-adjacent if
1. q is in N4(p), or
2. q is in ND(p) and the set N4(p) ∩ N4(q) has no pixels whose
values are from V

Hanan Hardan 5
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.

Hanan Hardan 6
Types of 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.

Hanan Hardan 7
Ch3: Some basic Relationships between pixels

A digital path
 A digital path from pixel p with coordinates
(x,y) to pixel q with coordinates (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.
Hanan Hardan 8
A Digital Path
 Return to the previous example:

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
Hanan Hardan 9
Ch3: Some basic Relationships between pixels

Connectivity
 S: 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.

Hanan Hardan 10
Ch3: Some basic Relationships between pixels

Regions and boundaries


 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.
000000
010010
011010
010110
000000

 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.
Hanan Hardan 11
Region and Boundary
 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.

Hanan Hardan 12
Foreground and background
Suppose that the image contains K disjoint
regions Rk none of which touches the
image border .
Ru : the union of all regions .
(Ru)c : is the complement .

so Ru is called foreground , and (Ru)c : is


the background .

Hanan Hardan 13
Ch3: Some basic Relationships between pixels

Distance measures
If we have 3 pixels: p,q,z respectively
p with (x,y)
q with (s,t)
z with (v,w)
Then:
A. D (p,q) ≥ 0 ,D(p,q) = 0 iff p = q
B. D(p,q) = D(q,p)
C. D(p,z) ≤ D(p,q) + D(q,z)

Hanan Hardan 14
Ch3: Some basic Relationships between pixels

Distance measures
 Euclidean distance between p and q:
De(p,q) = [(x-s)2 + (y-t)2]1/2

 D4 distance (also called city-block


distance):
D4(p,q) = |x-s| + |y-t|

 D8 distance (also called chessboard


distance) :
D8(p,q) = max (|x-s| , |y-t|)
Hanan Hardan 15
Distance measures

Hanan Hardan 16
Example:

Compute the distance between the two pixels


using the three distances : 1 2 3
q:(1,1)
1 q
P: (2,2)
2 p
Euclidian distance : ((1-2)2+(1-2)2)1/2 = sqrt(2).
3
D4(City Block distance): |1-2| +|1-2| =2
D8(chessboard distance ) : max(|1-2|,|1-2|)= 1
(because it is one of the 8-neighbors )

Hanan Hardan 17
Distance measures

Example :
Use the city block distance to prove 4-
neighbors ? 1 2 3
1
d
Pixel A : | 2-2| + |1-2| = 1 2
a p c
Pixel B: | 3-2|+|2-2|= 1
3 b
Pixel C: |2-2|+|2-3| =1
Pixel D: |1-2| + |2-2| = 1

Now as a homework try the chessboard


distance to proof the 8- neighbors!!!!
Hanan Hardan 18
Distance Measures
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)

Hanan Hardan 19
Distance Measures
Example:
D8 distance ≤ 2 from (x,y) form the
following contours of constant distance.

D8 = 1 are the 8-neighbors of (x,y)


Hanan Hardan 20
Distance Measures
 Dm distance:
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.

Hanan Hardan 21
Distance Measures
 Example:
Consider the following arrangement of
pixels and assume that p, p2, and p4 have
value 1 and that p1 and p3 can have a
value of 0 or 1
Suppose that we consider
the adjacency of pixels
values 1 (i.e. V = {1})

Hanan Hardan 22
Distance Measures
 Cont. Example:
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)

Hanan Hardan 23
Distance Measures
 Cont. Example:
Case2: If p1 =1 and p3 = 0

then, the length of the shortest


path will be 3 (p, p1, p2, p4)

Hanan Hardan 24
Distance Measures
 Cont. Example:
Case3: If p1 =0 and p3 = 1
The same applies here, and the shortest –
m-path will be 3 (p, p2, p3, p4)

Hanan Hardan 25
Distance Measures
 Cont. Example:
Case4: If p1 =1 and p3 = 1
The length of the shortest m-path will be 4
(p, p1 , p2, p3, p4)

Hanan Hardan 26

You might also like