Linear Algebra Review Why do we need Linear Algebra? • We will associate coordinates to – 3D points in the scene – 2D points in the CCD array – 2D points in the image • Coordinates will be used to – Perform geometrical transformations – Associate 3D with 2D points • Images are matrices of numbers – We will find properties of these numbers 6/27/2016 Octavia I. Camps 2 Matrices Anm a11 a12 a 21 a22 a31 a32 an1 an 2 Example: 6/27/2016 a1m a2 m a3m anm Sum: Cnm Anm Bnm cij aij bij A and B must have the same dimensions 2 5 6 2 8 7 3 1 1 5 4 6 Octavia I. Camps 3 Matrices Product: Cn p Anm Bm p m cij aik bkj A and B must have compatible dimensions Ann Bnn Bnn Ann k 1 Examples: 2 5 6 2 17 29 3 1.1 5 19 11 6/27/2016 6 2 2 5 18 32 1 5.3 1 17 10 Octavia I. Camps 4 Matrices Transpose: Cmn A nm cij a ji ( A B) A B T If AT A T T ( AB) B A T T T A is symmetric Examples: T T 6 2 6 1 1 5 2 5 6/27/2016 T 6 2 1 5 6 1 3 2 5 8 3 8 Octavia I. Camps 5 Matrices Determinant: A must be square a11 a12 a11 a12 det a11a22 a21a12 a21 a22 a21 a22 a11 a12 det a21 a22 a31 a32 a13 a22 a23 a11 a32 a33 Example: 2 5 det 2 15 13 3 1 6/27/2016 a23 a33 a12 a21 a23 a31 a33 Octavia I. Camps a13 a21 a22 a31 a32 6 Matrices Inverse: Ann A A must be square 1 nn A 1 nn 1 Ann I a11 a12 1 a a a11a22 a21a12 21 22 a22 a12 a a 21 11 1 Example: 6 2 1 5 2 1 5 28 1 6 1 6 2 6 2 1 5 2 6 2 1 28 0 1 0 1 5 .1 5 28 1 6 .1 5 28 0 28 0 1 6/27/2016 Octavia I. Camps 7 2D Vector x2 v ( x1 , x2 ) Magnitude: || v || x1 x2 If || v || 1 , v 2 2 P v x1 Is a UNIT vector x1 v x2 Is a unit vector , || v || || v || || v || Orientation: 6/27/2016 x2 tan x1 Octavia I. Camps 1 8 Vector Addition v w ( x1 , x2 ) ( y1 , y2 ) ( x1 y1 , x2 y2 ) v 6/27/2016 V+w w Octavia I. Camps 9 Vector Subtraction v w ( x1 , x2 ) ( y1 , y2 ) ( x1 y1 , x2 y2 ) v 6/27/2016 V-w w Octavia I. Camps 10 Scalar Product av a( x1 , x2 ) (ax1 , ax2 ) av v 6/27/2016 Octavia I. Camps 11 Inner (dot) Product v w v.w ( x1 , x2 ).( y1 , y2 ) x1 y1 x2 . y2 The inner product is a SCALAR! v.w ( x1 , x2 ).( y1 , y2 ) || v || || w || cos v.w 0 v w 6/27/2016 Octavia I. Camps 12 Orthonormal Basis P x2 j v i x1 v ( x1 , x2 ) i (1,0) || i || 1 j (0,1) || j || 1 ij 0 v x1.i x2 .j v.i ( x1.i x2 .j).i x1.1 x2 .0 x1 v.j ( x1.i x2 .j).j x1.0 x2 .1 x2 6/27/2016 Octavia I. Camps 13 Vector (cross) Product u w u v w v Magnitude: Orientation: 6/27/2016 The cross product is a VECTOR! || u || || v.w |||| v ||| w || sin u v u v (v w) v 0 u w u w (v w) w 0 Octavia I. Camps 14 Vector Product Computation k (0,0,1) j (0,1,0) || k || 1 || j || 1 i (1,0,0) || i || 1 i j 0, i k 0, j k 0 u v w ( x1 , x2 , x3 ) ( y1 , y2 , y3 ) i j k u w u x1 x2 x3 v y1 y2 y3 ( x2 y3 x3 y2 )i ( x3 y1 x1 y3 ) j ( x1 y2 x2 y1 )k 6/27/2016 Octavia I. Camps 15 2D Geometrical Transformations 2D Translation P’ t P 6/27/2016 Octavia I. Camps 17 2D Translation Equation ty P P’ t P ( x, y ) t (t x , t y ) y x tx P' ( x t x , y t y ) Pt 6/27/2016 Octavia I. Camps 18 2D Translation using Matrices ty P P’ t y x 6/27/2016 P ( x, y ) t (t x , t y ) t tx x x t x 1 0 t x P' y y t y 0 1 t y 1 Octavia I. Camps P 19 Homogeneous Coordinates • Multiply the coordinates by a non-zero scalar and add an extra coordinate equal to that scalar. For example, ( x, y ) ( x z , y z , z ) z 0 ( x, y, z ) ( x w, y w, z w, w) w 0 • NOTE: If the scalar is 1, there is no need for the multiplication! 6/27/2016 Octavia I. Camps 20 Back to Cartesian Coordinates: • Divide by the last coordinate and eliminate it. For example, ( x, y , z ) z 0 ( x / z , y / z ) ( x, y, z, w) w 0 ( x / w, y / w, z / w) 6/27/2016 Octavia I. Camps 21 2D Translation using Homogeneous Coordinates ty P P’ t y x tx P ( x, y ) ( x, y,1) t (t x , t y ) (t x , t y ,1) P x t x 1 0 t x x P' y t y 0 1 t y y 1 0 0 1 1 P' T P 6/27/2016 t Octavia I. Camps T 22 Scaling P’ P 6/27/2016 Octavia I. Camps 23 Scaling Equation P’ Sy.y P ( x, y ) ( x, y,1) P' ( s x x, s y y ) ( s x x, s y y,1) P y x 6/27/2016 Sx.x sx x sx P' s y y 0 1 0 0 sy P' S P S Octavia I. Camps 0 0 x 0 y 1 1 24 Scaling & Translating S P’’=T.P P’=S.P T P P’’=T.P’=T.(S.P)=(T.S).P 6/27/2016 Octavia I. Camps 25 Scaling & Translating P’’=T.P’=T.(S.P)=(T.S).P 1 0 t x s x 0 P ' ' T S P 0 1 t y 0 s y 0 0 1 0 0 sx 0 t x x sx x t x 0 s y t y y s y y t y 0 0 1 1 1 6/27/2016 Octavia I. Camps 0 x 0 y 1 1 26 Translating & Scaling Scaling & Translating P’’=S.P’=S.(T.P)=(S.T).P s x 0 0 1 0 t x x P' ' S T P 0 s y 0 0 1 t y y 0 0 1 0 0 1 1 sx 0 sxt x x sx x sxt x 0 s y s yt y y s y y s yt y 0 0 1 1 1 6/27/2016 Octavia I. Camps 27 Rotation P P’ 6/27/2016 Octavia I. Camps 28 Rotation Equations Counter-clockwise rotation by an angle Y’ P’ P y X’ 6/27/2016 x' cos y ' sin x sin x cos y P' R.P Octavia I. Camps 29 Degrees of Freedom x' cos y ' sin R is 2x2 sin x cos y 4 elements BUT! There is only 1 degree of freedom: The 4 elements must satisfy the following constraints: R RT RT R I det( R ) 1 6/27/2016 Octavia I. Camps 30 Scaling, Translating & Rotating Order matters! P’ = S.P P’’=T.P’=(T.S).P P’’’=R.P”=R.(T.S).P=(R.T.S).P R.T.S R.S.T T.S.R … 6/27/2016 Octavia I. Camps 31 3D Rotation of Points Rotation around the coordinate axes, counter-clockwise: Y’ P’ P y X’ z 6/27/2016 0 1 Rx ( ) 0 cos 0 sin x sin cos 0 sin 1 0 0 cos cos R y ( ) 0 sin cos sin Rz ( ) sin cos 0 0 Octavia I. Camps 0 0 0 1 32 3D Rotation (axis & angle) n n1 n2 n3 , angle T n12 R I cos I(1 cos ) n1n2 n n 1 3 6/27/2016 n1n2 2 n2 n2 n3 n1n3 0 n2 n3 sin n3 2 n2 n3 Octavia I. Camps n3 0 n1 33 n2 n1 0 3D Translation of Points Translate by a vector t=(tx,ty,tx)T: P’ t Y’ z’ z x’ P x 1 0 T 0 0 0 0 tx 1 0 ty 0 1 tz 0 0 1 y 6/27/2016 Octavia I. Camps 34