0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 function [H,X] = determine_Homography_2D_from_two_images(...
0015 Image_l,Image_r,readX)
0016
0017 global coordinate_sigma_x
0018 global coordinate_name
0019
0020 addpath(genpath('../../General-Functions'))
0021 ss = plot_init;
0022
0023 f1 = figure('Color','w','Name', 'left image','Position',[50,100,0.45*ss(1),0.45*ss(1)]);
0024 imshow(Image_l);
0025 hold on
0026 f2 = figure('Color','w','Name', 'right image','Position',[100+0.45*ss(1),100,0.45*ss(1),0.45*ss(1)]);
0027 imshow(Image_r);
0028 hold on
0029
0030 if readX == 0
0031 X = zeros(4,4);
0032 Cxx = zeros(4,4,4);
0033 for n=1:4
0034 figure(f1)
0035 hold on
0036 disp('measure point in left image (1)')
0037
0038
0039 keydown = waitforbuttonpress;
0040
0041 if keydown == 1
0042 break
0043 end
0044
0045 x = get(gca,'currentPoint');
0046
0047 z = x(1,1:2)';
0048
0049 Covl = coordinate_sigma_x*eye(2);
0050
0051
0052 plot_square_with_background(z(1),z(2),10);
0053 hold off
0054
0055 X(n,1:2)= x(1,1:2);
0056
0057 figure(f2)
0058 hold on
0059
0060 disp('measure corresponding point in right image (2)')
0061
0062 keydown = waitforbuttonpress;
0063
0064 if keydown == 1
0065 break
0066 end
0067
0068 x = get(gca,'currentPoint');
0069 z = x(1,1:2)';
0070
0071 Covr = coordinate_sigma_x*eye(2);
0072
0073
0074 plot_square_with_background(z(1),z(2),10);
0075 X(n,3:4) = x(1,1:2);
0076
0077 Cxx(n,:,:)= [Covl zeros(2);zeros(2) Covr];
0078 end
0079
0080 save(coordinate_name,'X','Cxx');
0081
0082 else
0083 load(coordinate_name,'X','Cxx');
0084 end
0085
0086 Tl = sugr_Homography_2D(X(:,1:2));
0087 Tr = sugr_Homography_2D(X(:,3:4));
0088 for n = 1 : 4
0089 pl = sugr_Point_2D(X(n,1:2)', squeeze(Cxx(n,1:2,1:2)));
0090 pl = sugr_transform_with_Homography_2D(Tl,pl);
0091
0092 pr = sugr_Point_2D(X(n,3:4)', squeeze(Cxx(n,3:4,3:4)));
0093 pr = sugr_transform_with_Homography_2D(Tr,pr);
0094
0095 PPc.h(n,:) = [pl.h', pr.h'];
0096 PPc.Crr(n,:,:) = [pl.Crr zeros(2);zeros(2) pr.Crr];
0097 end
0098
0099
0100 Ha = sugr_estimation_algebraic_Homography_2D_from_point_pairs(PPc);
0101 T = 0.1;
0102 maxiter = 3;
0103 [Hc,~,~] = sugr_estimation_ml_Homography_2D_from_point_pairs(PPc,Ha,T,maxiter);
0104
0105
0106
0107
0108 H = sugr_transform_Homography_2D(Hc, inv(Tr.H), Tl.H);
0109