Computer Vision Assignment
Computer Vision Assignment
Ex. 1 — Let u = [u1 , u2 , 1]T and v = [v1 , v2 , 1]T denote the homogeneous coordinates of points in planes P and
Q, respectively. Matching point pairs are related by a projection matrix H as
vi = Hui , i = 1, 2, . . . , n
(a) A transform from P to Q in the form of a translation by (x0 , x1 ) then a rotation by θ then a scaling by (s0 , s1 )
is described by the matrix
0.951623 0.443749 −6.97686
H = −0.401487 0.860992 −2.29753
0 0 1
Determine the values of (x0 , x1 , s0 , s1 , θ).
(b) A transform from P to Q in the form of a translation by (x0 , x1 ) then a scaling by (s0 , s1 ) then a rotation by θ
is described by the matrix
0.951623 0.401487 −6.76555
H = −0.443749 0.860992 −2.08622
0 0 1
Determine the values of (x0 , x1 , s0 , s1 , θ) for this order transformations.
Answer (ex. 1) — (a) An algebraic expression for the transformation can be formed from the product of trans-
formation matrices.
s0 0 0 cos θ sin θ 0 1 0 x0 s0 cos θ s0 sin θ s0 x0 cos θ + s0 x1 sin θ
H = SRT = 0 s1 0 − sin θ cos θ 0 0 1 x1 = −s1 sin θ s1 cos θ s1 x1 cos θ − s1 x0 sin θ
0 0 1 0 0 1 0 0 1 0 0 1
Therefore
2 2
1/2 1/2
s0 = H1,1 + H1,2 = 0.9516232 + 0.4014872 = 1.05
2 2
1/2 1/2
= 0.4014872 + 0.8609922
s1 = H2,1 + H2,2 = 0.95
x0 = H1,3 cos θ/s0 − H2,3 sin θ/s1 = −5
x1 = H1,3 sin θ/s0 + H2,3 cos θ/s1 = −5
θ = arctan(H1,2 , H1,1 ) ∗ 180/π = 25◦
The parameters can be found by operations similar to those in (a). The results are the same numerical values
given in the solution of (a).
Ex. 2 — Matching pairs of points from P and Q are given by the columns of the arrays U and V below.
21.630 28.280 31.870 46.150 28.230 36.530 24.540 31.940
U = 59.260 62.040 65.310 36.440 50.510 60.200 37.740 57.080
1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000
17.536 23.468 26.280 46.697 25.960 31.992 25.144 28.163
V = 52.587 56.753 60.691 36.368 45.732 56.870 32.699 52.848
1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000
(a) Find a matrix H that maps points from P to Q.
(b) Assume that the mapping is a translation, a scaling, and a rotation in that order. Find the parameters of the
individual transformations.
Answer (ex. 2) — (a) The relationship is of the form V = HU. Use singular value decomposition (SVD) to
find orthogonal matrices Q and R and a diagonal matrix D such that
U = QDRT
V = H QDRT
VR = HQDRT R = HQD
VRD−1 = HQ
VRD−1 QT = H
VU† = H
where U† = RD−1 QT is the pseudo-inverse of U. We can find the SVD of U by using the SVDC routine in
IDL or with a similar tool in other languages. The call is SVDC,U,W,Q,R. For the given matrix,
−0.494630 −0.868995 −0.013726 0.000000 0.000000 0.000000 0.000000 0.000000
Q = −0.868960 0.494774 −0.010402 0.000000 0.000000 0.000000 0.000000 0.000000 = A 0
−0.015831 −0.006782 0.999852 0.000000 0.000000 0.000000 0.000000 0.000000
−0.351525 0.406854 0.249213 −0.805477 0.000000 0.000000 0.000000 0.000000
−0.383762 0.236511 −0.097002 0.256932 −0.442195 −0.329696 −0.518618 −0.384923
−0.409852 0.178415 −0.336917 0.164745 0.155032 −0.322509 0.713437 −0.149986
−0.308007 −0.854216 −0.036460 −0.308334 −0.032379 −0.256078 −0.039941 −0.104058
R=
−0.327007 0.017505 0.250450 0.229042 0.817219 0.004531 −0.320200 −0.084731
−0.397786 −0.076047 −0.368045 0.021316 −0.078106 0.823297 −0.025273 −0.124559
−0.253990 −0.102870 0.778969 0.299897 −0.303097 0.182773 0.317916 −0.042801
−0.369637 0.018537 −0.093088 0.141878 −0.116474 −0.102318 −0.127321 0.891058
V = HU = ASRTa
H = VRa S−1 AT = VU†
where we now have another expression for U† . We would not have to do this partitioning, but it is instructive
to see how the pseudo-inverse works.
−0.351525 0.406854 0.249213
−0.383762 0.236511 −0.097002
−0.409852 0.178415 −0.336917
−0.308007 −0.854216 −0.036460
Ra =
−0.327007 0.017505 0.250450
−0.397786 −0.076047 −0.368045
−0.253990 −0.102870 0.778969
−0.369637 0.018537 −0.093088
−0.494630 −0.868995 −0.013726 0.005651 0.000000 0.000000
A = −0.868960 0.494774 −0.010402 S−1 = 0.000000 0.038685 0.000000
−0.015831 −0.006782 0.999852 0.000000 0.000000 2.880430
0.984108 −0.220440 9.313249
H = VRa S−1 AT = 0.227215 0.954889 −8.914172
0.000000 0.000000 1.000000
(b) The H matrix has the same form as Problem (1b). The solution is
q
s0 = H1,12 + H 2 = 1.01
2,1
q
s1 − H1,22 + H 2 = 0.98
2,2
Ex. 3 — Images LWIR087c.png, MWIR087c.png, SWIR087c.png are provided in the images directory
http://www.cis.rit.edu/class/simg782/images
(a) Find a transformation matrix H1 that maps the MW image to the LW image.
(b) Find a transformation H2 that maps the SW image to the LW image.
(c) Construct two greyscale images by mapping the MW and SW images.
(d) Construct an RGB image by building an array that has the mapped SW, the mapped MW and the original LW
as array layers. This is a raw image array that can be displayed with IDL or other tools.
Answer (ex. 3) — The IDL script below does the calculations. Point matches were constructed in ENVI and
saved as text files. The SWIR image was rotated 180◦ before the matching points were located. The image files that
were produced are shown below.
Mapped MWIR image Rotated and mapped SWIR image
np=10
pts=fltarr(9,np)
readf,1,pts
print,pts,format=’(9(f6.2,1x))’
close,1
Q=transpose([pts[2:3,*],replicate(1.,1,np)])
Q[*,1]=510-Q[*,1]
print,’Matrix Q’
print,Q,format=’(10(f6.2,1x))’
print
disp_image,A,xpos=0,ypos=0,title=’Mapped MWIR’
disp_image,B,TRUE=1,xpos=640,ypos=0,title=’MWIR (G) projected to LWIR (R)’
;========================================================
;Match SWIR to LWIR Section
;========================================================
print
print,’Matching SWIR to LWIR’
print
;Open LWIR to SWIR matching points from an ENVI ground control points table
pname=’L2Spoints.txt’
openr,1,pname
;Read and print 5 header lines
s=’’
for k=0,4 do begin & readf,1,s & print,s & end
print,format=’(3x,3(A3,4x),A3,3x,2(A4,3x),2(A2,5x),A3)’,$
[’LWx’,’LWy’,’SWx’,’SWy’,’L2Sx’,’L2Sy’,’Rx’,’Ry’,’|R|’]
np=10
pts=fltarr(9,np)
readf,1,pts
print,pts,format=’(9(f6.2,1x))’
close,1
print
;Construct the matrix of LWIR points.
;Note: The y-coordinates from ENVI are from top
;so we need to subtract from nrows to make them
;measure from the bottom.
P1=transpose([pts[0:1,*],replicate(1.,1,np)])
P1[*,1]=510-P1[*,1]
print,’Matrix P1’
print,P1,format=’(10(f6.2,1x))’
print
Q1=transpose([pts[2:3,*],replicate(1.,1,np)])
Q1[*,1]=510-Q1[*,1]
print,’Matrix Q1’
print,Q1,format=’(10(f6.2,1x))’
print
SWIR=read_image(’SWIR087cr.png’)
disp_image,A1,xpos=0,ypos=520,title=’Mapped SWIR’
disp_image,B2,TRUE=1,xpos=640,ypos=520,title=’SWIR(B) projected to LWIR(R)’
Matrix Q
40.33 473.00 235.25 15.17 40.33 267.83 583.33 558.00 307.67 339.67
458.83 165.75 33.25 178.17 458.83 438.33 431.50 241.33 270.00 157.33
1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00
Matrix Q1
260.75 252.00 582.25 328.75 92.00 470.50 575.75 132.25 460.75 72.50
130.00 9.25 379.00 227.00 401.50 119.75 217.50 279.75 383.50 41.50
1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00