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

Basic Relationship Between Pixels

by
Dr.R.Hemalatha, Associate Professor, ECE
SSN College of Engineering

UEC1722 Digital Image and Video


1
Processing
Session Objectives

• To understand the basic relationship between pixels.

UEC1722 Digital Image and Video


2
Processing
Session Outcomes

At the end of the session, you will be able,


• To understand neighborhood and adjacency between pixels.
• To explore the effect of different distance measures.

UEC1722 Digital Image and Video


3
Processing
U1-CO1 Outline

1
Neighbourhood & Adjacency

2 Path, Connectivity

3 Region & Boundary, Distance


measures

UEC1722 Digital Image and Video


4
Processing
Neighbors of a Pixel

There are three kinds of neighbors of a pixel:


•N4(p) 4-neighbors: the set of horizontal and vertical
neighbors (x-1, y), (x+1, y), (x,y-1), and (x, y+1).
•ND(p) diagonal neighbors: the set of 4 diagonal neighbors
(x-1, y-1), (x+1, y+1), (x+1,y-1), and (x-1, y+1).
•N8(p) 8-neighbors: union of 4-neighbors and diagonal
neighbors
O O O O O O
O X O X O X O
O O O O O O
UEC1722 Digital Image and Video 5
Processing
Neighbors of a Pixel

Given a pixel p in the center of 9 pixels:


a b c
d p e
f g h
then
• 4-neighbors of p = b, d, e, g; N4(p)
• diagonal neighbors of p = a, c, f, h; ND(p)
• 8-neighbors of p = a, b, c, d, e, f, g, h; N8(p)

UEC1722 Digital Image and Video


6
Processing
Adjacency

• Let V be the set of gray – level values used to define adjacency.


• Binary, V={1}; Gray scale image, V={subset of intensity values 0-255}
• 4 – adjacency: Two pixels p and q with values from V are 4 –
adjacent if q is in the set N4(p).
• 8 – adjacency: Two pixels p and q with values from V are 8 –
adjacent if q is in the set N8(p).
• m – adjacency (mixed adjacency): Two pixels p and q with values
from V are m – adjacent if
(i) q is in N4(p), or
(ii) q is in ND(p) and the set N4(p)  N4(q) has no pixels
whose values are from V (i.e., no common 4-adjacent neighbors)

UEC1722 Digital Image and Video


7
Processing
Path
• A (digital) path (or curve) from pixel p with coordinates (x0, y0)
to pixel q with coordinates (xn, yn) is a sequence of distinct pixels
with coordinates
(x0, y0), (x1, y1), …, (xn, yn)
where (xi, yi) and (xi-1, yi-1) are adjacent for 1 ≤ i ≤ n.

• N → length of the path.

• If (x0, y0) = (xn, yn), the path is closed path.

• 4-, 8-, and m-paths can be defined based on the type of adjacency
used.

UEC1722 Digital Image and Video


8
Processing
Examples - Adjacency and Path

V = {1, 2}
0 1 1 0 1 1 0 1 1
0 2 0 0 2 0 0 2 0
0 0 1 0 0 1 0 0 1

UEC1722 Digital Image and Video


9
Processing
Examples - Adjacency and Path

V = {1, 2}
0 1 1 0 1 1 0 1 1
0 2 0 0 2 0 0 2 0
0 0 1 0 0 1 0 0 1

8-adjacent

UEC1722 Digital Image and Video


10
Processing
Examples - Adjacency and Path

V = {1, 2}
0 1 1 0 1 1 0 1 1
0 2 0 0 2 0 0 2 0
0 0 1 0 0 1 0 0 1

8-adjacent m-adjacent

UEC1722 Digital Image and Video


11
Processing
Examples - Adjacency and Path

V = {1, 2}
0 1 1 0 1 1 0 1 1
0 2 0 0 2 0 0 2 0
0 0 1 0 0 1 0 0 1

8-adjacent m-adjacent

UEC1722 Digital Image and Video


12
Processing
Examples - Adjacency and Path

V = {1, 2}
0 1 1 0 1 1 0 1 1
0 2 0 0 2 0 0 2 0
0 0 1 0 0 1 0 0 1

8-adjacent m-adjacent

Considering the initial pixel as (1,1)


The 8-path from (1,3) to (3,3): The m-path from (1,3) to (3,3):
(i) (1,3), (1,2), (2,2), (3,3) (1,3), (1,2), (2,2), (3,3)
(ii) (1,3), (2,2), (3,3)

UEC1722 Digital Image and Video


13
Processing
Examples - Adjacency and Path

• M-adjacency path, V={1}


0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1
0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1
0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1
0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1
0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0

0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1
0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1
0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1
0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1
0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0

UEC1722 Digital Image and Video


14
Processing
Connectivity
• Let S represent a subset of pixels in an image
• Two pixels are said to be connected, if they are neighbors and
if their gray levels are equal.
• Connected component (c. c.): For any pixel p in S , the set of
pixels in S that are connected to p is called Connected
Component (entirety of pixels). If it has only one connected
component, then the set S is called a connected set.

S S→ Connected set
c.c. 1 c.c.

UEC1722 Digital Image and Video


15
Processing
Example - Connectivity

• In the following arrangement of pixels with set S, find the


nature of the set S. (use 8-adjacency, V={1})

Set S
1 1 1
1 0 1
0 1 0
0 0 1
1 1 1
1 1 1

UEC1722 Digital Image and Video


16
Processing
Example - Connectivity

• In the following arrangement of pixels with set S, find the


nature of the set S. (use m-adjacency)

Set S
1 1 1
1 0 1
0 1 0
0 0 1 One Connected Component →
1 1 1 Connected Set
1 1 1

UEC1722 Digital Image and Video


17
Processing
Region &Boundary
Region
• Let R represent a subset of pixels in an image, it is called a region of the
image if R is a connected set.
• Two regions, Ri and Rj are said to be adjacent if their union forms a connected
set.
• Regions that are not to be adjacent are said to be disjoint.
Boundary (or border/contour)
• The boundary of the 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 of the image.
Foreground and background
• An image contains K disjoint regions, Rk, k = 1, 2, …, K. Let Ru denote the
union of all the K regions, and let (Ru)c denote its complement.
All the points in Ru is called foreground;
All the points in (Ru)c is called background.
UEC1722 Digital Image and Video
18
Processing
Example - Region

• In the following arrangement of pixels, are the two regions


(of 1s) adjacent? (if 8-adjacency is used)

1 1 1
Region 1
1 0 1
0 1 0
0 0 1 Region 2

1 1 1
1 1 1

UEC1722 Digital Image and Video


19
Processing
Example - Region

• In the following arrangement of pixels, are the two parts (of


1s) adjacent? (if 4-adjacency is used)

1 1 1
Part 1
1 0 1
0 1 0
0 0 1 Part 2

1 1 1
1 1 1

UEC1722 Digital Image and Video


20
Processing
Example - Boundary

• In the following arrangement of pixels, the circled point is


part of the boundary of the 1-valued pixels if 8-adjacency is
used, true or false? (what if 4-adjacency is used?)

0 0 0 0 0
0 1 1 0 0
0 1 1 0 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0

UEC1722 Digital Image and Video


21
Processing
Example – Foreground, Background

• In the following arrangement of pixels, the two regions (of 1s)


are disjoint (if 4-adjacency is used)

1 1 1
foreground
1 0 1
0 1 0
0 0 1 background

1 1 1
1 1 1

UEC1722 Digital Image and Video


22
Processing
Distance Measures

• Given three pixels p, q, and z with coordinates (x, y), (s, t),
(u, v) respectively, D is a distance function or metric, if

(a) D(p,q)  0 (D(p,q) = 0, if p = q)

(b) D(p,q) = D(q,p), and

(c) D(p,z)  D(p,q) + D(q,z)

UEC1722 Digital Image and Video


23
Processing
Distance Measures
The three types of distances are:
1. Euclidean distance De(p, q) = [(x-s)2+(y-t)2]1/2
2. City-block distance (D4 distance)
D4(p, q) = | x - s | + | y - t |
The pixels with D4=1 to a pixel p are the 4-neighbors of p
3. Chessboard distance (D8 distance)
D8(p, q) = max ( | x - s | , | y - t | )
The pixels with D8=1 to a pixel p are the 8-neighbors of p
4. 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.
UEC1722 Digital Image and Video
24
Processing
Example – Distance Measures

• In the following arrangement of pixels, what’s the value of


the city-block distance between the two circled points?

0 0 0 0 0
0 0 1 1 0
0 1 1 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0

UEC1722 Digital Image and Video


25
Processing
Example – Distance Measures

• In the following arrangement of pixels, what’s the value of


the city-block distance between the two circled points?

0 0 0 0 0
(1,3)→(3,1)
0 0 1 1 0 D4 = │1-3│+│3-1│
0 1 1 0 0 = 4
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0

UEC1722 Digital Image and Video


26
Processing
Example – Distance Measures

• In the following arrangement of pixels, what’s the value of


the chessboard distance between the two circled points?

0 0 0 0 0
0 0 1 1 0
0 1 1 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0

UEC1722 Digital Image and Video


27
Processing
Example – Distance Measures

• In the following arrangement of pixels, what’s the value of


the chessboard distance between the two circled points?

0 0 0 0 0
(1,3)→(3,1)
0 0 1 1 0 D8 = max(│1-3│,│3-1│)
0 1 1 0 0 = 2
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0

UEC1722 Digital Image and Video


28
Processing
Example – Distance Measures

• In the following arrangement of pixels, what’s the value of


the Dm distance between the two circled points, V={1},
m-adjacent ?

0 0 0 0 0
0 0 1 1 0
0 1 1 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0

UEC1722 Digital Image and Video


29
Processing
Example – Distance Measures

• In the following arrangement of pixels, what’s the value of


the Dm distance between the two circled points, V={1},
m-adjacent ?

0 0 0 0 0
0 0 1 1 0
0 1 1 0 0 (1,3)→(1,2) →(2,2) →(2,1) →(3,1)
Dm = 1+1+1+1
0 1 0 0 0 = 4
0 0 0 0 0
0 0 0 0 0

UEC1722 Digital Image and Video


30
Processing
Summary

• The relationship between pixels in an image is discussed with


examples.
• The connectivity and adjacency between the pixels are
illustrated with examples.

UEC1722 Digital Image and Video


31
Processing
Test your understanding

Consider the image segment given below,


 V={0,1}, compute the length of 4-, 8- and m- path between p
and q .
 Repeat for V={1,2}
 Calculate the D4, D8 and Dm distance between p & q
3 1 2 1 (q)
2 2 0 2
1 2 1 1
(p)1 0 1 2

UEC1722 Digital Image and Video


32
Processing
References
• Gonzalez and Woods, Digital Image Processing, Pearson,
Third Edition, 2008.

Additional Reading:
• http://www.cse.iitm.ac.in/~vplab/courses/CV_DIP/PDF/NEIG
H_CONN.pdf

UEC1722 Digital Image and Video


33
Processing

You might also like