Professional Documents
Culture Documents
Pixels and Filters: Juan Carlos Niebles and Ranjay Krishna Stanford Vision Lab
Pixels and Filters: Juan Carlos Niebles and Ranjay Krishna Stanford Vision Lab
231
148
Cartesian coordinates
Notation for
discrete
functions
é r ( x, y ) ù
• A color image: f ( x, y ) = êê g ( x, y ) úú
êë b( x, y ) úû
In-painting
Bertamio et al
Stanford University Lecture 4- 33 6-Oct-16
Images as coordinates
Cartesian coordinates
Notation for
discrete
functions
1 1 1
1 1 1
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
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
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
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
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
In summary:
h[⋅ ,⋅ ]
• This filter “Replaces” each
pixel with an average of its 1 1 1
neighborhood. 1 1 1
1 1 1
• Achieve smoothing effect
(remove sharp features)
– Homogeneity
– Homogeneity
– Superposition
– Homogeneity
– Superposition
– Stability
– Homogeneity
– Superposition
– Stability
– Invertibility
– Shift invariance:
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!
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
• 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
1 1 1
1 1 1
1
( f * h)[m, n] = å f [k , l ] h[m - k , n - l ]
9 k ,l
Stanford University Lecture 4- 60 6-Oct-16
LSI (linear shift invariant) systems
A simple LSI is one that shifts the pixels of an
image:
shifting property of the delta function
superposition property
f [n, m] ⇤ h[n, m]
h[k,l] f[k,l]
h[k] h[n-k]
h[-2-k]
f[k] g[-2]
h[-1-k]
f[k] g[-1]
h[-k]
f[k] g[0]
h[1-k]
f[k] g[1]
h[2-k]
f[k] g[2]
h[n-k]
f[k] g[n]
n
Stanford University Lecture 4- 75 6-Oct-16
2D convolution
2D convolution is very similar to 1D.
• The main difference is that we now have to iterate over 2 axis instead of 1.
f [n, m] ⇤ h[n, m]
n
Stanford University Lecture 4- 76 6-Oct-16
2D convolution
2D convolution is very similar to 1D.
• The main difference is that we now have to iterate over 2 axis instead of 1.
f [n, m] ⇤ h[n, m]
n
Stanford University Lecture 4- 77 6-Oct-16
2D convolution
2D convolution is very similar to 1D.
• The main difference is that we now have to iterate over 2 axis instead of 1.
f [n, m] ⇤ h[n, m]
n
Stanford University Lecture 4- 78 6-Oct-16
2D convolution
2D convolution is very similar to 1D.
• The main difference is that we now have to iterate over 2 axis instead of 1.
f [n, m] ⇤ h[n, m]
n
Stanford University Lecture 4- 79 6-Oct-16
2D convolution
2D convolution is very similar to 1D.
• The main difference is that we now have to iterate over 2 axis instead of 1.
f [n, m] ⇤ h[n, m]
n
Stanford University Lecture 4- 80 6-Oct-16
2D convolution
2D convolution is very similar to 1D.
• The main difference is that we now have to iterate over 2 axis instead of 1.
f [n, m] ⇤ h[n, m]
superposition
Discrete convolution
f [n, m] ⇤ h[n, m]
Stanford University Lecture 4- 82 6-Oct-16
2D convolution example
•0 •0 •0
* •0 •1 •0
= ?
•0 •0 •0
Original
Courtesy of D Lowe
Stanford University Lecture 4- 90 6-Oct-16
Convolution in 2D - examples
•0 •0 •0
* •0 •1 •0
•0 •0 •0
=
Original Filtered
Courtesy of D Lowe
(no change)
•0 •0 •0
* •0 •0 •1
= ?
•0 •0 •0
Original
Courtesy of D Lowe
Stanford University Lecture 4- 92 6-Oct-16
Convolution in 2D - examples
•0 •0 •0
* •0 •0 •1
•0 •0 •0
=
Original Shifted right
Courtesy of D Lowe
By 1 pixel
•1 •1 •1
* •1 •1 •1
•1 •1 •1
= ?
Original
Courtesy of D Lowe
Stanford University Lecture 4- 94 6-Oct-16
Convolution in 2D - examples
•1 •1 •1
* •1 •1 •1
•1 •1 •1
=
Original Blur (with a
Courtesy of D Lowe
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”
•0 •0 •0 •0 •0 •0 •1 •1 •1
Courtesy of D Lowe
•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
N1 ×M1
• zero “padding”
f • edge value replication
h • mirror extension
• more (beyond the scope of this class)
Courtesy of J. Fessler
Stanford University Lecture 4- 104 6-Oct-16
(Cross) correlation – example
Courtesy of J. Fessler
Stanford University Lecture 4- 105 6-Oct-16
(Cross) correlation – example
Courtesy of J. Fessler
numpy’s
correlate
Stanford University Lecture 4- 106 6-Oct-16
(Cross) correlation – example
Left Right
scanline
f*h f**h
Figure from “Computer Vision for Interactive Computer Graphics,” W.Freeman et al, IEEE Computer Graphics and Applications,
1998 copyright 1998, IEEE
• Distributive property:
• Shift property:
• Shift-invariance: