spatial filtering - national institute of technology calicut · figure:spatial filtering with a 3 3...
TRANSCRIPT
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Spatial Filtering
Dr. Praveen Sankaran
Department of ECE
NIT Calicut
January 7, 2013
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Outline
1 Review
2 Smoothing Spatial FiltersLinearNonlinear
3 Sharpening Spatial FiltersGradients and their use in Sharpening
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Spatial Domain
Refers to the image plane itself.↓
Direct manipulation of image pixels.
Figure: Spatial Filtering with a 3×3 mask (kernel, template or window)
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Spatial Filter
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Correlation and Convolution - Representations
Correlation
w (m,n)�g (m,n) =a
∑s=−a
b
∑t=−b
w (s, t)g (m+ s, y + t)
Convolution
w (m,n)?g (m,n) =a
∑s=−a
b
∑t=−b
w (s, t)g (m− s, y − t)
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Generating a Gaussian Mask
Creating a �lter essentially boils down to specifying the valuesof mask coe�cients.
Basic form →h (x ,y) = e
− x2+y2
2σ2
sample,quantize
⇓
h (m,n) = e−m
2+n2
2σ2
Sample the continuous function about its center.w1 w2 w3
w4 w5 w6
w7 w8 w9
=
h (−1,−1) h (0,−1) h (1,−1)h (−1,0) h (0,0) h (1,0)h (−1,1) h(0,1) h (1,1)
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
LinearNonlinear
Outline
1 Review
2 Smoothing Spatial FiltersLinearNonlinear
3 Sharpening Spatial FiltersGradients and their use in Sharpening
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
LinearNonlinear
Averaging Filters
Objective → Noise reduction by reducing sharp transitions inintensities.
We have seen an averaging �lter before. These are alsoreferred to as low pass �lters.
Creating an averaging �lter - replace pixel with average intensity inneighborhood
Average = 19
9
∑i=1
gi =9
∑i=1
19gi ,
19
19
19
19
19
19
19
19
19
→averaging mask
Note that we are giving equal weight to the pixel underconsideration and the pixel values around it.
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
LinearNonlinear
Averaging Filters - Weighted
Idea → replace pixel value underconsideration with a weightedaverage of values in mask region.
Multiply pixel values withdi�erent mask coe�cients.
Done to reduce blurring.
116×
1 2 12 4 21 2 1
i (m,n) =
a
∑s=−a
b
∑t=−b
w (s, t)g (m± s, y ± t)
∑as=−a ∑
bt=−bw (s, t)
,
m = 0,1, · · ·M−1, n = 0,1,2, · · ·N−1.
Note that we need not worry about our operation beingconvolution or correlation with these masks.
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
LinearNonlinear
Filter Size Matters
Figure: E�ect of varying �lter sizes on an Image. Original image withsize 500×500. Filter sizes with m = 3,5,9,15,35
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
LinearNonlinear
Outline
1 Review
2 Smoothing Spatial FiltersLinearNonlinear
3 Sharpening Spatial FiltersGradients and their use in Sharpening
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
LinearNonlinear
Order-Statistic (Nonlinear) Filters - Median Filter
Replace value of a pixel by the median of the pixel values inthe mask region or region-of-interest (ROI).
Typical application → remove salt-&-pepper (?) noise.
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
Outline
1 Review
2 Smoothing Spatial FiltersLinearNonlinear
3 Sharpening Spatial FiltersGradients and their use in Sharpening
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
First Derivative
1 Must be zero in areas of constant intensity;
2 Must be non-zero at the onset of an intensity step or ramp;
3 Must be non-zero along ramps.
4 ∂ f∂x
= f (x+1,y)− f (x ,y), remember the problem we talkedabout earlier?
From Taylor's theorem,
f (x±ξ ,y) = f (x ,y)+ ∂ f (x ,y)∂x
(±ξ )+ 12!
∂2f (x ,y)∂x2
ξ 2+ · · ·Ignoring higher order terms we end up with three di�erent scenarios.
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
Di�ering Approximations
1∂ f (x ,y)
∂xw f (x+ξ ,y)−f (x ,y)
ξ
2∂ f (x ,y)
∂xw f (x ,y)−f (x−ξ ,y)
ξ
3∂ f (x ,y)
∂xw f (x+ξ ,y)−f (x−ξ ,y)
2ξ
Substituting ξ = 1, three separate, corresponding operators can beformed for a digital image.
Which one do we choose?
g [m+1,n]−g [m,n]g [m,n]−g [m−1,n]g [m+1,n]−g [m−1,n]
2
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
Second Derivative
1 Must be zero in areas of constant intensity;
2 Must be non-zero at the onset and end of an intensity step orramp;
3 Must be zero along ramps of constant slope.
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
The Laplacian
Laplacian
∇2f (x ,y) = ∂2f (x ,y)∂x2
+ ∂2f (x ,y)∂y2
From Taylor's theorem,
f (x±ξ ,y) = f (x ,y)+ ∂ f (x ,y)∂x
(±ξ )+ 12!
∂2f (x ,y)∂x2
ξ 2+ · · · , and take
∂ f (x ,y)∂x
w f (x+ξ ,y)−f (x−ξ ,y)2ξ
, ξ = 1
∂2f∂x2≈ f (x+1,y)+ f (x−1,y)−2f (x ,y) and,
∂2f∂y2≈ f (x ,y +1)+ f (x ,y −1)−2f (x ,y)
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
The Laplacian
Laplacian
∇2f (x ,y) = ∂2f (x ,y)∂x2
+ ∂2f (x ,y)∂y2
From Taylor's theorem,
f (x±ξ ,y) = f (x ,y)+ ∂ f (x ,y)∂x
(±ξ )+ 12!
∂2f (x ,y)∂x2
ξ 2+ · · · , and take
∂ f (x ,y)∂x
w f (x+ξ ,y)−f (x−ξ ,y)2ξ
, ξ = 1
∂2f∂x2≈ f (x+1,y)+ f (x−1,y)−2f (x ,y) and,
∂2f∂y2≈ f (x ,y +1)+ f (x ,y −1)−2f (x ,y)
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
The Laplacian (Final Approximated Form)
Laplacian Form in digital image
∇2g ≈g [m+1,n]+g [m−1,n]+g [m,n+1]+g [m,n−1]−4g [m,n].
Mask Values0 1 01 −4 10 1 0
Note that any di�erent approximation of the Taylor seriesexpansion could have given a di�erent form for the Laplacian.
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
Using Laplacian to Sharpen an Image
i (m,n) =g [m,n]+ c
[∇2g [m,n]
]Add Laplacian image to theoriginal.
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
Unsharp Masking and Highboost Filtering
1 Blur the original image;
2 Subtract the blurred image from the original (this forms themask);
3 Add mask to the original.
imask [m,n] = g [m,n]−gavg [m,n],
g [m,n] = g [m,n]+k× imask [m,n]
If k = 1, process = unsharp masking.
If k > 1, process = highboost �ltering.
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
First Gradients - Robert's
We de�ne an image j [m,n] =
√(∂g∂m
)2+(
∂g∂n
)2→ gradient
image.
Roberts [1965] →(
∂g∂m
)= (w9−w5),(
∂g∂n
= (w8−w6))
gradient image =
i [m,n] =
√[(w9−w5)
2+(w8−w6)2]
w1 w2 w3
w4 w5 w6
w7 w8 w9
[−1 00 1
] [0 −11 0
]
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
Sobel Operator
Roberts had a mask of even size → no center of symmetry.
Approximate →(∂g∂m
)= (w7+2w8+w9)−
(w1+2w2+w3),(∂g∂n
)= (w3+2w6+w9)−
(w1+2w4+w7)
w1 w2 w3
w4 w5 w6
w7 w8 w9
−1 −2 −1
0 0 01 2 1
−1 0 1−2 0 2−1 0 1
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
Summary
Application of Spatial approach to:
Low pass �ltering.Sharpening.
First gradient, Roberts, Sobel.
Second gradient, Laplacian
Application of gradient to sharpening.
Dr. Praveen Sankaran DIP Winter 2013
ReviewSmoothing Spatial FiltersSharpening Spatial Filters
Gradients and their use in SharpeningSummary
Questions
3.1, 3.2, 3.3, 3.4, 3.5
3.6, 3.7, 3.11
3.13, 3.14
3.15, 3.16, 3.17,3.18, 3.26, 3.27, 3.28
Dr. Praveen Sankaran DIP Winter 2013