Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

1 2

of
19
of
19
Contents
In this lecture we will look at spatial filtering
techniques:
– Neighbourhood operations
– What is spatial filtering?
– Smoothing operations
– What happens at the edges?
– Correlation and convolution
Image Enhancement
(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

1
5 Simple Neighbourhood Operations 6
of of The Spatial Filtering Process
19 Example 19

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)

g ( x, y )  operations we can perform is a smoothing


s   at   b
operation
Filtering can be given – Simply average all of the pixels in a
in equation form as neighbourhood around a central value
shown above – Especially useful
1/ 1/ 1/
Notations are based in removing noise 9 9 9
from images Simple
on the image shown 1/ 1/ 1/
– Also useful for 9 9 9 averaging
to the left
highlighting gross filter
1/ 1/ 1/
detail 9 9 9

2
9 10
of
19
Smoothing Spatial Filtering of
19
Smoothing Spatial Filtering
Origin x Origin x
104 100 108 1/ 1/ 1/ 104 100 108 1/ 1/ 1/
9 9 9 9 9 9

99 106 98

95 90 85
* 1/

1/
9
1/

1/
9
1/

1/
9 99 106 98

95 90 85
* 1/

1/
9
1/

1/
9
1/

1/
9

9 9 9 9 9 9

1/ 100
104
9
1/ 108
9
1/
9
Original Image Filter 1/ 100
104
9
1/ 108
9
1/
9
Original Image Filter
Simple 3*3 199
/9 1106
/9 198
/9
3*3 Smoothing Pixels Simple 3*3 199
/9 1106
/9 198
/9
3*3 Smoothing Pixels
Neighbourhood 195
/9 190
/9 185
/9
Filter Neighbourhood 195
/9 190
/9 185
/9
Filter
e = 1/9*106 + e = 1/9*___ +
1/ *104 + 1/ *100 + 1/ *108 + 1/ *___ + 1/ *___ + 1/ *___ +
9 9 9 9 9 9
1/ *99 + 1/ *98 + 1/ ___ + 1/ *___ +
9 9 9 9
y Image f (x, y) 1/ *95 + 1/ *90 + 1/ *85 y Image f (x, y) 1/ *___ + 1/ *___ + 1/ *___
9 9 9 9 9 9
= 98.3333 = _____
The above is repeated for every pixel in the The above is repeated for every pixel in the
original image to generate the smoothed image original image to generate the smoothed image

11 12
of
19
Image Smoothing Example of
19
Weighted Smoothing Filters
The image at the top left More effective smoothing filters can be
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

is an original image of generated by allowing different pixels in the


size 500*500 pixels neighbourhood different weights in the
The subsequent images averaging function
1/ 2/ 1/
show the image after – Pixels closer to the 16 16 16

filtering with an averaging central pixel are more


2/ 4/ 2/
important 16 16 16
filter of increasing sizes
– Often referred to as a
– 3, 5, 9, 15 and 35 1/ 2/ 1/
weighted averaging 16 16 16
Notice how detail begins Weighted
to disappear averaging filter

3
13 14 Averaging Filter Vs. Median Filter
of Another Smoothing Example of
19 19 Example
By smoothing the original image we get rid
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of lots of the finer detail which leaves only
the gross features for thresholding

Original Image Image After Image After


With Noise Averaging Filter Median Filter

Filtering is often used to remove noise from


images
Original Image Smoothed Image Thresholded Image Sometimes a median filter works better than
an averaging filter

15 16 Strange Things Happen At The Edges!


of Strange Things Happen At The Edges! of
19 19 (cont…)
At the edges of an image we are missing There are a few approaches to dealing with
pixels to form a neighbourhood missing edge pixels:
Origin x – Omit missing pixels
e e
• Only works with some filters
• Can add extra code and slow down processing
– Pad the image
e
• Typically with either all white or all black pixels
e
– Replicate border pixels
– Truncate the image
e e e
– Allow pixels wrap around the image
y Image f (x, y) • Can cause some strange image artefacts

4
17 Strange Things Happen At The Edges! 18
of of Correlation & Convolution
19 (cont…) 19

The filtering we have been talking about so


Images taken from Gonzalez & Woods, Digital Image Processing (2002)

Filtered Image: far is referred to as correlation with the filter


Zero Padding
itself referred to as the correlation kernel
Convolution is a similar operation, with just
Original Filtered Image:
one subtle difference
Image Replicate Edge Pixels
a b c r s t eprocessed = v*e +
z*a + y*b + x*c +
d
f
e
g
e
h
* u
x
v
y
w
z
w*d + u*e +
Filtered Image: t*f + s*g + r*h
Wrap Around Edge Pixels Original Image Filter
Pixels

For symmetric filters it makes no difference

19 20
of
19
of
19
Summary
In this lecture we have looked at the idea of
spatial filtering and in particular:
– Neighbourhood operations
– The filtering process
– Smoothing filters
– Dealing with problems at image edges when
using filtering
– Correlation and convolution
Next time we will looking at sharpening
filters and more on filtering and image
enhancement

You might also like