imgl = imread('pic410.bmp');
imgr = imread('pic430.bmp');
[ROWS, COLS, CHANNELS] = size(imgl);
disimg = [imgl imgr];
image(disimg);
Nc = 12;
Nt = 4;
cnt = 1;
hold;
while(cnt <= Nc+Nt)
dR = 20;
dC = 20;
pl = zeros(4,3);
[X, Y] = ginput(1);
Cl = X(1); Rl = Y(1);
pl(cnt,:) = [Cl Rl 1];
Cl= pl(cnt,1); Rl=pl(cnt,2);
rectangle('Curvature', [0 0], 'Position', [Cl Rl dC dR]);
pr = zeros(4,3);
[X, Y] = ginput(1);
Cr = X(1); Rr = Y(1);
pr(cnt,:) = [Cr-COLS Rr 1];
Cr=pr(cnt,1)+COLS; Rr=pr(cnt,2);
rectangle('Curvature', [0 0], 'Position', [Cr Rr dC dR]);
drawnow;
cnt = cnt+1;
end
for cnt=1:1:Nc+Nt,
an = F*pl(cnt,:)';
x = 0:COLS;
y = -(an(1)*x+an(3))/an(2);
x = x+COLS;
plot(pl(cnt,1),pl(cnt,2),'r*');
line(x,y,'Color', 'r');
[X, Y] = ginput(1);
plot(pl(cnt,1),pl(cnt,2),'b*');
line(x,y,'Color', 'b');
end
save F.txt F -ASCII
save eR.txt eRv -ASCII;
save eL.txt eRv -ASCII;
Xvals = Nc(:,1);
Yvals = Nc(:,2);
Zvals = Nc(:,3);
xvals = (fl/Zvals)*Xvals;
yvals = (fl/Zvals)*Xvals;
x1 = xvals(1);
x2 = xvals(6);
x3 = xvals(15);
x4 = xvals(10);
x5 = xvals(20);
x6 = xvals(11);
x7 = xvals(8);
x8 = xvals(17);
x9 = xvals(21);
x10 = xvals(31);
y1 = yvals(1);
y2 = yvals(6);
y3 = yvals(15);
y4 = yvals(10);
y5 = yvals(20);
y6 = yvals(11);
y7 = yvals(8);
y8 = yvals(17);
y9 = yvals(21);
y10 = yvals(31);
xmean = (x1+x2+x3+x4+x5+x6+x7+x8+x9+x10)/10;
ymean = (y1+y2+y3+y4+y5+y6+y7+y8+y9+y10)/10;
hyp = sqrt((xmean)^2+(ymean)^2);
scaling_factor = sqrt(2)/hyp;
T1 = scaling_factor*[1 0 -xmean;0 1 -ymean;0 0 1/scaling_factor];
pl_translated_xval = T1*pl(:,1);
pl_translated_yval = T1*pl(:,2);
yT1 = pl_translated_yval(1);
yT2 = pl_translated_yval(6);
yT3 = pl_translated_yval(15);
yT4 = pl_translated_yval(10);
yT5 = pl_translated_yval(20);
yT6 = pl_translated_yval(11);
yT7 = pl_translated_yval(8);
yT8 = pl_translated_yval(17);
yT9 = pl_translated_yval(21);
yT10 = pl_translated_yval(31);
xT1 = pl_translated_xval(1);
disp(xT1);
xT2 = pl_translated_xval(6);
xT3 = pl_translated_xval(15);
xT4 = pl_translated_xval(10);
xT5 = pl_translated_xval(20);
xT6 = pl_translated_xval(11);
xT7 = pl_translated_xval(8);
xT8 = pl_translated_xval(17);
xT9 = pl_translated_xval(21);
xT10 = pl_translated_xval(31);
A = [];
[U,D,V] = svd(A,0);
V1 = transpose(V);
F1 = V1(:,end);
f11 = F1(1);
f12 = F1(2);
f13 = F1(3);
f21 = F1(4);
f22 = F1(5);
f23 = F1(6);
f31 = F1(7);
f32 = F1(8);
f33 = F1(9);
Xvals1 = Nc(:,1);
Yvals1 = Nc(:,2);
Zvals1 = Nc(:,3);
xvals1 = (fr/Zvals1)*Xvals1;
yvals1 = (fr/Zvals1)*Xvals1;
x1r = xvals1(1);
x2r = xvals1(6);
x3r = xvals1(15);
x4r = xvals1(10);
x5r = xvals1(20);
x6r = xvals1(11);
x7r = xvals1(8);
x8r = xvals1(17);
x9r = xvals1(21);
x10r = xvals1(31);
y1r = yvals1(1);
y2r = yvals1(6);
y3r = yvals1(15);
y4r = yvals1(10);
y5r = yvals1(20);
y6r = yvals1(11);
y7r = yvals1(8);
y8r = yvals1(17);
y9r = yvals1(21);
y10r = yvals1(31);
xmeanr = (x1r+x2r+x3r+x4r+x5r+x6r+x7r+x8r+x9r+x10r)/10;
ymeanr = (y1r+y2r+y3r+y4r+y5r+y6r+y7r+y8r+y9r+y10r)/10;
hypr = sqrt((xmeanr)^2+(ymeanr)^2);
scaling_factor_r = sqrt(2)/hypr;
Tr = scaling_factor_r*[1 0 -xmeanr;0 1 -ymeanr;0 0 1/scaling_factor_r];
Tl = T1;
F = (transpose(Tr))*F1*Tl;
[U1,D1,V2] = svd(F,0);
el = V2(:,something);
er = U1(:,something);
e_xval_r = er(:,1);
e_yval_r = er(:,2);
xnew = Nt(:,1);
ynew = Nt(:,2);
distance = ((e_xval_r*xnew+e_yval_r*ynew)/sqrt(e_xval_r^2+e_yval_r^2));