Professional Documents
Culture Documents
Linear Filters
Professor Fei‐Fei Li
Stanford Vision Lab
f(x,y)
f(x,y)
y
y
x x
r ( x, y )
• A color image: f ( x, y ) g ( x, y )
b( x, y )
Cartesian coordinates
Notation for
discrete
functions
Array coordinates
Matlab notation
Goals:
‐Extract useful information from the images
• Features (edges, corners, blobs…)
In‐painting
Bertamio et al
Fei-Fei Li Lecture 3 - 10 3‐Oct‐12
2D discrete‐space systems (filters)
1 1 1
1 1 1
1
( f h)[m, n] f [k , l ] h[m k , n l ]
9 k ,l
Fei-Fei Li Lecture 3 - 12 3‐Oct‐12
Moving average
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0
0 0
0 0
0 90
90 0
0 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
Courtesy of S. Seitz
0
0 0
0 90
90 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
(f g )[m, n ] f [k , l] g[m k , n l]
k ,l 14
Fei-Fei Li Lecture 3 - 14 3‐Oct‐12
Moving average
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
(f g )[m, n ] f [k , l] g[m k , n l]
k ,l
Fei-Fei Li Lecture 3 - 15 3‐Oct‐12
Moving average
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
(f g )[m, n ] f [k , l] g[m k , n l]
k ,l
Fei-Fei Li Lecture 3 - 16 3‐Oct‐12
Moving average
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
(f g )[m, n ] f [k , l] g[m k , n l]
k ,l
Fei-Fei Li Lecture 3 - 17 3‐Oct‐12
Moving average
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10
0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30
0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20
0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10
0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
(f g )[m, n ] f [k , l] g[m k , n l]
k ,l Source: S. Seitz
g[ , ]
In summary:
• Replaces each pixel 1 1 1
• Achieve smoothing
effect (remove sharp
features)
Fei-Fei Li Lecture 3 - 19 3‐Oct‐12
Moving average
• Spatial properties
• Causality
• Separability
• Memory
• Shift invariance
• Rotation invariance
• If then
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10
0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30
0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20
0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10
0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Yes!
Fei-Fei Li Lecture 3 - 25 3‐Oct‐12
Linear Systems (filters)
• Linear filtering:
– Form a new image whose pixels are a weighted sum of
original pixel values
– Use the same set of weights at each point
superposition property
h
1 1 1
1 1 1
1 1 1
superposition
Discrete convolution
h[k,l]
h[‐k,‐l] h[n‐k,m‐l]
n
Fei-Fei Li Lecture 3 - 32 3‐Oct‐12
Discrete convolution
• Fold h[n,m] about origin to form h[−k,−l]
• Shift the folded results by n,m to form h[n − k,m − l]
• Mul ply h[n − k,m − l] by f[k, l]
• Sum over all k,l
• Repeat for every n,m
h[k,l]
h[‐k,‐l] h[n‐k,m‐l]
n
Fei-Fei Li Lecture 3 - 33 3‐Oct‐12
Discrete convolution
• Fold h[n,m] about origin to form h[−k,−l]
• Shift the folded results by n,m to form h[n − k,m − l]
• Mul ply h[n − k,m − l] by f[k, l]
• Sum over all k,l
• Repeat for every n,m f[k,l] x h[n‐k,m‐l]
h[n‐k,m‐l]
n
Fei-Fei Li Lecture 3 - 34 3‐Oct‐12
Convolution in 2D ‐ examples
•0 •0 •0
•0 •1 •0
= ?
•0 •0 •0
Courtesy of D Lowe
Original
•0 •0 •0
•0 •1 •0
•0 •0 •0
=
Courtesy of D Lowe
Original Filtered
(no change)
•0 •0 •0
•0 •0 •1
= ?
•0 •0 •0
Courtesy of D Lowe
Original
•0 •0 •0
•0 •0 •1
•0 •0 •0
=
Courtesy of D Lowe
Original Shifted right
By 1 pixel
•1 •1 •1
•1 •1 •1
•1 •1 •1
= ?
Courtesy of D Lowe
Original
•1 •1 •1
•1 •1 •1
•1 •1 •1
=
Courtesy of D Lowe
Original Blur (with a
box filter)
•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 “details of the image”
Courtesy of D Lowe
•0 •0 •0 •0 •0 •0 •1 •1 •1
•0 •1 •0
•0 •0 •0
+ •0 •1 •0
•0 •0 •0
- •1 •1 •1
•1 •1 •1
– =
+a =
•0 •0 •0 •1 •1 •1
•0 •2 •0
•0 •0 •0
- •1 •1 •1
•1 •1 •1 =
Original
Courtesy of D Lowe
Sharpening filter: Accentuates differences with local average
• Associative property:
• Distributive property:
• Shift property:
• Shift‐invariance:
N1 ×M1
• zero “padding”
f • edge value replication
h • mirror extension
• more (beyond the scope of this class)
Courtesy of J. Fessler
MATLAB’s
xcorr2
Fei-Fei Li Lecture 3 - 49 3‐Oct‐12
Cross correlation – example
Left Right
scanline
Norm. corr
Inverse 2D DSFT:
Convolution:
Delta function:
1
( f h)[m, n] f [k , l ] h [m k , n l ]
9 k ,l h
1 1 1
1 1 1
1 1 1
• Down‐sampling operation:
(trivial form of image compression)
v v v good
bad
y
• N = sampling period T
• T = periodicity of the
replicas of the DFT (g)
T 1/N x
y
…
• N = sampling period
• T = periodicity of the … …
replicas of the DFT (g)
T 1/N x
…
…
…
G ( )
x
Low pass filter (smoothing)
blur
G1 (G0 * gaussian) 2
G0 Image
blur
High resolution
Figure from “Computer Vision for Interactive Computer Graphics,” W.Freeman et al, IEEE Computer Graphics and Applications,
1998 copyright 1998, IEEE
then
If g is square summable
(energy signal):
•Apply the 1D DFT to each column of the image, and then apply
the 1D DFT to each row of the result.
• Use the fast Fourier transform (1‐D FFT) for these 1D DFTs!
Fei-Fei Li Lecture 3 - 82 3‐Oct‐12
Fast Fourier transforms (FFT)
• FFT computational efficiency:
If x = 512x512 image
saving is a factor of 15000 relative to the brute‐force 2D DFT!