Ch-2C Spatial Filteing
Ch-2C Spatial Filteing
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 22
2
1
Masking Operation: Consider an image F and filter mask W
F Z1 Z2 Z3 w = w1 w2 w3 A =
=
Z4 Z5 Z6 * w4
w7
w5
w8
w6 ==
w9
R
Z7 Z8 Z9
R=
Spatial Filtering
F(8,11)
O 1 2 3 4 5 6 7 8 9 10 11 y
O z1 z2 z3 w1 w2 w3
1
2
3
4
z4 z5 z6
z7 z8 z9
* w4 w5 w6
w7 w8 w9
5
6
7 Original Image Filter Mask
8 Pixels
The response of Filter at
A(8,11) position is given by,
A(8,11) = z1 w1 + z2 w2 +
x Input Image F z3 w3+ … + z9 w9
2
List of Spatial Filters
[I] Smoothing Linear Filters (3)
Eg. Low Pass Averaging Filter, Weighted Average Filter,
Trimmed Averaging Filter and Geometric Mean Filter
[II] Smoothing Non-Linear Filters (3)
Eg. Median, Max and Min Filter.
[III] Sharpening : First Order Derivative Filters (4)
Eg. Robert, Prewit, Sobel and Fri-Chen filter
[IV] Sharpening Second Order Derivative Filters (3)
Eg. Laplacian Filter, HPF and High Boost Filter
3
(iii) LPF removes sharp transitions in the image
• Sharp transitions are due to :
(1) High frequency random Impulse Noise.
(2) High frequency Edges of an object.
. .
F= 0 0 0
0 200 0
0 0 0
4
Eg. Digital Image with impulse noise
0 0 0
0 0 LPF
200
0 0 0
A=
F= 0 1 2
LPF
7 255 3
6 5 4
Case-1 : Assume virtual Rows and Columns with Zero pixel Values
10
5
(1) To find A(0,0)
A(0,1) = ( 0 + 0 + 0 + 0 + 1 + 2 + 7 + 255 + 3 )/ 9
A(0,1) = 29.77
By rounding,
A(0,1) = 30
A(0,2) = 29
6
(5) To find A(1,2)
A(1,2) = ( 1 + 2 + 0 + 255 + 3 + 0 + 5 + 4 + 0 ) / 9
A(1,2) = 30
By rounding,
A(1,2) = 30
7
Derivation of LPF Mask
Consider a Digital Image F and LPF Mask w as
shown in figure below,
F = Z1 Z2 Z3 A=
LPF
Z4 Z5 Z6
Z7 Z8 Z9
w1 w2 w3
w4 w5 w6
w7 w8 w9
F = Z1 Z2 Z3 A=
LPF
Z4 Z5 Z6 R
Z7 Z8 Z9 w = w1 w2 w3
w4 w5 w6
w7 w8 w9
8
By averaging output pixel value at (x,y) position
is given by,
R= ( z1 + z2 + z3 + … + z9 )
R= z1 + z2 + + … + z9 ) …… (II)
w= W1= W 2= W 3= w=
1 1 1
W4= W 5= W 6= 1 1 1
W7= W 8= W9 = 1 1 1
9
Pixel Position Weight
1 Center Pixel 4
2 Four Directional 2
Neighbour
3 Diagonal Direction 1
Neighbour
F= Z Z Z A=
1 2 3
Weighted
Z4 Z5 Z6 Average Filter R
Z7 Z8 Z9
10
(3) Trimmed Averaging Filter
A non-linear smoothing filter.
11
(4) Alpha (α)-Trimmed Averaging Filter
A non-linear smoothing filter.
F = 20 20 18 A=
21 19 12 A(x,y)
19 22 10
To find A(x,y)
For different values of α, the output is as follows:
Case-1 : When α = 0
F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}
A(x,y) =
Case-2 : When α = 1
12
Case-3 : When α = 2
F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}
A(x,y) =
Case-4 : When α = 3
F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}
A(x,y) =
Case-5 : When α = 4
F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}
A(x,y) =
13
(5) Geometric Mean Filter
The geometric mean filter is an image filtering process
meant to smooth and reduce noise of an image.
F= 5 16 22 A=
Geometric
6 3 18 Mean A(x,y)
Filter
12 3 15
A(x,y) = (5 * 16 * 22 * 6 * 3 * 18 * 12 * 3 * 15)^(1/9)
A(x,y) = 8.77
14
[II] Smoothing Non-Linear Filters
[ also called as ordered statistic filters]
15
Eg. Consider a Digital Image F
F = 41 200 60 A=
52 45 72 Median A(x,y)
Filter
10 58 81
58
16
To remove noisy pixels, assume virtual rows and
columns with repeated border pixel values
A=
41 41 200 60 60
F= 41 41 200 60 60 Median
Filter
52 52 45 42 42
0 0 58 51 51
0 0 58 51 51
17
F= 41 200 60 ▪ Eliminated noisy pixel values
are replaced by one of the
52 45 42
neighbouring pixel values.
0 58 51
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 35
35
18
Eg.
F= 41 200 60 A=
52 45 42
Max
200
Filter
0 58 51
F= 41 200 60 A=
52 45 42
Min
0
Filter
0 58 51
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 37
37
Smoothing
SUM Integration
Filter
Ex. LPF
Sharpening
Filter Difference Differentiation
Ex. HPF
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 38
38
19
[ III ] Sharpening First Order Derivative filters
[also called as Gradient Filters]
Eg: Robert, Prewit, Sobel and Fri-chen filters
Where,
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 40
40
20
y-1 y y+1
F=
x-1
x+1
y
1. Robert Filter F=
( 1st Order Derivative Sharpening filter )
x
▪ To find Gx
▪ To find Gy
-
-
-1 0
1 0 -1 1
0 0
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 42
42
21
y
2. Prewit Filter z1 z2 z3
( 1st Order Derivative - Sharpening filter ) x z4 z5 z6
z7 z8 z9
▪ To find Gx ▪ To find Gy
Gx= (z7–z1)+ (z8–z2) + (z9–z3) Gx= (z3–z1)+(z6–z4)+ (z9–z7)
y
3. Sobel Filter z1 z2 z3
( 1st Order Derivative - Sharpening filter ) x z4 z5 z6
z7 z8 z9
▪ To find Gx ▪ To find Gy
Gx= (z7–z1) +2 (z8–z2) + (z9–z3) Gy= (z3–z1)+ 2 (z6–z4) + (z9–z7)
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 44
44
22
y
4. Fri-Chen Filter z1 z2 z3
( 1st Order Derivative - Sharpening filter ) x z4 z5 z6
z7 z8 z9
▪ To find Gx ▪ To find Gy
Gx= (z7–z1) + (z8–z2)+(z9–z3) Gy= (z3–z1)+ (z6–z4)+ (z9–z7)
-1 - - 1 -1 0 1
0 0 0 - 0
1 1 -1 0 1
α=
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 46
46
23
Example-1 :
F= 41 200 60 Prewit A=
52 45 42 Gradient R
0 58 51 Filter
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 47
47
Similarly,
F= 41 200 60 Prewit A=
52 45 42 Gradient R
0 58 51 Filter
24
Example...
F= 41 200 60 Prewit A=
52 45 42 Gradient R
0 58 51 Filter
(iii) To find R
( 192 ) + ( 60 )
( 252 )
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 49
49
25
y-1 y y+1
(i) Find G2x x-1 f(x-1,y)
G2x = 0 1 0 G2x =
0 -2 0
0 1 0 Scale by (-1)
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 51
51
y-1 y y+1
(i) Find G2y x-1 f(x-1,y)
G 2y = 0 0 0 G2y =
1 -2 1
0 0 0 Scale by (-1)
26
y-1 y y+1
(iii) Find x-1 f(x-1,y)
x+1 f(x+1,y)
=
+
=
Laplacian 4 directional
Mask
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 53
53
(iv) Find
= +
( 4 Directional) ( Diagonal Directional)
= 0 -1 0 -1 0 -1
+
-1 4 -1 0 4 0
0 -1 0 -1 0 -1
= -1 -1 -1
Laplacian 8 directional
-1 8 -1
Mask
-1 -1 -1
27
(2) High Pass Filter
(i) HPF attenuates LOW frequency Components and
allows to pass HIGH frequency components of the
image.
(ii) HPF image can be obtained by subtracting LPF image
from the original image.
(iii) HPF Mask is given by,
w=
-1 -1 -1
-1 8 -1
-1 -1 -1
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 55
55
10 10
100
200 100
200 0 30 30 0
H PF
10 10 200
100 100
200 0 30 30 0
10 10 200
100 100
200 0 30 30 0
-1 -1 -1
W= -1 8 -1
-1 -1 -1
28
Derivation of HPF Mask
Consider a Digital Image F and HPF Mask w as
shown in figure below,
Z1 Z2 Z3
LPF A(x,y)
Z4 Z5 Z6
Z7 Z8 Z9
w = w1 w2 w3
w4 w5 w6
w7 w8 w9
The response of HPF mask at A(x,y) position is given by,
A(x,y) = z1 w1 + z2 w2 + z3 w3 + …+ z9 w9 ……(I)
Dr. Kiran TALELE 99870 30 881 [email protected] 57
57
Z1 Z2 Z3
LPF
Z4 Z5 Z6 B(x,y)
Z7 Z8 Z9 w = 1 1 1
1 1 1
1 1 1
B(x,y) = z1 + z2 + + … + z9 …… (II)
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 58
58
29
Now, Original Image = LPF Image + HPF Image
= Z1 Z2 Z3 -
A(x,y) B(x,y)
Z4 Z5 Z6
Z7 Z8 Z9
At (x,y) position,
A(x,y) = Z5 - B(x,y)
Where, B(x,y) = z1 + + z2 + + … + z9
A(x,y) = Z5 – ( z1 z1 + -- z2 + + + + z9 )
= Z5 - z1 - z2 - z3 - z4 - Z5 … z9 )
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 60
60
30
By equating equation (I) and (III) we get,
w= W1= W 2= W 3= w=
W4= W 5= W 6=
W7= W 8= W9 =
= Z1 Z2 Z3 +
A(x,y) B(x,y)
Z4 Z5 Z6
Z7 Z8 Z9
At (x,y) position,
A(x,y) = Z5 + B(x,y)
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 62
62
31
Now, A(x,y) = Z5 + B(x,y)
Where, B(x,y) = - z1 - z2 - z3 - z4 + z5 - z9
By Substituting,
A(x,y) = Z5 + ( - z1 - z2 - z3 - z4 + Z5 - z9)
A(x,y) = - z1 - z2 - z3 - z4 + Z5 … - z9
Let A(x,y) = z1 w1 + z2 w2 + z3 w3 + … + z9 w9
w= W1= W 2= W 3= w=
W4= W 5= W 6=
W7= W 8= W9 =
☆
Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 64
64
64
32