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

ImageProcessing5 SpatialFiltering1

This document discusses digital image processing techniques called spatial filtering. Spatial filtering involves applying filters to neighborhoods of pixels rather than individual pixels. Common spatial filters include smoothing filters, which average pixel values over an area, and sharpening filters. The key aspects covered are: 1) Spatial filtering operates on neighborhoods of pixels rather than individual pixels. This allows operations like blurring and sharpening that single pixel operations cannot perform. 2) Common filter parameters include size, shape, weights, and function. Smoothing filters simply average pixel values in a neighborhood. 3) The spatial filtering process applies a filter to each pixel neighborhood in an image to generate a filtered output image.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

ImageProcessing5 SpatialFiltering1

This document discusses digital image processing techniques called spatial filtering. Spatial filtering involves applying filters to neighborhoods of pixels rather than individual pixels. Common spatial filters include smoothing filters, which average pixel values over an area, and sharpening filters. The key aspects covered are: 1) Spatial filtering operates on neighborhoods of pixels rather than individual pixels. This allows operations like blurring and sharpening that single pixel operations cannot perform. 2) Common filter parameters include size, shape, weights, and function. Smoothing filters simply average pixel values in a neighborhood. 3) The spatial filtering process applies a filter to each pixel neighborhood in an image to generate a filtered output image.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 45

Digital Image Processing

Image Enhancement
(Spatial Filtering 1)

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


2
of
45
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
3
of
45
What is a Filter?
• Capabilities of point operations are limited
• Filters: combine pixel’s value + values of neighbours
• E.g. blurring: Compute average intensity of block of
pixels

• Combining multiple pixels needed for certain operations:


- Blurring, Smoothing
- Sharpening
4
of
45
What Point Operations Can’t Do

• Example: sharpening
5
of
45
What Point Operations Can’t Do

• Other cool artistic patterns by combining pixels


6
of
45
Neighbourhood Operations
- Neighbourhood operations simply operate
on a larger neighbourhood of pixels than
point operations, Origin x

- Neighbourhoods are
mostly a rectangle
(x, y)
around a central pixel. Neighbourhood

y Image f (x, y)
7
of
45
Filter Parameters
 Many possible filter parameters (size,
weights, function, etc)
• Filter size (size of neighbourhood):
3x3, 5x5, 7x7, …,21x21,..
• Filter shape: not necessarily square. Can be
rectangle, circle, etc
• Filter weights: May apply unequal weighting
to different pixels
• Filters function: can be linear (a weighted
summation) or nonlinear
8
of
45
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
9
of
Simple Neighbourhood Operations
45 Example

Original Image x Enhanced Image x


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

y y
10
of
45
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
11
of
45
Spatial Filtering: Equation Form
a b

  w(s, t ) f ( x  s, y  t )
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

g ( x, y ) 
s   at   b

Filtering can be given


in equation form as
shown above
Notations are based
on the image shown
to the left
12
of
45
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
13
of
45
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/ 1/ 1/
3*3 Smoothing Pixels
999 106
9 989
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
14
of
45
Image Smoothing Example
The image at the top left
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

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
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
15
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
16
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
17
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
18
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
19
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
20
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
21
Image Smoothing Example
22
of
45
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
23
of
45
Another Smoothing Example
By smoothing the original image we get rid
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 Smoothed Image Thresholded Image


24
of
45
The Filter Matrix
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

Filter operation can be


expressed as a matrix
Example: averaging filter

Filter matrix also


called
filter mask H(i,j)
25
of
45
Example: What does this Filter Do?
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

Identity function ( leaves image alone)


26
of
45
Example: What does this Filter Do?
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

Mean (averages neighbourhood)


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

of
45
27
Mean Filters: Effect of Filter Size
28
of
Averaging Filter Vs. Median Filter
45 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
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
29

Example
Averaging Filter Vs. Median Filter
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
30

Example
Averaging Filter Vs. Median Filter
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
31

Example
Averaging Filter Vs. Median Filter
32
of
Simple Neighbourhood Operations
45 Example

x
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

y
33
of
45
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)
34
of
Strange Things Happen At The Edges!
45 (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 (Extend)
– Truncate the image (crop)
– Allow pixels wrap around the image
• Can cause some strange image artefacts
35
of
45
What to do at image boundaries?

Crop
36
of
45
What to do at image boundaries?

Pad
37
of
45
What to do at image boundaries?

Extend
38
of
45
What to do at image boundaries?

Wrap
39
of
Simple Neighbourhood Operations
45 Example

x
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

y
40
of
Strange Things Happen At The Edges!
45 (cont…)
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
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
41
Strange Things Happen At The Edges!
(cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
42
Strange Things Happen At The Edges!
(cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
45
43
Strange Things Happen At The Edges!
(cont…)
44
of
45
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


45
of
45
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