Lecture No 7 Spatial Filtering
Lecture No 7 Spatial Filtering
U M E R J AV E D
( U M E R . J AV E D @ I I U . E D U . P K )
D E PA R T M E N T O F E L E C T R O N I C
ENGINEERING,
FA C U LT Y O F E N G I N E E R I N G & T E C H N O L O G Y,
IIUI
SPRING 2017
CS-407:
Digital Image Processing
U M E R J AV E D
( U M E R . J AV E D @ I I U . E D U . P K )
CHAPTER: 3
I N T E N S I T Y T R A N S F O R M AT I O N A N D S PAT I A L
F I LT E R I N G
S L I D E # 3 , PA R T B
S PAT I A L F I LT E R I N G
Background
a b
g ( x, y ) w(s, t ) f ( x s, y t )
s at b
Simplify expression mn
R w1 z1 w2 z2 ... wmn zmn wi zi w1 w2 w3
i 1
9 w4 w5 w6
R w1 z1 w2 z2 ... w9 z9 wi zi w7 w8 w9
i 1
Where the w’s are mask coefficients, the z’s are the value of the image gray
levels corresponding to those coefficients
Order-Statistics Filters
1 1 1 1 2 1
1 1
1 1 1 2 4 2
9 16
1 1 1 1 2 1
1 1 1 1 1
1 1 1 1 1
1
x 1 1 1 1 1
25
1 1 1 1 1
1 1 1 1 1
a b
w(s, t ) f ( x s, y t )
g ( x, y ) s at b
a b
w(s, t )
s at b
Original Image
Corp region of
neighborhood
10 15 20
Sort the values of
20 100 20 the pixel in our
region
20 20 25
In the MxN mask
the median is MxN
10, 15, 20, 20, 20, 20, 20, 25, 100 div 2 +1
5th
Umer Javed, CS:407 Digital Image Processing Chapter:3, Slide # 19
Result of median filter
f
f ( x 1) f ( x)
x
2 f
f ( x 1) f ( x 1) 2 f ( x).
x 2
000123200226332233000000776553
7
6
5
4
3
2
1
0
0 0 0 1 2 3 2 0 0 2 2 6 3 3 2 2 3 3 0 0 0 0 0 0 7 7 6 5 5 3
second 0-1 0 0-2-1 2 2-2 4-7 3-1 1 1-1-3 3 0 0 0 0-7 7-1 0 1-2
2
f 2
f
f 2 2
2
x y
f(x,y-1)
f(x,y) 2 f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y 2
f(x,y+1)
2
f 2
f
2 f 2 2
x x
2 f f ( x 1, y) f ( x 1, y) f ( x, y 1) f ( x, y 1) 4 f ( x, y)
1 -4 1
0 1 0 1 1 1
1 -4 1 1 -8 1
0 1 0 1 1 1
1 0 1
0 -4 0
1 0 1
0 -1 0 -1 -1 -1
-1 4 -1 -1 8 -1
0 -1 0 -1 -1 -1
-1 0 -1
0 4 0
-1 0 -1
Filtered = Conv(image,mask)
And then add the image result from step 1 and the
original image
g ( x, y) f ( x, y) f ( x 1, y) f ( x 1, y) f ( x, y 1) f ( x, y 1) 4 f ( x, y)
g ( x, y) 5 f ( x, y) f ( x 1, y) f ( x 1, y) f ( x, y 1) f ( x, y 1)
0 -1 0 -1 -1 -1
-1 5 -1 -1 9 -1
0 -1 0 -1 -1 -1
f hb ( x, y) Af ( x, y) f ( x, y) where A 1
f hb ( x, y) ( A 1) f ( x, y) f ( x, y) f ( x, y)
f hb ( x, y) ( A 1) f ( x, y) f s ( x, y)
0 -1 0 -1 -1 -1
-1 A+4 -1 -1 A+8 -1
0 -1 0 -1 -1 -1
f
Gx x
f f
G y
y
Gy 1
-1
z4 z5 z6 f ( z9 z5 ) 2 ( z8 z6 ) 2
z7 z8 z9
f z9 z5 z8 z6
-1 0 0 -1
0 1 1 0
f ( z7 2 z8 z9 ) ( z1 2 z2 z3 ) ( z3 2 z6 z9 ) ( z1 2 z4 z7 )
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
Neighborhood
Filter
Mask, kernel, window
Size
Symmetry
Correlation
Convolution
Neighborhood
Adjacency
Connectivity
Paths
Neighborhood
Adjacency
Connectivity
Paths
Neighborhood
Adjacency
Connectivity
Paths