Review:’’ Linear’Algebrafor’CameraModels’vision.stanford.edu › teaching ›...
Transcript of Review:’’ Linear’Algebrafor’CameraModels’vision.stanford.edu › teaching ›...
Reviews - !!!
Fei-Fei Li!
Review: Linear Algebra for Camera Models
Professor Fei-‐Fei Li Stanford Vision Lab
19-‐Oct-‐12 1
Reviews - !!!
Fei-Fei Li!
Agenda
• Basic definiEons and properEes • Geometrical transformaEons
19-‐Oct-‐12 2
Reading: [HZ] Chapter 2, 4
Reviews - !!!
Fei-Fei Li!
P = [x,y,z]
Vectors (i.e., 2D or 3D vectors)
Image
3D world p = [x,y]
19-‐Oct-‐12 3
Reviews - !!!
Fei-Fei Li! 19-‐Oct-‐12 4
Vectors (i.e., 2D vectors)
),( 21 xx=vP
x1
x2
θ v
Magnitude: 22
21|||| xx +=v
OrientaEon: ⎟⎟⎠
⎞⎜⎜⎝
⎛= −
1
21tanxx
θ
⎟⎟⎠
⎞⎜⎜⎝
⎛=
||||,||||||||
21
vvvv xx
Is a unit vector
If 1|||| =v , v Is a UNIT vector
Reviews - !!!
Fei-Fei Li!
Vector AddiEon
),(),(),( 22112121 yxyxyyxx ++=+=+wv
v w
v+w
19-‐Oct-‐12 5
Reviews - !!!
Fei-Fei Li!
Vector SubtracEon
),(),(),( 22112121 yxyxyyxx −−=−=−wv
v w
v-w
19-‐Oct-‐12 6
Reviews - !!!
Fei-Fei Li!
Scalar Product
),(),( 2121 axaxxxaa ==v
v av
19-‐Oct-‐12 7
Reviews - !!!
Fei-Fei Li!
Inner (dot) Product
v
w α
22112121 yxyx)y,y()x,x(wv +=⋅=⋅
The inner product is a SCALAR!
αcos||w||||v||)y,y()x,x(wv 2121 ⋅=⋅=⋅
?wv ,wvif =⋅⊥ 0=
19-‐Oct-‐12 8
Reviews - !!!
Fei-Fei Li! 19-‐Oct-‐12 9
Orthonormal Basis
),( 21 xx=v
1||||1||||
=
=
ji
jiv 21 xx +=
P
x1
x2
θ v
i
j )1,0()0,1(
=
=
ji 0=⋅ ji
?=⋅ iv
22121 x1.x0.x)xx( =+=⋅+=⋅ jjijv12121 x0x1x)xx( =+=⋅+= iji
Reviews - !!!
Fei-Fei Li!
Vector (cross) Product
wvu ×=
The cross product is a VECTOR!
w
v
α u
0)(0)(=⋅×=⋅⇒⊥
=⋅×=⋅⇒⊥
wwvwuwuvwvvuvu
OrientaEon:
αsin||w|||v||||wv|| ||u|| =⋅=Magnitude:
?w//vif 0u =→19-‐Oct-‐12 10
Reviews - !!!
Fei-Fei Li!
Vector Product ComputaEon
),,(),,( 321321 yyyxxx ×=×= wvu
) 1 , 0 , 0 (
) 0 , 1 , 0 (
) 0 , 0 , 1 (
=
=
=
k
j
i
1 || ||
1 || ||
1 || ||
=
=
=
k
j
i
0 0 0 = ⋅ = ⋅ = ⋅ k j k i j i
k j i ) ( ) ( ) ( 1 2 2 1 3 1 1 3 2 3 3 2 y x y x y x y x y x y x - + - + - =
19-‐Oct-‐12 11
Reviews - !!!
Fei-Fei Li!
Matrices
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
=×
nmnn
m
m
m
mn
aaa
aaaaaaaaa
A
21
33231
22221
11211
mnmnmn BAC ××× +=Sum: ijijij bac +=
?0120
1002
=⎥⎦
⎤⎢⎣
⎡+⎥⎦
⎤⎢⎣
⎡Example:
A and B must have the same dimensions!
Pixel’s intensity value
⎥⎦
⎤⎢⎣
⎡=
1122 PTP
tI⋅=⋅⎥
⎦
⎤⎢⎣
⎡=
1019-‐Oct-‐12 12
Reviews - !!!
Fei-Fei Li!
Matrices
⎥⎦
⎤⎢⎣
⎡=
10tS
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
100020101
P
⎥⎦
⎤⎢⎣
⎡=
2001
S
⎥⎦
⎤⎢⎣
⎡=01
t
19-‐Oct-‐12 13
Reviews - !!!
Fei-Fei Li!
Matrices
pmmnpn BAC ××× =
Product:
∑=
=⋅=m
1kkjikjiij bac ba
nnnnnnnn ABBA ×××× ≠
A and B must have compatible dimensions!
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
=×
nmnn
m
m
m
mn
aaa
aaaaaaaaa
A
21
33231
22221
11211 ia
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
=×
nmnn
m
m
m
mn
bbb
bbbbbbbbb
B
21
33231
22221
11211
jb
⎥⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡
7003
0110
⎥⎦
⎤⎢⎣
⎡=
0370
19-‐Oct-‐12 14
Reviews - !!!
Fei-Fei Li!
Matrices
mnT
nm AC ×× =Transpose:
jiij ac = TTT ABAB =)(
TTT BABA +=+ )(
If AAT = A is symmetric
Examples:
⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡
5216
5126 T
⎥⎦
⎤⎢⎣
⎡=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
852316
835126 T ⎥
⎦
⎤⎢⎣
⎡
5125
Symmetric?
⎥⎦
⎤⎢⎣
⎡
7223 Symmetric?
No!
Yes!
19-‐Oct-‐12 15
Reviews - !!!
Fei-Fei Li!
Matrices Determinant:
131521352
det −=−=⎥⎦
⎤⎢⎣
⎡Example:
A must be square
3231
222113
3331
232112
3332
232211
333231
232221
131211
detaaaa
aaaaa
aaaaa
aaaaaaaaaa
+−=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
122122112221
1211
2221
1211det aaaaaaaa
aaaa
−==⎥⎦
⎤⎢⎣
⎡
19-‐Oct-‐12 16
Reviews - !!!
Fei-Fei Li!
Matrices
IAAAA nnnnnnnn == ××−
×−
×11
Inverse: A must be square
⎥⎦
⎤⎢⎣
⎡
−
−
−=⎥
⎦
⎤⎢⎣
⎡−
1121
1222
12212211
1
2221
1211 1aaaa
aaaaaaaa
Example:
?5126 1
=⎥⎦
⎤⎢⎣
⎡−
⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡
−
−=⎥
⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡−
1001
280028
281
5126
.6125
281
5126
.5126 1
⎥⎦
⎤⎢⎣
⎡
−
−=
6125
281
19-‐Oct-‐12 17
Reviews - !!!
Fei-Fei Li!
Agenda
• Basic definiEons and properEes • Geometrical transformaEons
19-‐Oct-‐12 18
Reading: [HZ] Chapter 2, 4
Reviews - !!!
Fei-Fei Li!
2D TranslaEon
t
P
P’
19-‐Oct-‐12 19
2D TranslaEon EquaEon
P
x
y
tx
ty
P’
t
)ty,tx(' yx ++=+= tPP
),(),(
yx ttyx
=
=
tP
19-‐Oct-‐12 20
Reviews - !!!
Fei-Fei Li! 19-‐Oct-‐12 21
2D TranslaEon using Matrices
P
x
y
tx
ty
P’ t
),(),(
yx ttyx
=
=
tP
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⋅⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡
+
+→
110
01
' yx
tt
tytx
y
x
y
xP
Reviews - !!!
Fei-Fei Li!
Homogeneous Coordinates
• MulEply the coordinates by a non-‐zero scalar and add an extra coordinate equal to that scalar. For example,
0 ),,,(),,(0 ),,(),(
≠⋅⋅⋅→
≠⋅⋅→
wwwzwywxzyxzzzyzxyx
19-‐Oct-‐12 22
Reviews - !!!
Fei-Fei Li!
Back to Cartesian Coordinates:
• Divide by the last coordinate and eliminate it. For example,
)/,/,/(0 ),,,()/,/(0 ),,(
wzwywxwwzyxzyzxzzyx
→≠
→≠
• NOTE: in our example the scalar was 1
19-‐Oct-‐12 23
Reviews - !!!
Fei-Fei Li! 19-‐Oct-‐12 24
2D TranslaEon using Homogeneous Coordinates
P
x
y
tx
ty
P’ t
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⋅
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
+
+
→
11001001
1' y
xtt
tytx
y
x
y
x
P
)1,,(),()1,,(),(
yxyx ttttyxyx
→=
→=
tP
t P
PTPtI
⋅=⋅⎥⎦
⎤⎢⎣
⎡=
10
Reviews - !!!
Fei-Fei Li!
Scaling
P
P’
19-‐Oct-‐12 25
Reviews - !!!
Fei-Fei Li!
Scaling EquaEon
P
x
y
sx x
P’ sy y
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⋅
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
→
11000000
1' y
xs
sysxs
y
x
y
x
P
)1,,(),(')1,,(),(
ysxsysxsyxyx
yxyx →=
→=
PP
S
PSP100S
⋅=⋅⎥⎦
⎤⎢⎣
⎡=
'
)ys,xs(')y,x( yx=→= PP
19-‐Oct-‐12 26
Reviews - !!!
Fei-Fei Li!
P
P’=S·P P’’=T·P’
P’’=T ·∙ P’=T ·∙(S ·∙ P)= T ·∙ S ·∙P = A ·∙ P
Scaling & TranslaEng
P’’
19-‐Oct-‐12 27
Reviews - !!!
Fei-Fei Li!
Scaling & TranslaEng
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎦
⎤⎢⎣
⎡=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
+
+
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⋅
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=⋅⋅=
110
1111000
0
11000000
1001001
''
yx
tSyx
tystxs
yx
tsts
yx
ss
tt
yy
xx
yy
xx
y
x
y
x
PSTP
A 19-‐Oct-‐12 28
Reviews - !!!
Fei-Fei Li!
TranslaEng & Scaling = Scaling & TranslaEng ?
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
+
+
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=⋅⋅=
1tsystsxs
1yx
100tss0ts0s
1yx
100t10t01
1000s000s
'''
yyy
xxx
yyy
xxx
y
x
y
x
PTSP
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
+
+
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=⋅⋅=
1tystxs
1yx
100ts0t0s
1yx
1000s000s
100t10t01
''' yy
xx
yy
xx
y
x
y
x
PSTP
19-‐Oct-‐12 29
Reviews - !!!
Fei-Fei Li!
RotaEon
P
P’
19-‐Oct-‐12 30
Reviews - !!!
Fei-Fei Li!
RotaEon EquaEons Counter-clockwise rotation by an angle θ
⎥⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡ −=⎥
⎦
⎤⎢⎣
⎡
yx
yx
θθ
θθ
cossinsincos
''
P
x
y’ P’
θ
x’
y
PRP'=
yθsinxθcos'x −=xθsinyθcos'y +=
19-‐Oct-‐12 31
Reviews - !!!
Fei-Fei Li!
Degrees of Freedom
R is 2x2 4 elements
1)det( =
=⋅=⋅
RIRRRR TT
⎥⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡ −=⎥
⎦
⎤⎢⎣
⎡
yx
yx
θθ
θθ
cossinsincos
''
Note: R belongs to the category of normal matrices and satisfies many interesting properties:
19-‐Oct-‐12 32
Reviews - !!!
Fei-Fei Li!
RotaEon+ Scaling +TranslaEon P’= (T R S) P
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡ −
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=⋅⋅⋅=
1yx
1000s000s
1000θcossinθ0inθsθcos
100t10t01
R' y
x
y
x
PSTP
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡ −
=
1yx
1000s000s
100tθcossinθtinθsθcos
y
x
y
x
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎦
⎤⎢⎣
⎡ ʹ′=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡ ʹ′=
1yx
10tSR
1yx
100S
10tR
If sx=sy, this is a similarity transformation!
19-‐Oct-‐12 33
Reviews - !!!
Fei-Fei Li!
TransformaEon in 2D
- Isometries
- Similarities
- Affinity
- Projective
19-‐Oct-‐12 34
Reviews - !!!
Fei-Fei Li!
TransformaEon in 2D
Isometries: ⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎦
⎤⎢⎣
⎡=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
1yx
H1yx
10tR
1'y'x
e
- Preserve distance (areas) - 3 DOF - Regulate motion of rigid object
[Euclideans]
19-‐Oct-‐12 35
Reviews - !!!
Fei-Fei Li!
TransformaEon in 2D
SimilariEes: ⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎦
⎤⎢⎣
⎡=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
1yx
H1yx
10tRs
1'y'x
s
- Preserve - ratio of lengths - angles
- 4 DOF
19-‐Oct-‐12 36
Reviews - !!!
Fei-Fei Li!
TransformaEon in 2D
AffiniEes: ⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎦
⎤⎢⎣
⎡=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
1yx
H1yx
10tA
1'y'x
a
⎥⎦
⎤⎢⎣
⎡=
2221
1211
aaaa
A )(RD)(R)(R φφθ ⋅⋅−⋅= ⎥⎦
⎤⎢⎣
⎡=
y
x
s00s
D
19-‐Oct-‐12 37
Reviews - !!!
Fei-Fei Li!
TransformaEon in 2D
AffiniEes: ⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎦
⎤⎢⎣
⎡=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
1yx
H1yx
10tA
1'y'x
a
⎥⎦
⎤⎢⎣
⎡=
2221
1211
aaaa
A )(RD)(R)(R φφθ ⋅⋅−⋅= ⎥⎦
⎤⎢⎣
⎡=
y
x
s00s
D
- Preserve: - Parallel lines - Ratio of areas - Ratio of lengths on collinear lines - others…
- 6 DOF
19-‐Oct-‐12 38
Reviews - !!!
Fei-Fei Li!
TransformaEon in 2D
ProjecEve: ⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎦
⎤⎢⎣
⎡=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
1yx
H1yx
bvtA
1'y'x
p
- 8 DOF - Preserve:
- cross ratio of 4 collinear points - collinearity - and a few others…
19-‐Oct-‐12 39
Reviews - !!!
Fei-Fei Li!
Agenda
• Basic definiEons and properEes • Geometrical transformaEons
19-‐Oct-‐12 40
Reading: [HZ] Chapter 2, 4