Digital Image Processing: Lecture # 7 Spatial Filtering
Digital Image Processing: Lecture # 7 Spatial Filtering
Lecture # 7
Spatial Filtering
1
Assignment-2
Sharpening Spatial Filters
A B
1st Derivative
ff
ff ((xx11)) ff ((xx))
xx
Its just the difference between subsequent
values and measures the rate of change of
the function
11ststDerivative
Derivative
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 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0
2 Derivative
nd
Simply takes into account the values both before and after the current value
ff
22
ff ((xx11)) ff ((xx11))22 ff ((xx))
xx
22
22ndndDerivative
Derivative
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
2nd Derivative for Image Enhancement
The
The2nd
2ndderivative
derivative isismore
moreuseful
usefulfor
for image
imageenhancement
enhancement
than
than the
the1st
1stderivative
derivative-- Stronger
Strongerresponse
response totofine
finedetail
detail
We
Wewill
willcome
comeback
backto
tothe
the1st
1st order
orderderivative
derivativelater
lateron
on
The
Thefirst
firstsharpening
sharpeningfilter
filter we
wewill
willlook
lookat
at isis the
the Laplacian
Laplacian
Laplacian Filter
The Laplacian is defined as follows:
f f 2 2
f 2 2
2
x y
2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x 2
2 f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y 2
Laplacian Filter
0 1 0
Laplacian Filter
Laplacian Filter
Applying the Laplacian to an image we get a
new image that highlights edges and other
discontinuities
The
The result
result of
of aaLaplacian
Laplacianfiltering
filtering isis not
not an
an
enhanced
enhancedimage
image
To
Togenerate
generatethe
thefinal
finalenhanced
enhancedimage
image
Laplacian
Filtered Image
Scaled for Display
f ( x, y ) f , w5 0
2
g ( x, y )
f ( x, y ) 2 f , w5 0
Laplacian Image Enhancement
- =
Original Laplacian Sharpened
Image Filtered Image Image
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 )]
Simplified Image Enhancement
• The entire enhancement can be combined
into a single filtering operation
g ( x, y ) f ( x , y ) f
2
5 f ( x, y ) f ( x 1, y ) f ( x 1, y )
0 -1 0
f ( x , y 1) f ( x , y 1)
-1 5 -1
0 -1 0
Simplified Image Enhancement
0 -1 0
-1 5 -1
0 -1 0
Order-Statistic Filtering
23
Median Filter
• For an image, mask symmetric: 3x3, 5x5, etc.
Sorted: 0,0,1,1,1,2,2,2,4
Input Output
1 2 0 1 3
2 2 4 2 2 1
1 0 1 0 1
1 2 1 0 2
2 5 3 1 2
24
Median Filtering
Sort
Sortthe
thevalues
values
Determine
Determinethe
themedian
median
Median = ? 20
Particularly
Particularly effective
effective when
when
The noise
The noise pattern
pattern consists
consists of
of strong
strong
impulsenoise
impulse noise((salt-and-pepper)
salt-and-pepper)
25
Salt and Pepper Noise
Median Filtering
27
Min/Max Filtering
Combining Spatial Enhancement
Methods
Successful image enhancement is
typically not achieved using a single
operation
32