Professional Documents
Culture Documents
5 Spatial
5 Spatial
of
19
Contents
In this lecture we will look at spatial filtering
techniques:
Digital Image Processing – Neighbourhood operations
– What is spatial filtering?
– Smoothing operations
– What happens at the edges?
Image Enhancement – Correlation and convolution
(Spatial Filtering 1)
3 4
of
19
Neighbourhood Operations of
19
Simple Neighbourhood Operations
Neighbourhood operations simply operate Some simple neighbourhood operations
on a larger neighbourhood of pixels than include:
point operations Origin x – Min: Set the pixel value to the minimum in
Neighbourhoods are the neighbourhood
mostly a rectangle – Max: Set the pixel value to the maximum in
around a central pixel the neighbourhood
(x, y) – Median: The median value of a set of
Any size rectangle Neighbourhood
numbers is the midpoint value in that set (e.g.
and any shape filter from the set [1, 7, 15, 18, 24] 15 is the
are possible median). Sometimes the median works better
y Image f (x, y)
than the average
5 Simple Neighbourhood Operations 6
of
19 Example
of
19
The Spatial Filtering Process
Origin x
a b c r s t
Original Image x Enhanced Image x
123 127 128 119 115 130
d
g
e
h
f
i
* u
x
v
y
w
z
140 145 148 153 167 172 Original Image Filter
Simple 3*3 Pixels
e 3*3 Filter
Neighbourhood
133 154 183 192 194 191
eprocessed = v*e +
194 199 207 210 198 195 r*a + s*b + t*c +
u*d + w*f +
164 170 175 162 173 151 y Image f (x, y) x*g + y*h + z*i
y y
The above is repeated for every pixel in the
original image to generate the filtered image
7 8
of
19
Spatial Filtering: Equation Form of
19
Smoothing Spatial Filters
a b One of the simplest spatial filtering
w(s, t ) f ( x s, y t )
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
is an original image of
99 106 98
95 90 85
* 1/
1/
9
1/
1/
9
1/
1/
9
size 500*500 pixels
9 9 9
Simple 3*3
1/ 100
104
9
1/ 108
9
1/
9
3*3 Smoothing
Original Image Filter The subsequent images
1/ 1/
9 106
99 1/
9 98
Pixels
show the image after
9
Neighbourhood 195
/9 190
/9 185
/9
Filter
e = 1/9*106 +
1/ *104 + 1/ *100 + 1/ *108 + filtering with an averaging
9 9 9
1/ *99 + 1/ *98 +
9 9
filter of increasing sizes
y Image f (x, y) 1/ *95 + 1/ *90 + 1/ *85
9 9 9 – 3, 5, 9, 15 and 35
= 98.3333
Notice how detail begins
The above is repeated for every pixel in the
to disappear
original image to generate the smoothed image
11 12
of
19
Image Smoothing Example of
19
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Images taken from Gonzalez & Woods, Digital Image Processing (2002) Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
of
19
15
19
13
Images taken from Gonzalez & Woods, Digital Image Processing (2002) Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
of
19
16
19
14
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
generated by allowing different pixels in the of lots of the finer detail which leaves only
neighbourhood different weights in the the gross features for thresholding
averaging function
1/ 2/ 1/
– Pixels closer to the 16 16 16
central pixel are more
2/ 4/ 2/
important 16 16 16
– Often referred to as a 1/ 2/ 1/
weighted averaging 16 16 16
Original Image Smoothed Image Thresholded Image
Weighted
averaging filter
19
of
Averaging Filter Vs. Median Filter 20
of
Averaging Filter Vs. Median Filter
19 Example 19 Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
23 Simple Neighbourhood Operations 24
of of Strange Things Happen At The Edges!
19 Example 19
y
e e e
y Image f (x, y)
25
of
Strange Things Happen At The Edges! 26
of
Simple Neighbourhood Operations
19 (cont…) 19 Example
There are a few approaches to dealing with
missing edge pixels: x
– Omit missing pixels 123 127 128 119 115 130
• Only works with some filters
140 145 148 153 167 172
• Can add extra code and slow down processing
133 154 183 192 194 191
– Pad the image
• Typically with either all white or all black pixels 194 199 207 210 198 195
27
of
Strange Things Happen At The Edges! 28
of
Strange Things Happen At The Edges!
19 (cont…) 19 (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Filtered Image:
Zero Padding
Filtered Image:
Wrap Around Edge Pixels
29
of
Strange Things Happen At The Edges! 30
of
Strange Things Happen At The Edges!
19 (cont…) 19 (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
31 32
of
19
Correlation & Convolution of
19
Summary
The filtering we have been talking about so In this lecture we have looked at the idea of
far is referred to as correlation with the filter spatial filtering and in particular:
itself referred to as the correlation kernel – Neighbourhood operations
– The filtering process
Convolution is a similar operation, with just
– Smoothing filters
one subtle difference
– Dealing with problems at image edges when
a b c r s t eprocessed = v*e + using filtering
z*a + y*b + x*c + – Correlation and convolution
d
f
e
g h
e
* u
x
v
y
w
z
w*d + u*e +
Next time we will looking at sharpening
t*f + s*g + r*h
Original Image Filter filters and more on filtering and image
Pixels
enhancement
For symmetric filters it makes no difference