You are on page 1of 31

1

Lahore Garrison University


Digital Image Processing
Lectures
Semester#7

Prepared by:

Engr. Muhammad Nadeem Ali


2
Instructor Contact Details

 Name: Muhammad Nadeem Ali


 Course Instructor: Digital Image Processing
 Credit Hours: 2+1=3
 Designation : Senior Lecturer
 Office Location: CS-Staff Room Cabin
 Email: mnadeemali@lgu.edu.pk
 Visiting Hours: Monday- Friday (08:00-04:00)
 Lab instructor : Miss Arfa Hasan, Mr. Umair Bin Ahmed

Lahore Garrison University


3

Image Sampling and Quantization, Some Basic


Relationships between Pixels

Lahore Garrison University


4
Image Sampling and Quantization:

Image sampling:
discretize an image in the
spatial domain
Spatial resolution/
image resolution: pixel
size or number of pixels

Lahore Garrison University


5
How to choose the spatial resolution:

Spatial resolution
Original
image
Sampled
image

Lahore Garrison University Under sampling, we lost some image details!


6
How to choose the spatial resolution :
Nyquist Rate:
Original image

Sampled image Nyquist Rate:


Spatial resolution must be less or
equal
half of the minimum period of the
image
or sampling frequency must be
1mm

2mm greater or
Equal twice of the maximum
Minimum frequency.
Period No detail is lost!
Spatial
resolution
Lahore Garrison University (sampling rate)
7

Aliased Frequency:

1
x1 (t )  sin( 2t ), f 1
0.5

0 x2 (t )  sin(12t ), f  6
-0.5

-1
0 0.5 1 1.5 2

0.5 Sampling rate:


5 samples/sec
0

-0.5

-1
0 0.5 1 1.5 2

Lahore Garrison University


Two different frequencies but the same results !
8
Effect of Spatial Resolution

64x64 pixels 32x32 pixels

256x256 pixels 128x128 pixels

Lahore Garrison University


9
Effect of Spatial Resolution:

Lahore Garrison University


10
Moire Pattern Effect : Special Case of Sampling

Moire patterns occur when frequencies of two superimposed


Lahore Garrison University periodic patterns are close to each other.
11

Effect of Spatial Resolution:

Lahore Garrison University


12
Can we increase spatial resolution by
interpolation ?

Down sampling is an
irreversible process.

Lahore Garrison University


13
Image Quantization:

Image quantization:
discretize continuous pixel values into discrete numbers

Color resolution/ color depth/ levels:


- No. of colors or gray levels or
- No. of bits representing each pixel value
- No. of colors or gray levels Nc is given by

where b = no. of bits


Nc  2 b

Lahore Garrison University


14

Quantization function:

Nc-1
Quantization level Nc-2

1
0
Light intensity
Lahore Garrison University Darkest Brightest
15
Effect of Quantization Levels:

64 levels 32 levels

256 levels 128 levels

Lahore Garrison University


16
Effect of Quantization Levels (cont.):

4 levels 2 levels

16 levels 8 levels

In this image,
it is easy to see
false contour.
Lahore Garrison University
17
How to select the suitable size and pixel depth of images:

The word
“suitable” is
subjective:
depending on
“subject”.

Low detail image Medium detail image High detail image


Lena image Cameraman image
To satisfy human mind
1. For images of the same size, the low detail image may need more pixel depth.
2. As an image size increase, fewer gray levels may be needed.
Lahore Garrison University
18
Human vision: Spatial Frequency vs Contrast:

Lahore Garrison University


19
Human vision: Distinguish ability for Difference
in brightness

Regions with 5% brightness difference

Lahore Garrison University


20
Basic Relationship of Pixels:

(0,0) x

Conventional indexing method


(x-1,y-1) (x,y-1) (x+1,y-1)

(x-1,y) (x,y) (x+1,y)


y

(x-1,y+1) (x,y+1) (x+1,y+1)

Lahore Garrison University


21
Neighbors of a Pixel:

Neighborhood relation
(x,y-1) 4-neighbors of p: is used to tell adjacent
pixels. It is
useful for analyzing
(x-1,y)
(x-1,y) p (x+1,y) regions.
(x+1,y)
N4(p) = (x,y-1)
(x,y+1) 4-neighborhood
(x,y+1)
relation considers only
vertical and
horizontal neighbors.
Note: q Î N4(p) implies p Î N4(q)

Lahore Garrison University


22
Neighbors of a Pixel (cont.):

(x-1,y-1) (x,y-1) (x+1,y-1) (x-1,y-1) 8-neighbors of p:


(x,y-1)
(x+1,y-1)
(x-1,y) p (x+1,y) N8(p) = (x-1,y)
(x+1,y)
(x-1,y+1)
(x,y+1)
(x-1,y+1) (x,y+1) (x+1,y+1)
(x+1,y+1)

8-neighborhood relation considers all neighbor pixels.


Lahore Garrison University
23
Neighbors of a Pixel (cont.):

(x-1,y-1) (x+1,y-1) Diagonal neighbors of p:

(x-1,y-1)
p
(x+1,y-1)
ND(p) = (x-1,y+1)
(x+1,y+1)
(x-1,y+1) (x+1,y+1)

Diagonal -neighborhood relation considers only diagonal


neighbor pixels.

Lahore Garrison University


24
Connectivity:

 Connectivity is adapted from neighborhood relation.


 Two pixels are connected if they are in the same class (i.e. the
 same color or the same range of intensity) and they are
 neighbors of one another.
 For p and q from the same class
w 4-connectivity: p and q are 4-connected if q ÎN4(p)
w 8-connectivity: p and q are 8-connected if q Î N8(p)
w mixed-connectivity (m-connectivity):
p and q are m-connected if q Î N4(p) or
q Î ND(p) and N4(p) Ç N4(q) = Æ
Lahore Garrison University
25

Adjacency:

A pixel p is adjacent to pixel q is they are connected.


Two image subsets S1 and S2 are adjacent if some pixel in S1
is adjacent to some pixel in S2

We can define type of adjacency: 4-adjacency, 8-adjacency


or m-adjacency depending on type of connectivity.
S1
S2

Lahore Garrison University


26
Path:

A path from pixel p at (x,y) to pixel q at (s,t) is a


sequence
of distinct pixels:
(x0,y0), (x1,y1), (x2,y2),…, (xn,yn) q
p
such that
(x0,y0) = (x,y) and (xn, yn) = (s,t)
and
(xi,yi) is adjacent to (xi-1,yi-1), i = 1,…,n
We can define type of path: 4-path, 8-path or m-path
depending on type of adjacency.

Lahore Garrison University


27

Path (cont.):
8-path m-path
p p p

q q q

8-path from p to q m-path from p to q


results in some ambiguity solves this ambiguity

Lahore Garrison University


28
Distance:

For pixel p, q, and z with coordinates (x,y), (s,t) and (u , v),


D is a distance function or metric if

w D( p, q) ³ 0 (D(p , q) = 0 if and only if p = q)


w D(p , q) = D(q , p)
w D(p , z) £ D(p , q) + D(q , z)

Example: Euclidean distance

De ( p, q)  ( x  s ) 2  ( y  t ) 2

Lahore Garrison University


29

Distance (cont.):

D4-distance (city-block distance) is defined as

D4 ( p, q)  x  s  y  t

2 1 2

2 1 0 1 2

2 1 2

2
Pixels with D4(p) = 1 is 4-neighbors of p.
Lahore Garrison University
30

Distance (cont.):

D8-distance (chessboard distance) is defined as

D8 ( p, q)  max( x  s , y  t )

2 2 2 2 2

2 1 1 1 2

2 1 0 1 2

2 1 1 1 2

2 2 2 2 2

Lahore Garrison University


Pixels with D8(p) = 1 is 8-neighbors of p.
31

Thankyou

Lahore Garrison University

You might also like