CMSC 828D: Fundmentls of Computer Vision Homework 4 nstructors: Lrry Dvis, Rmni Duriswmi, Dniel DeMenthon, nd Yinnis loimonos Solution sed on homework sumitted y Hiying Liu. Show y direct clcultion for the 2 y 2 mtrices nd tht nd hve the sme eigenvlues. Does this result hold in generl (i.e. for nd N y N mtrices)? Solution: ssume,. Thus + +. Solve, i.e. + + + + ( ) ( ) ( + ) ( + ) ( ( ))( ( )) ( )( ) + + + + 2 ( + + + ) + + + 2 ( + + + ) + ( + ) + + Similrly,. Solve, i.e. + + ( + ) ( + ) ( + ) ( + ) ( ( ))( ( )) ( )( ) + + + + 2 ( + + + ) + + + 2 + ( + + + ) + ( + ) The ove two equtions re the sme. Therefore, they hve the sme eigenvlues. + The result holds in the generl cse. This cn e proved s follows. Rewrite [ ] form [ ] in the. Notice tht for ny squre mtrix. t cn e verify tht /
2/ ( ) ( ) Thus, we hve ( ) ( ) ( ) ( ) ( ) Eqution Similrly, it cn lso e verified tht ( ) ( ) Thus, we hve ( ) ( ) ( ) ( ) ( ) Eqution 2 Compre [Eqution 2] with [Eqution ], we hve, which implies tht if then, i.e. nd hve the sme eigenvlues. 2. For the 2 y 2 cse otin the reltionship etween the eigenvlues of nd of 2 does the result you otined hold for nd n in generl (i.e. for generl n nd for N y N mtrix)? Solution: ssume tht is n eigenvlue of mtrix, nd is n eigenvlue of mtrix 2. ccording to the definition of eigenvlue, we hve X X nd X X 2. Since is sclr, we hve
Thus, the reltionship etween nd is 2 2 X X X X X X X 2. n This result holds for nd in generl. This cn e proved y induction. The se prt is n n proved s ove. Now ssume tht is n eigenvlue of mtrix, then: Thus, n+ is n eigenvlue of n n n X X X X X n+ n n+ n+. Therefore, if is n eigenvlue of mtrix, n is n eigenvlue of mtrix 3. Red chpter 2.6 of Numericl Recipes. To those who do not hve the ook, you cn find copy on the we t http://li-www.lnl.gov/numericl/ookcpdf/c2-6.pdf. fter you red this, solve the following prolem. The solution of liner eqution x is often represented s x -. s discussed in clss nd in numericl recipes, the eqution cn lso e solved using the singulr vlue decomposition using the expression x +,where + (V S - U t ),where S is the digonl mtrix of singulr vlues. n cse of zero or ner zero, singulr vlues the corresponding elements of S re set to zero. Write Mtl function tht computes the pseudoinverse of given mtrix fter computing its SVD. (Do not use ntive Mtl functions to compute the pseudo inverse. You my use the Mtl svd function.) Find the singulr vlue decomposition nd the pseudoinverse of the following mtrices: ( ),, nd C X n. Solution: See ppix for the Mtl script nd results. 4. Verify the sttement tht the cross-rtio of four points on line remins invrint when the points re mpped to different configurtion y projective trnsformtion (i.e. projectivity,or homogrphy). Solution: We use homogeneous coordintes to express D point. ssume the four points re x x xc xd, x, C 2 x, D 2 x. ccording to the definition of cross-rtio, C 2 xd 2 x det x Notice tht [ ] det C cross (,, C, D). D CD 2 x x 2, we hve det( ) det( C cross(,, C, D) det( D) det( C ) D), 3/
ssume the projective trnsformtion is H. Then the four points fter the trnsformtion re x x xc xd H, H x, C H 2 x, D H 2 x. The cross-rtio of the new points is: C2 xd2 cross(,, C, D ) D det( H ) det det( H ) det det( det( C C D cross(,, C, D) det( H[ ] ) det( H[ D] ) ([ ] ) det( H ) ([ D] ) det( H ) ) det( C D) det( C ) D) det det det det ( H [ C ] ) ( H[ C D] ) ([ C ] ) ([ C D] ) i.e. the cross-rtio remins invrint. The ove prove cn e esily exted to 3D.. root vehicle is equipped with cmer. The cmer imge is rectngle of height 5 pixels nd width 6 pixels. The focl length is 69 pixels. The center of projection C of the cmer is 3 m ove the ground. The opticl xis of the cmer mkes 2 degree ngle with the ground, so tht the cmer looks slightly downwrd towrd the rod. Lrge squres of size 4 m hve een pinted everywhere long the medin lines of rods to fcilitte utomtic vehicle nvigtion. Two of the sides of the squres re prllel to the rod edges. The vehicle is on flt rod where it sees only two squres. The vehicle fces the first squre such tht the opticl xis of the cmer psses through the center of the squre, nd is perpiculr to two sides of the squre. ecuse the rod turns, the next squre is t n ngle with the first squre. The centers of the squres re on circle of rdius meters (which is lso the rdius of the rod turn), nd the rc etween the two centers is degrees. The 4 coordinte systems re selected s follow [Figure ]: coordinte originted t the center of projection, coordinte originted t the center of the first squre, coordinte 2 originted t the center of the second squre, nd the imge coordinte originted t the center of the imge plne. ll coordintes use right-hnd-rule. The x- nd z- xis of coordinte nd 2 re in the rod plne nd prllel to the two sides of the squres respectively. The reltionships etween these coordintes cn e esily estlished y simple rottion nd trnsltion. 4/
coordinte 3m O y x z f 69 pixel y x 5 6 pixel imge coordinte 2 O coordinte y x z R O 2 y coordinte 2 x z Figure : Root nvigtion prolem.. Compute the pixel positions of the imges of the corners of the two squres. Solution: The sic ide of this solution is estlishing the rottion-trnsltion reltionship etween coordinte 2 nd coordinte : rotte round xis y y nd trnslte from O to O 2 ; coordinte nd coordinte : rotte round xis x y 2 nd trnslte from O to O ; coordinte nd imge coordinte: trnsltion nd scling. See the Mtl script for detiled definition of the trnsformtion mtrix for the ove rottion nd trnsltion. The Mtl script nd pixel positions of the imges of the corners of the two squres re listed in ppix.. Mke drwing of the imges of the two squres nd of the rectngulr frme of the imge using Mtl. Solution: The Mtl script is listed in ppix. The imge is s follows: 5/
c. To nvigte, the root computes projectivity (i.e. homogrphy) tht trnsforms the imges of the squres ck to their ctul geometry on the rod,in order to compute how the rod turns. To do tht, it does not use the cmer focl length nd the cmer position with respect to the rod. nsted, it uses its knowledge tht the squres it sees re lwys of size 4 m, nd computes projectivity mtrix using the four corners of the closest squre it sees. Using the imges of the squre corners found in (),compute this mtrix using Mtl. Solution: Define the trnsformtion mtrix s H [ h ij ] 3 3. ssume imge coordinte is [ u v, ] T nd correspondent spce coordinte is [ x, z, s] hve the eqution: x z Notice tht x, z, we hve: s s x h z h s h,,. Note tht the squre is on flt plne. We then 3 h h h 32 h h h 3 23 33 u v 6/
hu + hv + h x h u + h v + 3 hu + hv + h y h u + h v + 3 32 32 3 23 h u + h h u + h v + h 3 v + h 23 h 3 h ux h 3 32 uz h vx x 32 vz z Since we hve 4 correspondent points, we hve 8 equtions, which cn e expressed in the form of h : ui v i u i L v i L u x i u z i i i h h h vi xi M vi zi h h h 3 3 32 33 x z M M. M x4 z 4 Therefore, the H cn e esily solved y. y using the imge corners from () prt, we cn lso clculte the new rod coordinte of the 4 corners of the squre 2. The Mtl script nd result (H ) for this su-prolem re listed in ppix. d. Drw the two reconstructed squres. Compute the rdius of the rod turn. Solution: The reconstructed squres re show s follow [Figure 3]. Once we get the geometry reltionship etween squre nd squre 2, we hve the their position informtion on the rod plne. Then the rc θ etween the two centers of the squres cn e computed y two side of the two squres respectively. Comining with the distnce D etween the two centers, the rdius is D given y. This is illustrted in [Figure 2]. See detils in the Mtl script in ppix. 2sin ( θ 2) θ squre 2 R squre D θ Figure 2: Geometry reltionship of the two squres. 7/
Figure 3: Geometry of the two squres. 8/
ppix: hw4_3.m: function hw4_3 Syntx: hw4_3 Description: Test my_pinv CMSC 828D: Fundmentls of Computer Vision Homework4 nstructors : Lrry Dvis, Rmni Duriswmi, Dniel DeMenthon, nd Yinnis loimonos Student : Hiying Liu Dte : Sept. 23, 2 dstop if error msg nrgchk(,, nrgin); if (~isempty(msg)) error(strct('error:', msg)); cler msg; Prepre record result in file filenme 'hw4_3.txt'; if exist(filenme, 'file') delete(filenme); diry off; diry(filenme); Test disp('------------------------------------'); [ ] disp(':::::::::::::::::::::::::::::::'); disp(': [U, S, V] svd() returns: :'); disp(':::::::::::::::::::::::::::::::'); [U, S, V] svd() disp(':::::::::::::::::::::::'); disp(': my_pinv() returns: :'); disp(':::::::::::::::::::::::'); my_pinv() Test disp('---------'); [ ; ] disp(':::::::::::::::::::::::::::::::'); 9/
disp(': [U, S, V] svd() returns: :'); disp(':::::::::::::::::::::::::::::::'); [U, S, V] svd() disp(':::::::::::::::::::::::'); disp(': my_pinv() returns: :'); disp(':::::::::::::::::::::::'); my_pinv() Test C disp('---------'); C [ ; ] disp(':::::::::::::::::::::::::::::::'); disp(': [U, S, V] svd(c) returns: :'); disp(':::::::::::::::::::::::::::::::'); [U, S, V] svd(c) disp(':::::::::::::::::::::::'); disp(': my_pinv(c) returns: :'); disp(':::::::::::::::::::::::'); my_pinv(c) Stop recording diry off; my_pinv.m: function result my_pinv(m) Syntx: result my_pinv(m) Description: Compute the pseudoinverse of given mtrix y SVD CMSC 828D: Fundmentls of Computer Vision Homework4 nstructors : Lrry Dvis, Rmni Duriswmi, Dniel DeMenthon, nd Yinnis loimonos Student : Hiying Liu Dte : Sept. 23, 2 dstop if error msg nrgchk(,, nrgin); if (~isempty(msg)) error(strct('error:', msg)); cler msg; Do the SVD [U, S, V] svd(m); /
Compute pseudoinverse mtrix of M nrow size(s, ); ncol size(s, 2); S_inv zeros(ncol, nrow); nelement min(nrow, ncol); for index :nelement entry S(index, index); if entry ~ S_inv(index, index)./ entry; result V * S_inv * U'; Result from my_pinv.m: ------------------------------------ ::::::::::::::::::::::::::::::: : [U, S, V] svd() returns: : ::::::::::::::::::::::::::::::: U S 2 V.5 -.866.5.2887 -.5774 -.5774.5.2887.7887 -.23.5.2887 -.23.7887 ::::::::::::::::::::::: : my_pinv() returns: : ::::::::::::::::::::::: ns.25.25.25.25 --------- /
::::::::::::::::::::::::::::::: : [U, S, V] svd() returns: : ::::::::::::::::::::::::::::::: U S V ::::::::::::::::::::::: : my_pinv() returns: : ::::::::::::::::::::::: ns --------- C ::::::::::::::::::::::::::::::: : [U, S, V] svd(c) returns: : ::::::::::::::::::::::::::::::: U S /
.442 V.77 -.77.77.77 ::::::::::::::::::::::: : my_pinv(c) returns: : ::::::::::::::::::::::: ns.5.5 hw4_5.m: function hw4_5 Syntx: hw4_5 Description: Root nvigtion prolem. CMSC 828D: Fundmentls of Computer Vision Homework4 nstructors : Lrry Dvis, Rmni Duriswmi, Dniel DeMenthon, nd Yinnis loimonos Student : Hiying Liu Dte : Sep. 23, 2 dstop if error msg nrgchk(,, nrgin); if (~isempty(msg)) error(strct('error:', msg)); cler msg; Turn on the diry to sve the result. filenme 'hw4_5.txt'; if (exist(filenme, 'file')) delete(filenme); diry off; evl(['diry ', filenme]); 3/
disp('» hw4_5'); Prt. Define corners of squre in coordinte 2 squre_corners [... +2 2 ;... +2-2 ;... -2-2 ;... -2 2 ;... ]; Define corners of squre 2 in coordinte squre2_corners [... +2 2 ;... +2-2 ;... -2-2 ;... -2 2 ;... ]; Convert squre corners to imge plne ncorners size(squre_corners, ); imge_corners zeros(ncorners, 3); Mtomge Mto Mtomge coordtomge; coordto; Mtomge * Mto; for index :ncorners point squre_corners(index, :)'; imge_corners(index, :) (Mtomge * point)'; scle imge_corners(index, 3); imge_corners(index, :) imge_corners(index, :)./ scle; Convert squre 2 corners to imge plne ncorners2 size(squre2_corners, ); imge_corners2 zeros(ncorners2, 3); M2to M2tomge coord2to; Mtomge * Mto * M2to; for index :ncorners2 point squre2_corners(index, :)'; imge_corners2(index, :) (M2tomge * point)'; scle imge_corners2(index, 3); imge_corners2(index, :) imge_corners2(index, :)./ scle; Disply the imge coordintes of corners. disp(' '); disp(':::::::::::::::::::::::::::::::::::::::::::::'); disp(':: mge coordinte of corners of squre ::'); disp(':::::::::::::::::::::::::::::::::::::::::::::'); disp(' '); disp('id x y'); 4/
disp('-----+----------------------'); for index :ncorners disp([num2str(index), ' ',... num2str(imge_corners(index, ), '3.4f'), ' ',... num2str(imge_corners(index, 2), '3.4f')]); disp(' '); disp(':::::::::::::::::::::::::::::::::::::::::::::'); disp(':: mge coordinte of corners of squre 2 ::'); disp(':::::::::::::::::::::::::::::::::::::::::::::'); disp(' '); disp('id x y'); disp('-----+----------------------'); for index :ncorners2 disp([num2str(index), ' ',... num2str(imge_corners2(index, ), '3.4f'), ' ',... num2str(imge_corners2(index, 2), '3.4f')]); disp(' '); Prt. Drw the two squres in the imge plne imge_corners [imge_corners; imge_corners(, :)]; imge_corners2 [imge_corners2; imge_corners2(, :)]; left ; right 6; up ; ottom 5; figure; xis ij; xis equl; xis([left, right, up, ottom]); hold on; xlel('x'); ylel('y'); title('root vision of the rod');.. Drw frme plot([left, right, right, left, left], [up, up, ottom, ottom, up], 'k');.. Drw corners for squre plot(imge_corners(:, ), imge_corners(:, 2)); fill(imge_corners(:, ), imge_corners(:, 2), 'k');.. Drw corners for squre 2 plot(imge_corners2(:, ), imge_corners2(:, 2)); fill(imge_corners2(:, ), imge_corners2(:, 2), 'k'); print -djpeg hw4_5_ 5/
Prt c. Construct nd for x squre_corners_xz [... +2 2 ;... +2-2 ;... -2-2 ;... -2 2 ;... ]; zeros(8); for index :ncorners rod_corner squre_corners_xz(index, :); x rod_corner(); z rod_corner(2); imge_corner imge_corners(index, :); u imge_corner(); v imge_corner(2); row [u, v,,,,, -u * x, -v * x]; row2 [,,, u, v,, -u * z, -v * z]; (2 * index -, :) row; (2 * index, :) row2; (2 * index -, :) x; (2 * index, :) z; HH inv() * ; H zeros(3, 3); H(, ) HH(); H(, 2) HH(2); H(, 3) HH(3); H(2, ) HH(4); H(2, 2) HH(5); H(2, 3) HH(6); H(3, ) HH(7); H(3, 2) HH(8); H(3, 3) ; disp(' '); disp('::::::::::::::::::::::::::::::::::::::::::::::::::::'); disp(':: Trnsformtion mtrix (from imge to geometry) ::'); disp('::::::::::::::::::::::::::::::::::::::::::::::::::::'); H Prt d. Clculte geometry for squre 2. squre2_corners_xz zeros(ncorners2, 3); for index :ncorners2 imge_corner imge_corners2(index, :); squre2_corners_xz(index, :) (H * imge_corner')'; squre2_corners_xz(index, :)... squre2_corners_xz(index, :)./ squre2_corners_xz(index, 3); 6/
squre_corners_xz [squre_corners_xz; squre_corners_xz(, :)]; squre2_corners_xz [squre2_corners_xz; squre2_corners_xz(, :)]; Drw the two squres. figure hold on; xis equl; xlel('-x'); ylel('z'); title('geometry of the two squres'); plot(-squre_corners_xz(:, ), squre_corners_xz(:, 2), 'k'); fill(-squre_corners_xz(:, ), squre_corners_xz(:, 2), 'k'); plot(-squre2_corners_xz(:, ), squre2_corners_xz(:, 2), 'k'); fill(-squre2_corners_xz(:, ), squre2_corners_xz(:, 2), 'k'); print -djpeg hw4_5_2; Clculte rdius. center_x (squre_corners_xz(, ) + squre_corners_xz(3, ))./ 2; center_z (squre_corners_xz(, 2) + squre_corners_xz(3, 2))./ 2; center [center_x; center_z]; center2_x (squre2_corners_xz(, ) + squre2_corners_xz(3, ))./ 2; center2_z (squre2_corners_xz(, 2) + squre2_corners_xz(3, 2))./ 2; center2 [center2_x; center2_z]; distnce norm(center - center2); Clculte rc. vector squre_corners_xz(, :) - squre_corners_xz(2, :); vector(, 3) ; vector vector./ norm(vector); vector2 squre2_corners_xz(, :) - squre2_corners_xz(2, :); vector2(, 3) ; vector2 vector2./ norm(vector2); sin_thet cos_thet cross(vector, vector2) * [,, ]'; vector * vector2'; sin_thet_y2 sqrt(( - cos_thet) / 2); Clculte rdius. disp('::::::::::::'); disp(':: Rdius ::'); disp('::::::::::::'); rdius (distnce./ 2) / sin_thet_y2 Turn off diry. diry off; coord2to.m: 7/
function M coord2to Syntx: M coord2to Description: Compute mtrix tht converts the point from coordinte 2 to uthor: Hiying Liu Dte : Sep. 24, 2 dstop if error msg nrgchk(,, nrgin); if (~isempty(msg)) error(strct('error:', msg)); cler msg; rdius ; thet * pi / 8; thet_y -thet; sin_thet_y2 sin(thet / 2); cos_thet_y2 cos(thet / 2); delt_x - 2 * rdius * sin_thet_y2 * sin_thet_y2; delt_y ; delt_z + 2 * rdius * sin_thet_y2 * cos_thet_y2; Mt Mr M trnslte3d(delt_x, delt_y, delt_z); rotte3dy(thet_y); Mt * Mr; coordto.m: function M coordto Syntx: M coordto Description: Compute mtrix tht converts the point from coordinte to uthor: Hiying Liu Dte : Sep. 24, 2 dstop if error 8/
msg nrgchk(,, nrgin); if (~isempty(msg)) error(strct('error:', msg)); cler msg; thet_x 2 * pi / 8; delt_x ; delt_y ; delt_z 3./ sin(thet_x); Mt Mr M trnslte3d(delt_x, delt_y, delt_z); rotte3dx(thet_x); Mt * Mr; coordtomge.m: function M coordtomge Syntx: M coordtomge Description: Convert the point from coordinte to imge plne uthor: Hiying Liu Dte : Sep. 24, 2 dstop if error msg nrgchk(,, nrgin); if (~isempty(msg)) error(strct('error:', msg)); cler msg; nitiliztion. f 69; ku -; kv -; u 3; v 25; M [... f * ku,, u, ;..., f * kv, v, ;... 9/
,,, ;... ]; trnslte3d.m: function M trnslte3d(x, y, z) Returns mtrix tht performs 3-D trnsltion. M eye(4); M(,4) x; M(2,4) y; M(3,4) z; rotte3dx.m: function M rotte3dx(thet) Returns mtrix tht performs rottion out the X xis 3-D rottion mtrix M eye(4); M(2,2) cos(thet); M(3,3) M(2,2); M(2,3) sin(thet); M(3,2) -M(2,3); rotte3dy.m: function M rotte3dy(thet) Returns mtrix tht performs rottion out the Y xis 3-D rottion mtrix M eye(4); M(,) cos(thet); M(3,3) M(,); M(,3) sin(thet); M(3,) -M(,3); Result from hw4_5.m:» hw4_5 ::::::::::::::::::::::::::::::::::::::::::::: :: mge coordinte of corners of squre :: ::::::::::::::::::::::::::::::::::::::::::::: 2/
id x y -----+---------------------- 7.43 25.6852 2 99.7687 38.4832 3 5.233 38.4832 4 429.5678 25.6852 ::::::::::::::::::::::::::::::::::::::::::::: :: mge coordinte of corners of squre 2 :: ::::::::::::::::::::::::::::::::::::::::::::: id x y -----+---------------------- 297.39 79.65 2 276.6427 92.34 3 394.69 95.52 4 399.4584 8.6324 :::::::::::::::::::::::::::::::::::::::::::::::::::: :: Trnsformtion mtrix (from imge to geometry) :: :::::::::::::::::::::::::::::::::::::::::::::::::::: H.e+3 * -.28..845. -.82 2.48..9. :::::::::::: :: Rdius :: :::::::::::: rdius. /