Lect 6
Lect 6
Lect 6
• Spatial filtering
• Linear filters
–Image Smoothing
–Image sharpening
Fundamentals of Spatial Filtering
• A neighborhood
• An operator with the same size: linear/nonlinear
Linear spatial
a b
filtering:
g ( x, y ) = w(s, t ) f ( x + s, y + t )
s = − at = − b
Inner product g ( x, y) = w • f = w f
T
Fundamentals of Spatial Filtering
11 9 1
N(p)
g(p):
• Linear function
• Correlation
• Convolution
• Nonlinear function
• Order statistic (median)
Linear Filtering
0 0 0
* 0 1 0 =
0 0 0
Spatial Correlation: 1D Signal
w(s) f ( x + s)
1D correlation
s =− a
2𝑎 2𝑎
Zero-padding: add zeros on the
left and right margin, respectively
Discrete impulse
Flipped
a
w(s) f ( x + s)
1D correlation
s =− a
a
1D convolution w(s) f ( x − s)
s =− a
a b
w(s, t ) f ( x + s, y + t )
s = − at = − b
a b
w(s, t ) f ( x − s, y − t )
s = − at = − b
Weighted average
a b
w(s, t ) f ( x + s, y + t )
• Noise deduction
• reduction of “irrelevant details”
g ( x, y ) = s = − at = − b
a b
• edge blurred
w(s, t )
s = − at = − b
Normalization factor
Smoothing Spatial Filter
1 1 1
1 =
* 1 1 1
9
1 1 1
Smoothing Spatial Filter
x2 + y2
1 −
2D Gaussian filter h ( x, y ) = e 2 2
2 2
* =
Comparison using Different Smoothing
Filters – Different Kernels
Average Gaussian
Comparison using Different Smoothing
Filters: Different Size
smooth sharpen
http://www.bythom.com/
sharpening.htm
Enhance/amplify difference by
image sharpening
Sharpening Spatial Filters
Original image
𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝑐 ∗ 𝑒(𝑥, 𝑦)
f
= f ( x + 1) − f ( x)
x
Nonzero at
• onset of ramp and step
• along ramp
2 f Double edge
= f ( x + 1)
x 2
+ f ( x − 1) − 2 f ( x)
Thick edge
Nonzero at
• onset of ramp and step
• end of ramp and step
First-order VS Second-order Derivative for
Edge Detection
Direction of change 𝜕𝑓
𝑔𝑥 𝜕𝑥
∇𝑓 = grad(𝑓) = 𝑔 =
𝑦 𝜕𝑓
𝜕𝑦
Magnitude of change (gradient image)
𝑀(𝑥, 𝑦) = 𝑚𝑎𝑔(∇𝑓)
http://en.wikipedia.org/wiki/Image_gradient
= 𝑔𝑥2 + 𝑔𝑦2
𝑀(𝑥, 𝑦) ≈ |𝑔𝑥 | + |𝑔𝑦 |
Gradient for Image Sharpening
Edge detectors:
• Roberts cross – fast
while sensitive to noise
• Sobel - smooth
Laplacian for Image Sharpening
x y
Laplacian operator
2
f 2
f 2
f
2 f = 2 + 2 + 2
x y xy
g ( x, y ) = f ( x, y )
+ c 2 f ( x, y )
Image sharpening with Laplacian
Image Sharpening
g ( x, y) = f ( x, y) + k * ( f ( x, y) − f ( x, y) )
k 0
Blurred
Unsharp mask
Order-statistic filtering – rank the pixel values in the filter window and
assign the center pixel according to the property of the filter
• Median
• Min/max
Reading Assignments