Linear Algebra & Geometry - Stanford University
Transcript of Linear Algebra & Geometry - Stanford University
![Page 1: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/1.jpg)
Linear Algebra & Geometry why is linear algebra useful in computer vision?
Some of the slides in this lecture are courtesy to Prof. Octavia I. Camps, Penn State University
References:-Any book on linear algebra!-[HZ] – chapters 2, 4
![Page 2: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/2.jpg)
Why is linear algebra useful in computer vision?
• Representation– 3D points in the scene– 2D points in the image
• Coordinates will be used to– Perform geometrical transformations– Associate 3D with 2D points
• Images are matrices of numbers– Find properties of these numbers
![Page 3: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/3.jpg)
Agenda
1. Basics definitions and properties2. Geometrical transformations3. SVD and its applications
![Page 4: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/4.jpg)
P = [x,y,z]
Vectors (i.e., 2D or 3D vectors)
Image
3D worldp = [x,y]
![Page 5: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/5.jpg)
Vectors (i.e., 2D vectors)
P
x1
x2θ
v
Magnitude:
Orientation:
Is a unit vector
If , Is a UNIT vector
![Page 6: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/6.jpg)
Vector Addition
vw
v+w
![Page 7: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/7.jpg)
Vector Subtraction
vw
v-w
![Page 8: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/8.jpg)
Scalar Product
vav
![Page 9: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/9.jpg)
Inner (dot) Product
vw
α
The inner product is a SCALAR!
![Page 10: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/10.jpg)
Orthonormal BasisP
x1
x2θ
v
ij
![Page 11: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/11.jpg)
Magnitude:kuk = kv ⇥ wk = kvkkwk sin↵
Vector (cross) Product
The cross product is a VECTOR!
wv
αu
Orientation:
![Page 12: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/12.jpg)
i = j⇥ k
j = k⇥ i
k = i⇥ j
Vector Product Computation
)1,0,0()0,1,0()0,0,1(
=
=
=
kji
1||||1||||1||||
=
=
=
kji
kji )()()( 122131132332 yxyxyxyxyxyx −+−+−=
![Page 13: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/13.jpg)
Matrices
Sum:
Example:
A and B must have the same dimensions!
Pixel’s intensity value
An⇥m =
2
6664
a11 a12 . . . a1ma21 a22 . . . a2m...
......
...an1 an2 . . . anm
3
7775
![Page 14: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/14.jpg)
Matrices
Product:
A and B must have compatible dimensions!
An⇥m =
2
6664
a11 a12 . . . a1ma21 a22 . . . a2m...
......
...an1 an2 . . . anm
3
7775
![Page 15: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/15.jpg)
Matrix Transpose
Definition:
Cm×n = ATn×m
cij = aji
Identities:
(A + B)T = AT + BT
(AB)T = BTAT
If A = AT , then A is symmetric
![Page 16: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/16.jpg)
Matrix Determinant
Useful value computed from the elements of a square matrix A
det[a11
]= a11
det
[a11 a12
a21 a22
]= a11a22 − a12a21
det
a11 a12 a13
a21 a22 a23
a31 a32 a33
= a11a22a33 + a12a23a31 + a13a21a32
− a13a22a31 − a23a32a11 − a33a12a21
![Page 17: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/17.jpg)
Matrix Inverse
Does not exist for all matrices, necessary (but not sufficient) thatthe matrix is square
AA−1 = A−1A = I
A−1 =
[a11 a12
a21 a22
]−1
=1
det A
[a22 −a12
−a21 a11
], det A 6= 0
If det A = 0, A does not have an inverse.
![Page 18: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/18.jpg)
2D Geometrical Transformations
![Page 19: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/19.jpg)
2D Translation
t
P
P’
![Page 20: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/20.jpg)
2D Translation Equation
P
x
y
tx
tyP’
t
![Page 21: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/21.jpg)
2D Translation using Matrices
P
x
y
tx
tyP’
t
![Page 22: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/22.jpg)
Homogeneous Coordinates
• Multiply the coordinates by a non-zero scalar and add an extra coordinate equal to that scalar. For example,
![Page 23: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/23.jpg)
Back to Cartesian Coordinates:
• Divide by the last coordinate and eliminate it. For example,
• NOTE: in our example the scalar was 1
![Page 24: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/24.jpg)
2D Translation using Homogeneous Coordinates
P
x
y
tx
tyP’
tt
P
![Page 25: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/25.jpg)
Scaling
P
P’
![Page 26: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/26.jpg)
Scaling Equation
P
x
y
sx x
P’sy y
![Page 27: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/27.jpg)
P
P’=S·PP’’=T·P’
P’’=T · P’=T ·(S · P)=(T · S)·P = A · P
Scaling & Translating
P’’
![Page 28: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/28.jpg)
Scaling & Translating
A
![Page 29: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/29.jpg)
Translating & Scaling = Scaling & Translating ?
![Page 30: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/30.jpg)
Rotation
P
P’
![Page 31: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/31.jpg)
Rotation Equations
Counter-clockwise rotation by an angle θ
P
x
y’P’
θ
x’y
![Page 32: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/32.jpg)
Degrees of Freedom
R is 2x2 4 elements
Note: R belongs to the category of normal matrices and satisfies many interesting properties:
![Page 33: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/33.jpg)
Rotation+ Scaling +TranslationP’= (T R S) P
If sx=sy, this is asimilarity transformation!
![Page 34: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/34.jpg)
Transformation in 2D
-Isometries
-Similarities
-Affinity
-Projective
![Page 35: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/35.jpg)
Transformation in 2D
Isometries:
- Preserve distance (areas)- 3 DOF- Regulate motion of rigid object
[Euclideans]
![Page 36: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/36.jpg)
Transformation in 2D
Similarities:
- Preserve- ratio of lengths- angles
-4 DOF
![Page 37: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/37.jpg)
Transformation in 2D
Affinities:
![Page 38: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/38.jpg)
Transformation in 2D
Affinities:
-Preserve:- Parallel lines- Ratio of areas- Ratio of lengths on collinear lines- others…
- 6 DOF
![Page 39: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/39.jpg)
Transformation in 2D
Projective:
- 8 DOF- Preserve:
- cross ratio of 4 collinear points- collinearity - and a few others…
![Page 40: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/40.jpg)
Eigenvalues and Eigenvectors
A eigenvalue λ and eigenvector u satisfies
Au = λu
where A is a square matrix.
I Multiplying u by A scales u by λ
![Page 41: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/41.jpg)
Eigenvalues and Eigenvectors
Rearranging the previous equation gives the system
Au− λu = (A− λI)u = 0
which has a solution if and only if det(A− λI) = 0.
I The eigenvalues are the roots of this determinant which ispolynomial in λ.
I Substitute the resulting eigenvalues back into Au = λu andsolve to obtain the corresponding eigenvector.
![Page 42: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/42.jpg)
UΣVT = A• Where U and V are orthogonal matrices,
and Σ is a diagonal matrix. For example:
Singular Value Decomposition
![Page 43: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/43.jpg)
Singular Value decomposition
that
![Page 44: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/44.jpg)
• Look at how the multiplication works out, left to right:
• Column 1 of U gets scaled by the first value from Σ.
• The resulting vector gets scaled by row 1 of VT to produce a contribution to the columns of A
An Numerical Example
![Page 45: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/45.jpg)
• Each product of (column i of U)·(value i from Σ)·(row i of VT) produces a
+=
An Numerical Example
![Page 46: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/46.jpg)
We can look at Σ to see that the first column has a large effect
while the second column has a much smaller effect in this example
An Numerical Example
![Page 47: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/47.jpg)
• For this image, using only the first 10 of 300 singular values produces a recognizable reconstruction
• So, SVD can be used for image compression
SVD Applications
![Page 48: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/48.jpg)
• Remember, columns of U are the Principal Components of the data: the major patterns that can be added to produce the columns of the original matrix
• One use of this is to construct a matrix where each column is a separate data sample
• Run SVD on that matrix, and look at the first few columns of U to see patterns that are common among the columns
• This is called Principal Component Analysis (or PCA) of the data samples
Principal Component Analysis
![Page 49: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/49.jpg)
• Often, raw data samples have a lot of redundancy and patterns
• PCA can allow you to represent data samples as weights on the principal components, rather than using the original raw form of the data
• By representing each sample as just those weights, you can represent just the “meat” of what’s different between samples.
• This minimal representation makes machine learning and other algorithms much more efficient
Principal Component Analysis
![Page 50: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/50.jpg)
![Page 51: Linear Algebra & Geometry - Stanford University](https://reader031.fdocuments.in/reader031/viewer/2022012013/6158bdef0fc90945cc382014/html5/thumbnails/51.jpg)