0% found this document useful (0 votes)
0 views19 pages

Chapter 4 Image - Spatial_Filtering

This document discusses spatial filtering techniques in digital image processing, focusing on neighbourhood operations, smoothing operations, and the effects of filtering at image edges. It covers methods such as correlation and convolution, as well as sharpening and combining filters. The document also highlights the importance of median filters for noise reduction and the challenges of processing edge pixels in images.

Uploaded by

alaaynassar7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views19 pages

Chapter 4 Image - Spatial_Filtering

This document discusses spatial filtering techniques in digital image processing, focusing on neighbourhood operations, smoothing operations, and the effects of filtering at image edges. It covers methods such as correlation and convolution, as well as sharpening and combining filters. The document also highlights the importance of median filters for noise reduction and the challenges of processing edge pixels in images.

Uploaded by

alaaynassar7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Digital Image Processing

Ch4. Spatial Filtering

Dr. Sondos Fadl


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
– Sharpening filters
– Combining filtering techniques
Neighbourhood Operations
Neighbourhood operations simply operate
on a larger neighbourhood of pixels than
point operations Origin x

Neighbourhoods are
mostly a rectangle
around a central pixel
(x, y)
Any size rectangle Neighbourhood

and any shape filter


are possible
y Image f (x, y)
Simple Neighbourhood Operations
Some simple neighbourhood operations
include:
– Min: Set the pixel value to the minimum in
the neighbourhood
– Max: Set the pixel value to the maximum in
the neighbourhood
– Median: The median value of a set of
numbers is the midpoint value in that set (e.g.
from the set [1, 7, 15, 18, 24] 15 is the
median). Sometimes the median works better
than the average
Simple Neighbourhood Operations
Example

Original Image x Enhanced Image x


123 127 128 119 115 130

140 145 148 153 167 172 123 119 115

133 154 183 192 194 191

194 199 207 210 198 195

164 170 175 162 173 151

y y
The Spatial Filtering Process
Origin x
a b c r s t
d
g
e
h
f
i
* u
x
v
y
w
z
Original Image Filter
Simple 3*3 Pixels
e 3*3 Filter
Neighbourhood
eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y Image f (x, y) x*g + y*h + z*i
The above is repeated for every pixel in the
original image to generate the filtered image
Spatial Filtering: Equation Form
a b
g ( x, y ) = ∑ ∑ w(s, t ) f ( x + s, y + t )
s = − at = − b

Filtering can be given


in equation form as
shown above
Notations are based
on the image shown
to the left
Smoothing Spatial Filters
One of the simplest spatial filtering
operations we can perform is a smoothing
operation
– Simply average all of the pixels in a
neighbourhood around a central value
– Especially useful
1/ 1/ 1/
in removing noise 9 9 9
from images Simple
1/ 1/ 1/
– Also useful for 9 9 9 averaging
highlighting gross filter
1/ 1/ 1/
detail 9 9 9
Smoothing Spatial Filtering
Origin x
104 100 108 1/ 1/ 1/
9 9 9

99 106 98

95 90 85
* 1/

1/
9
1/

1/
9
1/

1/
9

9 9 9

1/ 100
104
9
1/ 108
9
1/
9
Original Image Filter
Simple 3*3 1/
99 1/ 1/
3*3 Smoothing Pixels
9 98
9 106 9
Neighbourhood 195
/9 190
/9 185
/9
Filter
e = 1/9*106 +
1/ *104 + 1/ *100 + 1/ *108 +
9 9 9
1/ *99 + 1/ *98 +
9 9
y Image f (x, y) 1/ *95 + 1/ *90 + 1/ *85
9 9 9
= 98.3333
The above is repeated for every pixel in the original image to
generate the smoothed image.
Image Smoothing Example
The image at the top left
is an original image of
size 500*500 pixels
The subsequent images
show the image after
filtering with an averaging
filter of increasing sizes
– 3, 5, 9, 15 and 35
Notice how detail begins
to disappear
Weighted Smoothing Filters
More effective smoothing filters can be
generated by allowing different pixels in the
neighbourhood different weights in the
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

Weighted
averaging filter
Averaging Filter Vs. Median Filter
Example
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
Spatial smoothing and image
approximation
Spatial smoothing may be viewed as a
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

process for estimating the value of a pixel


from its neighbours.

What is the value that “best” approximates


the intensity of a given pixel given the
intensities of its neighbours?

We have to define “best” by establishing a


criterion.
Spatial smoothing and image
approximation (cont...)
– The median filter is non linear:
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

median{x + y} ≠ median{x} + median{ y}


– It works well for impulse noise (e.g. salt and
pepper).
– It requires sorting of the image values.
– It preserves the edges better than an average
filter in the case of impulse noise.
– It is robust to impulse noise at 50%.
Spatial smoothing and image
approximation (cont...)
Example x[n] 1 1 1 1 1 2 2 2 2 2
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

edge
Impulse
x[n] 1 3 1 1 1 2 3 2 2 3
noise

Median
(N=3) x[n] - 1 1 1 1 2 2 2 2 -

Average x[n] - 1.7 1.7 1 1.3 2 2.3 2.3 2.2 -


(N=3)
The edge is smoothed
Strange Things Happen At The Edges!

At the edges of an image we are missing


pixels to form a neighbourhood
Origin x
e e

e e e
y Image f (x, y)
Strange Things Happen At The Edges!
(cont…)
There are a few approaches to dealing with
missing edge pixels:
– Omit missing pixels
• Only works with some filters
• Can add extra code and slow down processing
– Pad the image
• Typically with either all white or all black pixels
– Replicate border pixels
Strange Things Happen At The Edges!
(cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

Filtered Image:
Zero Padding

Original
Image

Filtered Image:
Replicate Edge Pixels
Correlation & Convolution
The filtering we have been talking about so
far is referred to as correlation with the filter
itself referred to as the correlation kernel
Convolution is a similar operation, with just
one subtle difference
a b c r s t eprocessed = v*e +
z*a + y*b + x*c +
d
f
e
g h
e
* u
x
v
y
w
z
w*d + u*e +
t*f + s*g + r*h
Original Image Filter
Pixels

For symmetric filters it makes no difference.

You might also like