0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 function demo_epipolar_geometry()
0054
0055 addpath(genpath('../../General-Functions'))
0056 addpath('../Functions')
0057 addpath(genpath('../Data'))
0058
0059 ss = plot_init();
0060 close all
0061
0062
0063 plot_params.magnification_m = 300;
0064 plot_params.magnification = 3;
0065
0066
0067
0068 image_pair = 1;
0069
0070
0071
0072
0073 readX = 1;
0074
0075
0076
0077
0078 cov_im = 1;
0079
0080
0081 switch image_pair
0082 case 1
0083
0084 Image_name_l = 'IMG_9473.JPG';
0085 Image_name_r = 'IMG_9474.JPG';
0086 plot_params.magnification_m = 200;
0087 plot_params.magnification = 4;
0088 case 2
0089
0090 Image_name_l = '008.JPG';
0091 Image_name_r = '009.JPG';
0092 plot_params.magnification_m = 100;
0093 plot_params.magnification = 1;
0094 case 3
0095
0096 Image_name_l = 'IMG_1936.JPG';
0097 Image_name_r = 'IMG_1937.JPG';
0098 plot_params.magnification_m = 300;
0099 plot_params.magnification = 6;
0100 case 4
0101
0102 Image_name_l = 'IMG_9473-bw.JPG';
0103 Image_name_r = 'IMG_9474-bw.JPG';
0104 plot_params.magnification_m = 200;
0105 plot_params.magnification = 4;
0106 case 5
0107
0108 Image_name_l = '1336-34.jpg';
0109 Image_name_r = '1336-95.jpg';
0110 plot_params.magnification_m = 200;
0111 plot_params.magnification = 2;
0112 case 6
0113
0114 Image_name_l= '1337-1.jpg';
0115 Image_name_r = '1337-2.jpg';
0116 plot_params.magnification_m = 200;
0117 plot_params.magnification = 2;
0118 otherwise
0119 disp('wrong number of image pair')
0120 end
0121
0122
0123
0124
0125 plot_params.f1 = 9;
0126 plot_params.f2 = 4;
0127
0128 im_path = '../Data/images/';
0129 pt_path = '../Data/ObservedImageCoordinates/';
0130
0131
0132 structure_tensor_params.tau = 0.7;
0133 structure_tensor_params.sigma = 3;
0134 structure_tensor_params.integration_width = ceil(1.5*structure_tensor_params.sigma)*2+1;
0135 structure_tensor_params.sigma_n = 0.03;
0136
0137
0138 sugr_INIT
0139
0140
0141 Image_l = imread(fullfile(im_path,Image_name_l));
0142 Image_r = imread(fullfile(im_path,Image_name_r));
0143 coordinate_name = fullfile(pt_path,Image_name_l(1:end-4));
0144
0145
0146
0147 f1 = figure('name','Left image');
0148 imshow(Image_l);
0149 set(f1,'Position',[0 ss(2)/2.4 ss(1)/2 ss(2)/2]);
0150
0151 f2 = figure('name','Right image');
0152 imshow(Image_r);
0153 set(f2,'Position',[ss(1)/2 ss(2)/2.4 ss(1)/2 ss(2)/2]);
0154
0155 if readX == 0
0156
0157 [x1, x2] = measure_homologeous_Points(f1, f2, Image_l, Image_r, 8);
0158
0159 if x1 == -1
0160 error('Not enough points. We need at least 8 homologeous points!')
0161 return
0162 end
0163
0164 X = [x1', x2'];
0165
0166 save(coordinate_name,'X');
0167
0168 else
0169
0170 load(coordinate_name,'X');
0171
0172 N = size(X,1);
0173
0174 figure(f1)
0175 hold on
0176 for n = 1:N
0177 plot_square_with_background(X(n,1),X(n,2),100,plot_params.f1,plot_params.f2);
0178 end
0179
0180 figure(f2)
0181 hold on
0182 for n = 1:N
0183 plot_square_with_background(X(n,3),X(n,4),100,plot_params.f1,plot_params.f2);
0184 end
0185 end
0186
0187
0188
0189
0190
0191 Cxx = [ ones(8,1),zeros(8,4),ones(8,1),...
0192 zeros(8,4),ones(8,1),zeros(8,4),ones(8,1) ]...
0193 /12;
0194
0195
0196 [F,Cff,el,Cll,er,Crr] = sugr_estimate_F_and_epipoles_algebraically(X,Cxx);
0197
0198
0199
0200
0201
0202 f3 = figure('name','Left image');
0203 imshow(Image_l);
0204 set(f3,'Position',[0 0 ss(1)/2 ss(2)/2]);
0205 hold on
0206 plot_epipole(f3,el,Cll,plot_params)
0207
0208 f4 = figure('name','Right image');
0209 imshow(Image_r);
0210 set(f4,'Position',[ss(1)/2 0 ss(1)/2 ss(2)/2]);
0211 hold on
0212 plot_epipole(f4,er,Crr,plot_params)
0213
0214
0215 while true
0216
0217 disp('Measure point in Figure 3 to see epipolar line in Figure 4.')
0218 disp('Press right mouse button to exit')
0219
0220
0221
0222 x = measure_Point(f3, Image_l);
0223
0224 if x == -1
0225 title('Interactively stopped')
0226 disp('Interactively stopped')
0227 break
0228 end
0229
0230 [im_window, success] = get_image_window(Image_l, x, structure_tensor_params.integration_width);
0231
0232 if success==1
0233
0234 if cov_im == 0
0235 Cov = eye(2)/12;
0236 std_xy = sqrt(diag(Cov)');
0237 else
0238 T = structure_tensor(im_window,...
0239 structure_tensor_params.tau,...
0240 structure_tensor_params.sigma);
0241
0242 Cov = structure_tensor_params.sigma_n^2 * ...
0243 inv( T * structure_tensor_params.integration_width^2 ...
0244 + eye(2)*10^(-6) );
0245 std_xy = sqrt(diag(Cov)');
0246 end
0247 disp(['standard deviations xy in pixel: ', num2str(std_xy)])
0248
0249
0250 plot_epipole(f3,el,Cll,plot_params)
0251
0252
0253 plot_ellipse_mc(x, Cov*plot_params.magnification_m^2,'-k',plot_params.f1);
0254 plot_ellipse_mc(x, Cov*plot_params.magnification_m^2,'-y',plot_params.f2);
0255
0256
0257
0258 figure(f4)
0259 imshow(Image_r);
0260 hold on
0261
0262
0263
0264 lss = F'*[x;1];
0265
0266
0267 J = kron(eye(3),[x;1]');
0268 Cllh = J*Cff*J' + F'*[Cov,zeros(2,1);zeros(1,3)]*F;
0269
0270
0271 epi = sugr_Line_2D(lss,Cllh);
0272 sugr_plot_Line_2D(epi,'-k','-k',plot_params.f1,plot_params.magnification);
0273 sugr_plot_Line_2D(epi,'-y','-y',plot_params.f2,plot_params.magnification);
0274
0275
0276 plot_epipole(f4,er,Crr,plot_params)
0277
0278
0279 hold off
0280
0281 end
0282 end
0283
0284 return
0285
0286
0287 function plot_epipole(f,e,Cee,plot_params)
0288
0289 figure(f)
0290
0291 if abs(e(3)) > 0.0001
0292
0293
0294 ers=sugr_Point_2D(e,Cee);
0295
0296 sugr_plot_Point_2D(ers,'.k','-w',plot_params.f1,plot_params.magnification)
0297 sugr_plot_Point_2D(ers,'.k','-m',plot_params.f2,plot_params.magnification)
0298
0299
0300 [e_E,C_EE]=sugr_get_Euclidean_Point_2D(ers);
0301 text(e_E(1)+ 2*sqrt(C_EE(1,1))*plot_params.magnification,...
0302 e_E(2)+ 2*sqrt(C_EE(2,2))*plot_params.magnification,...
0303 'Epipole','FontSize',14,'FontWeight','bold','Color','m')
0304
0305 end