Spatial Filtering
Part 2
Sharpening filters
The principal objective of sharpening is
◦ to highlight fine detail in an image or
◦ to enhance detail that has been blurred, either in er
ror or as a natural effect of a particular method of i
mage acquisition
Sharpening Spatial Filters
An Example
1st Derivative
The formula for the 1st derivative of a fu
nction is as follows:
f
f ( x 1) f ( x)
x
It’s just the difference between subsequ
ent values and measures the rate of cha
nge of the function
1 Derivative
st
Image Strip
8
7
6
5
4
3
2
1
0
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
1st Derivative
8
6
4
2
0
-2
-4
-6
-8
2nd Derivative
The formula for the 2nd derivative of a fu
nction is as follows:
f
2
f ( x 1) f ( x 1) 2 f ( x)
x
2
Simply takes into account the values bot
h before and after the current value
Analyze
The 2nd derivative is more useful for i
mage enhancement than the 1st deriva
tive
◦ Stronger response to fine detail
◦ Simpler implementation
The Laplacian (2nd order derivativ
e)
Shown by Rosenfeld and Kak[1982] that the s
implest isotropic derivative operator is the Lap
lacian is defined as
f f
2 2
f 2 2
2
x y
where the partial 1st order derivative in the x direction is
defined as follows:
2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x
2
and in the y direction as follows:
Discrete form of derivative
f(x-1,y) f(x,y) f(x+1,y) 2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x 2
f(x,y-1)
f(x,y) 2 f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y 2
f(x,y+1)
2-Dimentional Laplacian
The digital implementation of the 2-Dimensional L
aplacian is obtained by summing 2 components
2
f 2
f
2 f 2 2
x x
2 f f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1) 4 f ( x, y )
1
1 -4 1
1
Use of Second Derivatives for Enhancement
The Laplacian
Use of Second Derivatives for Enhancement
The Laplacian
>> a=imread('moon_lap.jpg'); >> w=fspecial('laplacian',0)
>>f=rgb2gray(a); >> g1=imfilter(f,w,'replicate');
>> imshow(f) >> figure,imshow(g1)
Use of Second Derivatives for Enhancement
The Laplacian
Image f Image g2
>>g2=f-g1
>> imshow(g2)
Using Second Derivatives For Image
Enhancement
The 2nd derivative is more useful for ima
ge enhancement than the 1st derivative
◦ Stronger response to fine detail
◦ Simpler implementation
But That Is Not Very Enhance
d!
The result of a Laplacian filtering
is not an enhanced image
We have to do more work in ord
er to get our final image
Subtract the Laplacian result fro
m the original image to generate Laplacian
Filtered Image
our final sharpened enhanced im Scaled for Display
age
g ( x , y ) f ( x, y ) f
2
Simplified Image Enhancemen
t
The entire enhancement can be combin
ed 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 (con
t…)
This gives us a new filter which does the
whole job for us in one step
0 -1 0
-1 5 -1
0 -1 0
Simplified Image Enhancement (con
t…)
1st Derivative Filtering
There is some debate as to how best to calcula
te these gradients but we will use:
fz
72
z
8
z
9z
2
1z
2
z
3
z
32
z
6
z
9z
12
z
4
z
7
which is based on these coordinates
z1 z2 z3
z4 z5 z6
z7 z8 z9
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 opera
tors the results of which are added together
Sobel Example An image of a
contact lens
which is
enhanced in
order to make
defects (at four
and five o’clock
in the image)
more obvious
Sobel filters are typically used for edge detect
ion
1st & 2nd Derivatives
Comparing the 1st and 2nd derivatives we
can conclude the following:
◦ 1st order derivatives generally produce thic
ker edges
◦ 2nd order derivatives have a stronger resp
onse to fine detail e.g. thin lines
◦ 1st order derivatives have stronger respon
se to grey level step
◦ 2nd order derivatives produce a double res
ponse at step changes in grey level
Combining Spatial Enhancement Met
hods
Successful image enhancem
ent is typically not achieved
using a single operation
Rather we combine a range
of techniques in order to ac
hieve a final result
This example will focus on e
nhancing the bone scan to t
he right
Combining Spatial Enhancement Methods (
cont…)
(a)
Laplacian filter
of bone scan (a) (b)
Sharpened
version of bone (c)
scan achieved by
subtracting (a) Sobel filter of
bone scan (a) (d)
and (b)
Combining Spatial Enhancement Met
hods (cont…) Result of
(h)
applying a
Sharpened power-law trans.
image which is to (g)
The product of sum of (a) and (g)
(c) and (e) which (f) (f)
will be used as a
mask (e)
Image (d) smoothed
Combining Spatial Enhancement Met
hods (cont…)
Compare the original and final images