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

2

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)

Course Website: http://www.comp.dit.ie/bmacnamee

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)

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
9 10
of
19
Smoothing Spatial Filtering of
19
Image Smoothing Example
Origin x
104 100 108 1/
9
1/
9
1/
9 The image at the top left

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

Image Smoothing Example


Image Smoothing Example

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

19
16
19
14

Image Smoothing Example


Image Smoothing Example
17 18
of
19
Weighted Smoothing Filters of
19
Another Smoothing Example
More effective smoothing filters can be By smoothing the original image we get rid

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)

Original Image Image After Image After


With Noise Averaging Filter Median Filter

Filtering is often used to remove noise from


images
Sometimes a median filter works better than
an averaging filter
21
of
Averaging Filter Vs. Median Filter 22
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)
23 Simple Neighbourhood Operations 24
of of Strange Things Happen At The Edges!
19 Example 19

At the edges of an image we are missing


x pixels to form a neighbourhood
123 127 128 119 115 130 Origin x
e e
140 145 148 153 167 172

133 154 183 192 194 191


e
194 199 207 210 198 195
e
164 170 175 162 173 151

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

– Replicate border pixels 164 170 175 162 173 151


– Truncate the image
y
– Allow pixels wrap around the image
• Can cause some strange image artefacts

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

Original Filtered Image:


Image Replicate Edge Pixels

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

You might also like