Professional Documents
Culture Documents
3.3. Smoothing Spatial Filtering
3.3. Smoothing Spatial Filtering
Contact: kalpoma@aust.com
Google Class code: o5sjihh
Chapter 3 from R.C. Gonzalez and R.E. Woods, Digital Image Processing
(3rd Edition), Prentice Hall, 2008 [ Section 3.4, 3.5 ]
Where have we reached until now!
Till now we have discussed two important methods to manipulate
images.
1. Transformation Functions
f(x,y) g(x,y)
2. Histogram Processing
f(x,y) g(x,y)
Another way of dealing images
So now we are going to use this third method,
known as convolution. It can be represented as
g(x,y)
f(x,y)
m 1 n 1
where a = , b=
2 2
x 0,1, 2,...., M 1, y 0,1, 2,..., N 1
Sum of Product
Spatial Correlation & Convolution
Sum of Product
Spatial Filtering
Really important!
– Enhance images
• De-noise, resize, increase contrast, etc.
– Extract information from images
• Texture, edges, distinctive points, etc.
– Detect patterns
• Template matching
2016/1/27 16
Smoothing Spatial filters
Use: for blurring and noise reduction.
1.Standard average/Mean
linear
2.Weighted average.
*
99 106 98 1
/9 1
/9 1
/9
95 90 85
1
/9 1
/9 1
/9
y Image f (x, y)
20
of
42
Average/Mean filtering Process
*
99 106 98 1
/9 1
/9 1
/9
95 90 85
1
/9 1
/9 1
/9
10
1/ 91/10
1/9 109
Original Filter
Simple 3*3 4 0 8 3*3 Smoothing Image
199
/ 9 1/ 91/ 989
106
Neighbourhood /9 190
1
95 / 9 185
/9
Filter Pixels
98.3333
106 will be replaced by 98 at g(x,y) image
h[.,.] 1 1 1
f [.,.] g[ , ]
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 1 1
f [.,.] g[ , ]
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0 10
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 0
0 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 90
90 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
1 1 1
f [.,.] g[ , ]
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0 10 20
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 0
0 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 90
90 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
1 1 1
f [.,.] g[ , ]
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0 10 20 30
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 0
0 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 90
90 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
1 1 1
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 1 1
f [.,.] g[ , ]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
?
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 1 1
f [.,.] g[ , ]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
?
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0 50
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
f [.,.] g[ , ]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10
0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30
0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20
0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10
0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
e
e
e e e
y
Image f (x, y)
First solution : Zero
padding
(e.g.
(e.g. 512x512
512x512 input
input 510x510
510x510 output
output ifif mask
mask
size
size is
is 3x3)
3x3)
17 24 1 8 15
23 5 7 14 16 5 7 14
4 6 13 20 22 6 13 20
10 12 19 21 3 12 19 21
11 18 25 2 9
34
What does Mean or Box filter do?
Original image
Smooth by 3x3
Size: 500x500 box filter
Smooth by
Smooth by
35x35 box filter
15x15 box filter
Noticehow
Notice howdetail
detailbegins
beginsto
todisappear
disappear
Weighted Smoothing Filters
More effective smoothing filters can be
generated by allowing different pixels in the
neighbourhood different weights in the
averaging function.
Consider
Considerthe
the
output
outputpixel
pixelis
is
positioned
positionedatat
the
thecenter
center
91 94 98 200
90 91 99 100
82 96 85 90
40
Median filter
A Median Filter operates over a window by selecting the
median intensity in the window.
• No new pixel values
introduced
• Never replace with
Median = ?
largest or smallest value
• Removes spikes: good
for impulse, salt &
pepper noise
• Non-linear filter
Particularly
Particularlyeffective
effectivewhen
when
Thenoise
The noisepattern
patternconsists
consistsofofstrong
strongimpulse
impulsenoise
noise((salt-and-pepper)
salt-and-pepper)
Median filter: Example
Median filter effect: Blurring + Reduce Noise
Very effective for removing “salt and pepper” noise
2016/1/27 44
Spatial Filtering:
with coefficient mask
Given the 3×3 mask with coefficients: w1, w2,…, w9
The mask cover the pixels with gray levels: z1, z2,…, z9
w1 w2 w3 z1 z2 z3
w4 w5 w6 z4 z5 z6
w7 w8 w9 z7 z8 z9
Sum of Product
99
zz
zz99ww99
zz11ww11zz22ww22 zz33ww33 zzi iwwi ii
i 11
z gives the output intensity value for the processed image (to be stored in a new
array) at the location of z5 in the input image
45
Predict the outputs using coefficient
filtering
0 0 0 0 0 0
* 0 1 0 =? * 0 0 1 =?
0 0 0 0 0 0
0 0 0 1 1 1
* 0 2 0
0 0 0
- 1 1 1
1 1 1
=?
Practice with linear filters
0 0 0
0
0
1
0
0
0
?
Original
Source: D. Lowe
Practice with linear filters
0 0 0
0 1 0
0 0 0
Original Filtered
(no change)
Source: D. Lowe
Practice with linear filters
0 0 0
0
0
0
0
1
0
?
Original
Source: D. Lowe
Practice with linear filters
0 0 0
0 0 1
0 0 0
Source: D. Lowe
Practice with linear filters
00 00 00 1 11 11 1
-- ?
* 00 22 00
00 00 00
1 11 11 1
1 11 11 1
Original
Source: D. Lowe
Practice with linear filters
00 00 00 1 11 11 1
--
* 00 22 00
00 00 00
1 11 11 1
1 11 11 1
Source: D. Lowe
More Applications of filtering
54
55
2016/1/27
g(x,y) = i
56
2016/1/27
57
2016/1/27
58
2016/1/27
59
2016/1/27
60
2016/1/27