Professional Documents
Culture Documents
Digital Image Processing: Lecture # 6 Spatial Filtering
Digital Image Processing: Lecture # 6 Spatial Filtering
Lecture # 6
Spatial Filtering
1
Spatial Filtering
Original image
Smooth by 3x3
Size: 500x500 box filter
Smooth by
Smooth by
35x35 box filter
15x15 box filter
Noticehow
Notice howdetail
detailbegins
beginsto
todisappear
disappear
3
Smoothing Spatial Filters
Consider
Considerthe
the
output
outputpixel
pixelis
is
positioned
positionedatat
the
thecenter
center
4
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
Unsharp Masking
Use of first derivatives for image
enhancement: The Gradient
f
Gx x
f f
G y
y
Gradient Operators
• Most common differentiation operator is the
gradient vector.
f ( x, y )
x G x
f ( x, y )
f ( x , y ) G y
y
Magnitude: 2
f ( x, y ) G x G y
2 1/ 2
Gx Gx
Direction:
Gy
1
f ( x, y ) tan
Gx
27
Gradient Operators
Sobel
SobelOperator
Operator
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
Extract horizontal edges Extract vertical edges
f ( z7 2 z8 z9 ) ( z1 2 z2 z3 )
( z3 2 z6 z9 ) ( z1 2 z4 z7 )
Emphasize more the current point (x
direction) Pixel Arrangement
Sobel Operator: Example
An image of a
contact lens
which is
enhanced in
order to make
defects more
obvious
30
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
31
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)
32
Salt and Pepper Noise
Median Filtering
34
Min/Max Filtering
Combining Spatial Enhancement
Methods
Successful image enhancement is
typically not achieved using a single
operation
2002
Peters, Richard Alan, II, Lectures on Image Processing, Vanderbilt University, Nashville,
TN, April 2008
Brian Mac Namee, Digitial Image Processing, School of Computing, Dublin Institute of
Technology
Computer Vision for Computer Graphics, Mark Borg
39