CV 02
CV 02
Computer Vision
James Hays, Brown Many slides by Derek Hoiem
Next three classes: three views of filtering
• Really important!
– Enhance images
• Denoise, resize, increase contrast, etc.
– Extract information from images
• Texture, edges, distinctive points, etc.
– Detect patterns
• Template matching
Example: box filter
g[ , ]
1 1 1
1 1 1
1 1 1
g[ , ] 1 1 1
1 1 1
f [.,.] h[.,.]
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l Credit: S. Seitz
Image filtering 1 1 1
g[ , ] 1 1 1
1 1 1
f [.,.] h[.,.]
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l Credit: S. Seitz
Image filtering 1 1 1
g[ , ] 1 1 1
1 1 1
f [.,.] h[.,.]
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l Credit: S. Seitz
Image filtering 1 1 1
g[ , ] 1 1 1
1 1 1
f [.,.] h[.,.]
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l Credit: S. Seitz
Image filtering 1 1 1
g[ , ] 1 1 1
1 1 1
f [.,.] h[.,.]
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l Credit: S. Seitz
Image filtering 1 1 1
g[ , ] 1 1 1
1 1 1
f [.,.] h[.,.]
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l Credit: S. Seitz
Image filtering 1 1 1
g[ , ] 1 1 1
1 1 1
f [.,.] h[.,.]
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l Credit: S. Seitz
Image filtering g[ , ] 1 1 1
1 1 1
1 1 1
f [.,.] h[.,.]
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l Credit: S. Seitz
Box Filter
g[ , ]
What does it do?
• Replaces each pixel with 1 1 1
an average of its
neighborhood 1 1 1
1 1 1
• Achieve smoothing effect
(remove sharp features)
?
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
-
0 0 0 1 1 1
0
0
2
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 1 1 1
0 0 0 1 1 1
Source: D. Lowe
Sharpening
Source: D. Lowe
Other filters
1 0 -1
2 0 -2
1 0 -1
Sobel
Vertical Edge
(absolute value)
Other filters
1 2 1
0 0 0
-1 -2 -1
Sobel
Horizontal Edge
(absolute value)
How could we synthesize motion blur?
• 2d convolution
– h=conv2(g,f);
h[ m, n] g[ k , l ] f [ m k , n l ]
k ,l
Key properties of linear filters
Linearity:
filter(f1 + f2) = filter(f1) + filter(f2)
• Associative: a * (b * c) = (a * b) * c
– Often apply several filters one after another: (((a * b1) * b2) * b3)
– This is equivalent to applying one filter: a * (b1 * b2 * b3)
5 x 5, = 1
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?
Some practical matters
Practical matters
How big should the filter be?
• Values at edges should be near zero
• Rule of thumb for Gaussian: set filter half-width to
about 3 σ
Practical matters
• 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
Q?
Practical matters
– 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
Practical matters
• What is the size of the output?
• MATLAB: filter2(g, f, shape)
– shape = ‘full’: output size is sum of sizes of f and g
– shape = ‘same’: output size is same as f
– shape = ‘valid’: output size is difference of sizes of f and g
full same valid
g g
g g
g g
f f f
g g
g g
g g
Source: S. Lazebnik
Median filters
Laplacian Filter!
1 1 1
a) _ = D * B
3. Fill in the blanks: b) A = _ * _
A
c) F = D * _
d) _ = D * D
B
E
G
F C
H I D
Next class: Thinking in Frequency