IPPR Lecture 4
IPPR Lecture 4
Recognition (IPPR):
(Lecture 4)
Neighbourhoods are
mostly a rectangle
around a central pixel
(x, y)
Any size rectangle Neighbourhood
y y
8
of
43
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
g ( x, y ) w( s, t ) f ( x s, y t )
s at b
* /9 /9 /9
1 1 1
99 106 98
95 90 85 1
/9 1
/9 1
/9
1
/9 100
104 1
/9 108
1
/9 Original Image Filter
Simple 3*3 /9 106
1
99 1
/9 198
/9
3*3 Smoothing Pixels
Neighbourhood /9 190
1
95 /9 185
/9 Filter
e = 1/9*106 +
1
/9*104 + 1/9*100 + 1/9*108 +
1
/9*99 + 1/9*98 +
y Image f (x, y) 1
/9*95 + 1/9*90 + 1/9*85
= 98.3333
The above is repeated for every pixel in the original
image to generate the smoothed image
13
of
43
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
43
14
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
15
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
16
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
17
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
18
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
19
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
20
Image Smoothing Example
21
of
43
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 1
/16 /16
2
/16
1
Often referred to as a
weighted averaging
1
/16 /16
2
/16
1
Weighted
averaging filter
22
of
43
Another Smoothing Example
By smoothing the original image we get rid
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
23
Another Smoothing Example
24
of
43
Smoothing Filters
• One problem with the lowpass filter is it blurs edges and other sharp
details
• If the intent is to achieve noise reduction, one approach can be to
use median filtering
– The value of each pixel is replaced by the median pixel value in
the neighborhood (as opposed to the average)
– Particularly effective when the noise consists of strong, spike like
components and edge sharpness is to be preserved
• The median m of a set of values is such that half of the values are
greater than m and half are less than m
• To implement, sort the pixel values in the neighborhood, choose the
median and assign this value to the pixel of interest
• Forces pixels with distinct intensities to be more like their neighbors
25
of
Averaging Filter Vs. Median Filter
43 Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
26
Averaging Filter Vs. Median Filter
Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
27
Averaging Filter Vs. Median Filter
Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
28
Averaging Filter Vs. Median Filter
Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
29
Averaging Filter Vs. Median Filter
Example
30
of
43
Sharpening Filters (High Pass)
• The shape of the impulse response needed to implement a
high-pass (sharpening) filter indicates the filter should have
positive coefficients near its center and negative coefficients in
the outer periphery
• For a 3x3 mask, the simplest arrangement is to have the
center coefficient positive and all others negative
31
of
43
Sharpening Filters (High Pass ( ))
gives only edge
43
))
background
35
of
Simple Neighbourhood Operations
43 Example
x
123 127 128 119 115 130
y
36
of
43
Strange Things Happen At The Edges!
e e e
y Image f (x, y)
37
of
Strange Things Happen At The Edges!
43 (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
38
of
Simple Neighbourhood Operations
43 Example
x
123 127 128 119 115 130
y
39
of
Strange Things Happen At The Edges!
43 (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Filtered Image:
Zero Padding
Filtered Image:
Wrap Around Edge Pixels
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
40
Strange Things Happen At The Edges!
(cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
41
Strange Things Happen At The Edges!
(cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
43
42
Strange Things Happen At The Edges!
(cont…)
43
of
43
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 +
d
f
e
g h
e
* u
x
v
y
w
z
z*a + y*b + x*c +
w*d + u*e +
t*f + s*g + r*h
Original Image Filter
Pixels