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

Image Enhancement-Spatial Filtering From: Digital Image Processing, Chapter 3

The document discusses spatial filtering techniques for image enhancement, specifically smoothing spatial filters. Smoothing filters average pixel values in a neighborhood to reduce noise. A simple averaging filter replaces the center pixel value with the average of pixel values in a 3x3 neighborhood. The smoothing effect increases with larger filter sizes, causing more image detail to disappear. Spatial filtering can be described mathematically by convolving neighborhood pixel values with a filter kernel.

Uploaded by

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

Image Enhancement-Spatial Filtering From: Digital Image Processing, Chapter 3

The document discusses spatial filtering techniques for image enhancement, specifically smoothing spatial filters. Smoothing filters average pixel values in a neighborhood to reduce noise. A simple averaging filter replaces the center pixel value with the average of pixel values in a 3x3 neighborhood. The smoothing effect increases with larger filter sizes, causing more image detail to disappear. Spatial filtering can be described mathematically by convolving neighborhood pixel values with a filter kernel.

Uploaded by

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

1

of
19

Digital Image Processing

Image Enhancement-
Spatial Filtering
From:
Digital Image Processing, Chapter 3
Refael C. Gonzalez & Richard E. Woods
2
of
19
Contents
Next, we will look at spatial filtering
techniques:

What is spatial filtering?


Smoothing Spatial filters.
Sharpening Spatial Filters.
Combining Spatial Enhancement Methods
3
of
19
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)
4
of
19
Neighbourhood Operations
For each pixel in the origin image, the
outcome is written on the same location at
the target image.
Origin
Origin x Target

(x, y)
Neighbourhood

y Image f (x, y)
5
of
19
Simple Neighbourhood Operations
Simple neighbourhood operations example:

Min: Set the pixel value to the minimum in


the neighbourhood

Max: Set the pixel value to the maximum in


the neighbourhood
6
of
19
The Spatial Filtering Process
Origin x
a b c j k l
d
g
e
h
f
i
* m
p
n
q
o
r
Original Image Filter (w)
Simple 3*3 Pixels
e 3*3 Filter
Neighbourhood
eprocessed = n*e +
j*a + k*b + l*c +
m*d + o*f +
y Image f (x, y) p*g + q*h + r*i

The above is repeated for every pixel in the


original image to generate the filtered image
7
of
19
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
8
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 1
/9 1
/9 1
/9
in removing noise
from images Simple
1
/9 1
/9 1
/9 averaging
Also useful for
highlighting gross filter
1
/9 1
/9 1
/9
detail
9
of
19
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
10
of
19
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
19
11
Image Smoothing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

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

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

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

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

of
19
16
Image Smoothing Example
17
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
1
/16 /16
2
/16
1

central pixel are more


important
2
/16 /16
4
/16
2

Often referred to as a 1
/16 /16
2
/16
1
weighted averaging
Weighted
averaging filter
18
of
19
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

* Image taken from Hubble Space Telescope


19
of
Averaging Filter Vs. Median Filter
19 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
19
20

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

of
19
21

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

of
19
22

Filter
Median
Averaging Filter Vs. Median Filter
Example
23
of
19
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)
24
of
Strange Things Happen At The Edges!
19 (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
25
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
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


26
of
19
Sharpening Spatial Filters
Previously we have looked at smoothing
filters which remove fine detail
Sharpening spatial filters seek to highlight
fine detail
Remove blurring from images
Highlight edges
Sharpening filters are based on spatial
differentiation
27
of
19
Spatial Differentiation
Differentiation measures the rate of change of
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

a function
Lets consider a simple 1 dimensional
example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
19
28

A
B
Spatial Differentiation
29
of
19
1st Derivative
The formula for the 1st derivative of a
function is as follows:
f
f ( x 1) f ( x)
x
Its just the difference between subsequent
values and measures the rate of change of
the function
30
of
19
1st Derivative (cont)

f(x)

5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
0 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0

f(x)
31
of
19
2nd Derivative
The formula for the 2nd derivative of a
function is as follows:
f
2
f ( x 1) f ( x 1) 2 f ( x)
x
2

Simply takes into account the values both


before and after the current value
32
of
19
2nd Derivative (cont)

f(x)

5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
-1 0 0 0 0 1 0 6 -12 6 0 0 1 1 -4 1 1 0 0 7 -7 0 0

f(x)
33
of
19
1st and 2nd Derivative

f(x)

f(x)

f(x)
34
of
Using Second Derivatives For Image
19 Enhancement
The 2nd derivative is more useful for image
enhancement than the 1st derivative
Stronger response to fine detail
Simpler implementation
We will come back to the 1st order derivative
later on
The first sharpening filter we will look at is
the Laplacian
Isotropic
One of the simplest sharpening filters
We will look at a digital implementation
35
of
19
The Laplacian
The Laplacian is defined as follows:
f f
2 2
f 2 2
2

x y
where the partial 1st order derivative in the x
direction is defined as follows:
f
2
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x
2

and in the y direction as follows:


f
2
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y
2
36
of
19
The Laplacian (cont)
So, the Laplacian can be given as follows:
f [ f ( x 1, y ) f ( x 1, y )
2

f ( x, y 1) f ( x, y 1)]
4 f ( x, y )
We can easily build a filter based on this
0 1 0

1 -4 1

0 1 0
37
of
19
The Laplacian (cont)
Applying the Laplacian to an image we get a
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

new image that highlights edges and other


discontinuities

Original Laplacian Laplacian


Image Filtered Image Filtered Image
Scaled for Display
38
of
19
But That Is Not Very Enhanced!
The result of a Laplacian filtering
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

is not an enhanced image


We have to do more work in
order to get our final image
Subtract the Laplacian result
Laplacian
from the original image to Filtered Image
Scaled for Display
generate our final sharpened
enhanced image
g ( x, y ) f ( x, y ) f
2
39
of
19
Laplacian Image Enhancement
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

- =
Original Laplacian Sharpened
Image Filtered Image Image

In the final sharpened image edges and fine


detail are much more obvious
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

of
19
40
Laplacian Image Enhancement
41
of
19
Simplified Image Enhancement
The entire enhancement can be combined
into a single filtering operation
g ( x, y ) f ( x, y ) f
2

f ( x, y ) [ f ( x 1, y ) f ( x 1, y )
f ( x, y 1) f ( x, y 1)
4 f ( x, y )]
5 f ( x, y ) f ( x 1, y ) f ( x 1, y )
f ( x, y 1) f ( x, y 1)
42
of
19
Simplified Image Enhancement (cont)

This gives us a new filter which does the


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

whole job for us in one step

0 -1 0

-1 5 -1

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

of
19
43
Simplified Image Enhancement (cont)
44
of
19
Variants On The Simple Laplacian
There are lots of slightly different versions of
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

the Laplacian that can be used:


0 1 0 1 1 1
Simple Variant of
1 -4 1 1 -8 1
Laplacian Laplacian
0 1 0 1 1 1

-1 -1 -1

-1 9 -1

-1 -1 -1
45
of
19
Unsharp Mask & Highboost Filtering
Using sequence of linear spatial filters in
order to get Sharpening effect.

-Blur
- Subtract from original image
- add resulting mask to original image
46
of
19
Highboost Filtering
47
of
19
1st Derivative Filtering
Implementing 1st derivative filters is difficult in
practice
For a function f(x, y) the gradient of f at
coordinates (x, y) is given as the column
vector:
f
Gx x
f f
Gy
y
48
of
19
1st Derivative Filtering (cont)
The magnitude of this vector is given by:
f mag (f )

G G 2
x
2
y 1
2

1
f 2
f
2 2


x y

For practical reasons this can be simplified as:


f G x G y
49
of
19
1st Derivative Filtering (cont)
There is some debate as to how best to
calculate these gradients but we will use:
f z7 2 z8 z9 z1 2 z 2 z3
z3 2 z6 z9 z1 2 z 4 z7
which is based on these coordinates
z1 z2 z3

z4 z5 z6

z7 z8 z9
50
of
19
Sobel Operators
Based on the previous equations we can
derive the Sobel Operators
-1 -2 -1 -1 0 1

0 0 0 -2 0 2

1 2 1 -1 0 1

To filter an image it is filtered using both


operators the results of which are added
together
51
of
19
Sobel Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

An image of a
contact lens which
is enhanced in
order to make
defects (at four
and five oclock in
the image) more
obvious

Sobel filters are typically used for edge


detection
52
of
19
1st & 2nd Derivatives
Comparing the 1st and 2nd derivatives we
can conclude the following:
1st order derivatives generally produce thicker
edges
2nd order derivatives have a stronger
response to fine detail e.g. thin lines
1st order derivatives have stronger response
to grey level step
2nd order derivatives produce a double
response at step changes in grey level
53
of
Combining Spatial Enhancement
19 Methods
Successful image
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

enhancement is typically
not achieved using a single
operation
Rather we combine a range
of techniques in order to
achieve a final result
This example will focus on
enhancing the bone scan to
the right
54
of
Combining Spatial Enhancement
19 Methods (cont)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

(a)
Laplacian filter of
bone scan (a)
(b)
Sharpened version of
bone scan achieved (c)
by subtracting (a)
and (b) Sobel filter of bone
scan (a) (d)
55
of
Combining Spatial Enhancement
19 Methods (cont)
Result of applying a (h)
power-law trans. to
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

Sharpened image (g)


which is sum of (a)
and (f) (g)
The product of (c)
and (e) which will be (f)
used as a mask
(e)

Image (d) smoothed with


a 5*5 averaging filter
56
of
Combining Spatial Enhancement
19 Methods (cont)
Compare the original and final images
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

You might also like