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

IPPR Lecture 4

nn

Uploaded by

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

IPPR Lecture 4

nn

Uploaded by

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

Image Processing and Pattern

Recognition (IPPR):
(Lecture 4)

Sanjeeb Prasad Panday


[email protected]
2
of
43
Spatial Filtering
• Use of spatial masks for filtering is called spatial filtering
– May be linear or nonlinear
• Linear filters
– Lowpass: attenuate (or eliminate) high frequency components
such as characterized by edges and sharp details in an image
• Net effect is image blurring
– Highpass: attenuate (or eliminate) low frequency components
such as slowly varying characteristics
• Net effect is a sharpening of edges and other details
– Bandpass: attenuate (or eliminate) a given frequency range
• Used primarily for image restoration(are of little interest for
image enhancement)
3
of
43
Spatial Filtering
• Filters in the frequency domain and corresponding spatial filters
• Basic approach is to sum products between mask coefficients and
pixel values
– R=w1z1 +w2z2 +....+w9z9
4
of
Order-Statistic nonlinear
43
spatial filters
• Nonlinear spatial filters also operate on neighbourhoods
• Their operation is based directly on pixel values in the
neighbourhood under consideration
– They do not explicitly use coefficient values as in the linear spatial
filters
• Example nonlinear spatial filters
– Median filter: Computes the median gray-level value of the
neighborhood. Used for noise reduction.
– Max filter: Used to find the brightest points in an image
R=max{zk |k=1,2,...,9}
– Min filter: Used to find the dimmest points in an image
R=min{zk |k=1,2,...,9}
5
of
43
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)
6
of
43
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
7
of
Simple Neighbourhood Operations
43 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
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

The above is repeated for every pixel in the original


image to generate the filtered image
9
of
43
Spatial Filtering: Equation Form
a b
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

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
10
of
43
Smoothing Spatial Filters
• The shape of the impulse response needed to implement a lowpass
(smoothing) filter indicates the filter should have all positive coefficients
• For a 3x3 mask, the simplest arrangement is to have all the
coefficient values equal to one (neighborhood averaging)
– The response would be the sum of all gray levels for the nine
pixels in the mask
– This could cause the value of R to be out of the valid gray-level
range
• The solution is to scale the result by dividing by 9
11
of
43
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
1
/9 1
/9 1
/9
from images Simple
Also useful for
1
/ 9
1
/ 9
1
/9 averaging
highlighting gross filter
detail
1
/ 9
1
/ 9
1
/9
12
of
43
Smoothing Spatial Filtering
Origin x
104 100 108 1
/9 1
/9 1
/9

* /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

central pixel are more


important 2
/16 /16
4
/16
2

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 lots of the finer detail which leaves only


the gross features for thresholding

Original Image Smoothed Image Thresholded Image


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)

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

• Note the sum of the coefficients is zero


– When the mask is over a constant or slowly varying region the
output is zero or very small
• This filter eliminates the zero-frequency term
• Eliminating this term reduces the average gray-level value in
the image to zero (will reduce the global contrast of the image)
• Result will be a some what edge-enhanced image over a dark
background
• Reducing the average gray-level value to zero implies some
negative gray levels
– The output should be scaled back into an appropriate range
[0, L-1]
32
of
43
Sharpening Filters (High Pass)
33
of
43
Sharpening Filters (High-boost)
• A high-pass filter may be computed as:
High-pass = Original - Lowpass
• Multiplying the original by an amplification factor yields a high-boost
or high-frequency-emphasis filter
High-boost = A(Original) − Lowpass
= ( A − 1)(Original ) + Original − Lowpass
= ( A − 1)(Original ) + High-pass
– If A>1, part of the original image is added to the high-pass result
(partially restoring low frequency components)
– Result looks more like the original image with a relative degree of
edge enhancement that depends on the value of A
– May be implemented with the center coefficient value w=9A-1
(A≥1)
34
of
Sharpening Filters (High-boost ( gives edge with

43
))
background
35
of
Simple Neighbourhood Operations
43 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
36
of
43
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)
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

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
39
of
Strange Things Happen At The Edges!
43 (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
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

For symmetric filters it makes no difference

You might also like