Lec05 Filter
Lec05 Filter
1 1 1
1 1 1
1 1 1
“box filter”
Source: D. Lowe
Defining convolution
• Let f be the image and g be the kernel. The
output of convolving f with g is denoted f * g.
( f g )[m, n] f [m k , n l ] g[k , l ]
k ,l
f f f
g g g
g g g
Annoying details
What about near the edge?
• the filter window falls off the edge of the image
• need to extrapolate
• methods:
– clip filter (black)
– wrap around
– copy edge
– reflect across edge
Source: S. Marschner
Annoying details
What about near the edge?
• the filter window falls off the edge of the image
• need to extrapolate
• methods (MATLAB):
– clip filter (black): imfilter(f, g, 0)
– wrap around: imfilter(f, g, ‘circular’)
– copy edge: imfilter(f, g, ‘replicate’)
– reflect across edge: imfilter(f, g, ‘symmetric’)
Source: S. Marschner
Practice with linear filters
0 0 0
0 1 0 ?
0 0 0
Original
Source: D. Lowe
Practice with linear filters
0 0 0
0 1 0
0 0 0
Original Filtered
(no change)
Source: D. Lowe
Practice with linear filters
0 0 0
0 0 1 ?
0 0 0
Original
Source: D. Lowe
Practice with linear filters
0 0 0
0 0 1
0 0 0
Source: D. Lowe
Practice with linear filters
?
1 1 1
1 1 1
1 1 1
Original
Source: D. Lowe
Practice with linear filters
1 1 1
1 1 1
1 1 1
Source: D. Lowe
Practice with linear filters
0 0 0 1 1 1
0 2 0
0 0 0
- 1 1 1
1 1 1
?
(Note that filter sums to 1)
Original
Source: D. Lowe
Practice with linear filters
0 0 0 1 1 1
0 2 0
0 0 0
- 1 1 1
1 1 1
Source: D. Lowe
Sharpening
Source: D. Lowe
Smoothing with box filter revisited
• Smoothing with an average actually doesn’t compare
at all well with a defocused lens
• Most obvious difference is that a single point of light
viewed in a defocused lens looks like a fuzzy blob; but
the averaging process would give a little square
Source: D. Forsyth
Smoothing with box filter revisited
• Smoothing with an average actually doesn’t compare
at all well with a defocused lens
• Most obvious difference is that a single point of light
viewed in a defocused lens looks like a fuzzy blob; but
the averaging process would give a little square
• Better idea: to eliminate edge effects, weight
contribution of neighborhood pixels according to their
closeness to the center, like so:
“fuzzy blob”
Gaussian Kernel
5 x 5, = 1
Source: K. Grauman
Choosing kernel width
• Rule of thumb: set filter half-width to about
3σ
Example: Smoothing with a Gaussian
Mean vs. Gaussian filtering
Gaussian filters
• Remove “high-frequency” components from
the image (low-pass filter)
• Convolution with self is another Gaussian
• So can smooth with small-width kernel, repeat, and get
same result as larger-width kernel would have
• Convolving two times with Gaussian kernel of width σ is
same as convolving once with kernel of width σ√2
• Separable kernel
• Factors into product of two 1D Gaussians
Source: K. Grauman
Separability of the Gaussian filter
Source: D. Lowe
Separability example
2D convolution
(center location only)
Perform convolution
along rows: * =
Followed by convolution =
along the remaining column: *
Source: K. Grauman
Separability
• Why is separability useful in practice?
Review: Linear filtering
• Properties of convolution
• Properties of Gaussian kernels
Noise
• Salt and pepper
noise: contains
random occurrences
of black and white
pixels
• Impulse noise:
contains random
occurrences of white
pixels
• Gaussian noise:
variations in
intensity drawn from
a Gaussian normal
distribution
Source: S. Seitz
Gaussian noise
• Mathematical model: sum of many
independent factors
• Good for small standard deviations
• Assumption: independent, zero-mean noise
Source: M. Hebert
Reducing Gaussian noise
Source: K. Grauman
Median filter
Salt-and-pepper noise Median filtered
Gaussian
Median
Sharpening revisited
What does blurring take away?
– =
+α =
unit impulse
Gaussian Laplacian of Gaussian
Application: Hybrid Images