Digital Image Processing
IMAGE ENHANCEMENT
(SPATIAL FILTERING 2)
Contents
In this lecture we will look at more spatial filtering
techniques
Spatial filtering refresher
Sharpening filters
1st derivative filters
2nd derivative filters
Combining filtering techniques
Spatial Filtering Refresher
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 smoothed image
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
Spatial Differentiation
Differentiation measures the rate of change of a
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
function
Let’s consider a simple 1 dimensional example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
A
B
Spatial Differentiation
1st Derivative
The formula for the 1st derivative of a function is as
follows:
f
f ( x 1) f ( x)
x
It’s just the difference between subsequent values and
measures the rate of change of the function
1st Derivative (cont…)
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
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
2nd Derivative (cont…)
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
Using Second Derivatives For Image 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
The Laplacian
The Laplacian is defined as follows:
f f2 2
f 2 2
2
x y
where the partial 1 order derivative in the x
st
direction is defined as follows:
f
2
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x2
and in2 the y direction as follows:
f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y
2
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
The Laplacian (cont…)
Applying the Laplacian to an image we get a new
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
image that highlights edges and other discontinuities
Original Laplacian Laplacian
Image Filtered Image Filtered Image
Scaled for Display
But That Is Not Very Enhanced!
The result of a Laplacian filtering is not
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
an enhanced image
We have to do more work in order to
get our final image
Subtract the Laplacian result from the
original image to generate our final
Laplacian
sharpened enhanced image Filtered Image
Scaled for Display
g ( x, y ) f ( x, y ) f
2
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)
Laplacian Image Enhancement
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)
Simplified Image Enhancement (cont…)
This gives us a new filter which does the whole job for
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
us in one step
0 -1 0
-1 5 -1
0 -1 0
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Simplified Image Enhancement (cont…)
Variants On The Simple Laplacian
There are lots of slightly different versions of the
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
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
Simple Convolution Tool In Java
A great tool for testing out different filters
From the book “Image Processing tools in Java”
Available from webCT later on today
To launch: java ConvolutionTool Moon.jpg
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
Summary
In this lecture we looked at:
Sharpening filters
1st derivative filters
2nd derivative filters
Combining filtering techniques
Combining Spatial Enhancement
Methods
Successful image enhancement is
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
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
Combining Spatial Enhancement
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)
Combining Spatial Enhancement
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
Combining Spatial Enhancement
Methods (cont…)
Compare the original and final images
Images taken from Gonzalez & Woods, Digital Image Processing (2002)