0% found this document useful (0 votes)
64 views

Image Processing Spatial Filtering 1

The document discusses spatial filtering and neighborhood operations in digital image processing. It describes how neighborhood operations work on pixels surrounding a central pixel. Common neighborhood filters include minimum, maximum, and median filters. Smoothing is one of the simplest spatial filters, where pixel values are averaged across a neighborhood. Larger filter sizes produce more smoothing but less detail. Weighted averaging filters and median filters are also discussed as alternatives to simple averaging for noise removal. The document provides examples of filtering and its effects on edges and throughout an image.

Uploaded by

Matthew Wagner
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Image Processing Spatial Filtering 1

The document discusses spatial filtering and neighborhood operations in digital image processing. It describes how neighborhood operations work on pixels surrounding a central pixel. Common neighborhood filters include minimum, maximum, and median filters. Smoothing is one of the simplest spatial filters, where pixel values are averaged across a neighborhood. Larger filter sizes produce more smoothing but less detail. Weighted averaging filters and median filters are also discussed as alternatives to simple averaging for noise removal. The document provides examples of filtering and its effects on edges and throughout an image.

Uploaded by

Matthew Wagner
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 31

1

of
19
Digital Image Processing


Image Enhancement
(Spatial Filtering)
2
of
19
Neighbourhood Operations
Neighbourhood operations simply operate
on a larger neighbourhood of pixels than
point operations
Neighbourhoods are
mostly a rectangle
around a central pixel
Any size rectangle
and any shape filter
are possible
Origin x
y
I mage f (x, y)
(x, y)
Neighbourhood
3
of
19
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
4
of
19
Simple Neighbourhood Operations
Example
123 127 128 119 115 130
140 145 148 153 167 172
133 154 183 192 194 191
194 199 207 210 198 195
164 170 175 162 173 151
Original I mage
x
y
Enhanced I mage
x
y
5
of
19
The Spatial Filtering Process
r s t
u v w
x y z
Origin x
y
I mage f (x, y)
e
processed
= v*e +
r*a + s*b + t*c +
u*d + w*f +
x*g + y*h + z*i
Filter
Simple 3*3
Neighbourhood
e 3*3 Filter
a b c
d e f
g h i
Original Image
Pixels
*
The above is repeated for every pixel in the
original image to generate the filtered image
6
of
19
Spatial Filtering: Equation Form



a
a s
b
b t
t y s x f t s w y x g ) , ( ) , ( ) , (
Filtering can be given
in equation form as
shown above
Notations are based
on the image shown
to the left
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

7
of
19
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
in removing noise
from images
Also useful for
highlighting gross
detail
1
/
9

1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
Simple
averaging
filter
8
of
19
Smoothing Spatial Filtering
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
Origin x
y
I mage f (x, y)
e =
1
/
9
*106 +

1
/
9
*104 +
1
/
9
*100 +
1
/
9
*108 +

1
/
9
*99 +
1
/
9
*98 +

1
/
9
*95 +
1
/
9
*90 +
1
/
9
*85
= 98.3333
Filter
Simple 3*3
Neighbourhood
106
104
99
95
100 108
98
90 85
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
1
/
9
3*3 Smoothing
Filter
104 100 108
99 106 98
95 90 85
Original Image
Pixels
*
The above is repeated for every pixel in the
original image to generate the smoothed image
9
of
19
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
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

10
of
19
Image Smoothing Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

11
of
19
Image Smoothing Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

12
of
19
Image Smoothing Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

13
of
19
Image Smoothing Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

14
of
19
Image Smoothing Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

15
of
19
Image Smoothing Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

16
of
19
Weighted Smoothing Filters
More effective smoothing filters can be
generated by allowing different pixels in the
neighbourhood different weights in the
averaging function
Pixels closer to the
central pixel are more
important
Often referred to as a
weighted averaging
1
/
16

2
/
16
1
/
16
2
/
16
4
/
16
2
/
16
1
/
16
2
/
16
1
/
16
Weighted
averaging filter
17
of
19
Another Smoothing Example
By smoothing the original image we get rid
of lots of the finer detail which leaves only
the gross features for thresholding
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

Original Image Smoothed Image Thresholded Image
18
of
19
Averaging Filter Vs. Median Filter
Example
Filtering is often used to remove noise from
images
Sometimes a median filter works better than
an averaging filter
Original Image
With Noise
Image After
Averaging Filter
Image After
Median Filter
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

19
of
19
Averaging Filter Vs. Median Filter
Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

20
of
19
Averaging Filter Vs. Median Filter
Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

21
of
19
Averaging Filter Vs. Median Filter
Example
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

22
of
19
Simple Neighbourhood Operations
Example
123 127 128 119 115 130
140 145 148 153 167 172
133 154 183 192 194 191
194 199 207 210 198 195
164 170 175 162 173 151
x
y
23
of
19
Strange Things Happen At The Edges!
Origin x
y
I mage f (x, y)
e
e
e
e
At the edges of an image we are missing
pixels to form a neighbourhood
e e
e
24
of
19
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
Truncate the image
Allow pixels wrap around the image
Can cause some strange image artefacts
25
of
19
Simple Neighbourhood Operations
Example
123 127 128 119 115 130
140 145 148 153 167 172
133 154 183 192 194 191
194 199 207 210 198 195
164 170 175 162 173 151
x
y
26
of
19
Strange Things Happen At The Edges!
(cont)
Original
Image
Filtered Image:
Zero Padding
Filtered Image:
Replicate Edge Pixels
Filtered Image:
Wrap Around Edge Pixels
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

27
of
19
Strange Things Happen At The Edges!
(cont)
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

28
of
19
Strange Things Happen At The Edges!
(cont)
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

29
of
19
Strange Things Happen At The Edges!
(cont)
I
m
a
g
e
s

t
a
k
e
n

f
r
o
m

G
o
n
z
a
l
e
z

&

W
o
o
d
s
,

D
i
g
i
t
a
l

I
m
a
g
e

P
r
o
c
e
s
s
i
n
g

(
2
0
0
2
)

30
of
19
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




For symmetric filters it makes no difference
e
processed
= v*e +
z*a + y*b + x*c +
w*d + u*e +
t*f + s*g + r*h
r s t
u v w
x y z
Filter
a b c
d e e
f g h
Original Image
Pixels
*
31
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