cannot understand why my points in a graph are not working

3 views (last 30 days)
this is my entire code. the code is generating 2 picture, 1 right and 1 left. i am given that control points are correspondence points which will be used to figure out fundamental matrix. there are 12 control points i wish to take the control points as input for forming an equation. but my program is not displaying anything. it is not displaying any point. i am giving my entire code.
%%Note: Please do not delete the commented part of the code.
%%I am going to use it to test your program
%%=============================================================
%%Read in two images
imgl = imread('pic410.bmp');
imgr = imread('pic430.bmp');
%%display image pair side by side
[ROWS, COLS, CHANNELS] = size(imgl);
disimg = [imgl imgr];
image(disimg);
% You can change these two numbers,
% but use the variables; I will use them
% to load my data to test your algorithms
% Total Number of control points
Nc = 12;
% Total Number of test points
Nt = 4;
%%After several runs, you may want to save the point matches
%%in files (see below and then load them here, instead of
%%clicking many point matches every time you run the program
%%load pl.mat pl;
%%load pr.mat pr;
%%interface for picking up both the control points and
%%the test points
cnt = 1;
hold;
while(cnt <= Nc+Nt)
%%size of the rectangle to indicate point locations
dR = 20;
dC = 20;
%%pick up a point in the left image and display it with a rectangle....
%%%if you loaded the point matches, comment the point picking up (3 lines)%%%
pl = zeros(4,3);
[X, Y] = ginput(1);
Cl = X(1); Rl = Y(1);
pl(cnt,:) = [Cl Rl 1];
%%and draw it
Cl= pl(cnt,1); Rl=pl(cnt,2);
rectangle('Curvature', [0 0], 'Position', [Cl Rl dC dR]);
%%and then pick up the correspondence in the right image
%%%if you loaded the point matches, comment the point picking up (three lines)%%%
pr = zeros(4,3);
[X, Y] = ginput(1);
Cr = X(1); Rr = Y(1);
pr(cnt,:) = [Cr-COLS Rr 1];
%%draw it
Cr=pr(cnt,1)+COLS; Rr=pr(cnt,2);
rectangle('Curvature', [0 0], 'Position', [Cr Rr dC dR]);
%plot(Cr+COLS,Rr,'r*');
drawnow;
cnt = cnt+1;
end
%%Student work (1a) NORMALIZATION: Page 156 of the textbook and Ex 7.6
%%--------------------------------------------------------------------
%%Normalize the coordinates of the corresponding points so that
%%the entries of A are of comparable size
%%You do not need to do this, but if you cannot get correct
%%result, you may want to use this
%%END NORMALIZATION %%
%%Student work: (1b) Implement EIGHT_POINT algorithm, page 156
%%--------------------------------------------------------------------
%%Generate the A matrix
%%Singular value decomposition of A
%%the estimate of F
% Undo the coordinate normalization if you have done normalization
%%END of EIGHT_POINT
%%Draw the epipolar lines for both the controls points and the test
%%points, one by one; the current one (* in left and line in right) is in
%%red and the previous ones turn into blue
%%I suppose that your Fundamental matrix is F, a 3x3 matrix
%%Student work (1c): Check the accuray of the result by
%%measuring the distance between the estimated epipolar lines and
%%image points not used by the matrix estimation.
%%You can insert your code in the following for loop
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); %%the location doesn't matter, press mouse to continue...
plot(pl(cnt,1),pl(cnt,2),'b*');
line(x,y,'Color', 'b');
end
%%Save the corresponding points for later use... see discussions above
%save pr.mat pr;
%save pl.mat pl;
%%Save the F matrix in ascii
save F.txt F -ASCII
% Student work (1d): Find epipoles using the EPIPOLES_LOCATION algorithm page. 157
%%--------------------------------------------------------------------
%%save the eipoles
save eR.txt eRv -ASCII;
save eL.txt eRv -ASCII;
% Student work (2). Feature-based stereo matching
%%--------------------------------------------------------------------
%%Try to use the epipolar geometry derived from (1) in searching
%%correspondences along epipolar lines in Question (2). You may use
%%a similar interface as I did for question (1). You may use the point
%%match searching algorithm in (1) (if you have done so), but this
%%time you need to constrain your search windows along the epipolar lines.
% question 4..part 1.....part 1
%input n points where n = 10
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);
%finsing the mean value of x values and y values
xmean = (x1+x2+x3+x4+x5+x6+x7+x8+x9+x10)/10;
ymean = (y1+y2+y3+y4+y5+y6+y7+y8+y9+y10)/10;
%finsing the scalling factor
hyp = sqrt((xmean)^2+(ymean)^2);
scaling_factor = sqrt(2)/hyp;
%forming the 3x3 translation matrix
T1 = scaling_factor*[1 0 -xmean;0 1 -ymean;0 0 1/scaling_factor];
%translating all points
pl_translated_xval = T1*pl(:,1);
pl_translated_yval = T1*pl(:,2);
%displaying normalized points
%when we are normalizing the points by translating with respect to a
%translation matrix then the algorithm is determining the 10 points
%corresponsing to 10 pl. so here given a stereo point determining 10 point
%matches.
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 = [];%confusion what to do?
[U,D,V] = svd(A,0);
% as F is (f11;f12;f13;f21;f22;f23;f31;f32;f33)
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);
%finsing the mean value of x values and y values
xmeanr = (x1r+x2r+x3r+x4r+x5r+x6r+x7r+x8r+x9r+x10r)/10;
ymeanr = (y1r+y2r+y3r+y4r+y5r+y6r+y7r+y8r+y9r+y10r)/10;
%finsing the scalling factor
hypr = sqrt((xmeanr)^2+(ymeanr)^2);
scaling_factor_r = sqrt(2)/hypr;
%forming the 3x3 translation matrix
Tr = scaling_factor_r*[1 0 -xmeanr;0 1 -ymeanr;0 0 1/scaling_factor_r];
Tl = T1;
% F = regular fundamental matrix
F = (transpose(Tr))*F1*Tl;
[U1,D1,V2] = svd(F,0);
el = V2(:,something);%confusion
er = U1(:,something);%confusion
e_xval_r = er(:,1);%x and y coordinate of the epipole
e_yval_r = er(:,2);
%epipolar line e_xval_r*x+e_yval_r*y = 0;
%distance between epipolar line and image point xnew and ynew is
xnew = Nt(:,1);
ynew = Nt(:,2);
distance = ((e_xval_r*xnew+e_yval_r*ynew)/sqrt(e_xval_r^2+e_yval_r^2));
%WHOLE THIS QUESTION IS CONFUSION
it is also showing an error
Error using ginput (line 112)
Interrupted by figure deletion
Error in assignment4 (line 48)
[X, Y] = ginput(1);
please let me know who to solve this...thanx in advance
  1 Comment
Sat m
Sat m on 26 Apr 2013
this is my question, i am working according to this
(1). Fundamental Matrix. - Design and implement a program that , given a stereo pair, determines at least eight point matches, then recovers the fundamental matrix (10 points ) and the location of the epipoles (5 points). Check the accuracy of the result by measuring the distance between the estimated epipolar lines and image points not used by the matrix estimation (5 points). Also, overlay the epipolar lines of control points and test points on one of the images (say Image 1- I already did this in the starting code below). Control points are the correspondences (matches) used in computing the fundamental matrix, and test points are those used to check the accuracy of the computation.
Hint: As a first step, you can pick up the matches of both the control points and the test points manually. You may use my matlab code (FmatGUI.m) as a starting point - where I provided an interface to pick up point matches by mouse clicks. The epipolar lines should be (almost) parallel in this stereo pair. If not, something is wrong either with your code or the point matches. Make sure this is achieved before you move to the second step - that is to try to search for point matches automatically by your program ( 10 points)

Sign in to comment.

Answers (2)

Jan
Jan on 26 Apr 2013
What kind of answer do you expect?
I suggest to use the debugger to find out, what's going on inside the program: Set some breakpoints an let the program run again. Step through the code line by line and check the conditions in the relevant part of the code, wher you expect the program to have a different behaviour.

Fahad Rahman
Fahad Rahman on 8 Dec 2019
its working

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!