Home > 10-Uncertain-Geometry > Functions > determine_Homography_2D_from_two_images.m

determine_Homography_2D_from_two_images

PURPOSE ^

demo_h_determine_homography_from_two_images: read/interactively determine homography

SYNOPSIS ^

function [H,X] = determine_Homography_2D_from_two_images(Image_l,Image_r,readX)

DESCRIPTION ^

 demo_h_determine_homography_from_two_images: read/interactively determine homography

 [H,X,Cxx] = demo_h_determine_homography_from_two_images...
    (tau,sigma,sidth,sigma_n,Image_l,Image_r,coordinatesigma,coordinate_name,...
    ,magnification,readX);

 H homography from left to right
 X    = 4 x 4-matrix, rows control point coordinates
 Cxx  = 4 x 4 x 4 tensor with cov. matrices

 Wolfgang Förstner 06/18
 wfoerstn@uni-bonn.de

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % demo_h_determine_homography_from_two_images: read/interactively determine homography
0002 %
0003 % [H,X,Cxx] = demo_h_determine_homography_from_two_images...
0004 %    (tau,sigma,sidth,sigma_n,Image_l,Image_r,coordinatesigma,coordinate_name,...
0005 %    ,magnification,readX);
0006 %
0007 % H homography from left to right
0008 % X    = 4 x 4-matrix, rows control point coordinates
0009 % Cxx  = 4 x 4 x 4 tensor with cov. matrices
0010 %
0011 % Wolfgang Förstner 06/18
0012 % wfoerstn@uni-bonn.de
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         %imagesc(Image_l);
0038         %% wait until a button is pressed
0039         keydown = waitforbuttonpress;
0040         % if a keyboard button was pressed, stop cycle
0041         if keydown == 1
0042             break
0043         end
0044         %% grab mouse position
0045         x = get(gca,'currentPoint');
0046         % determina local accuracy
0047         z = x(1,1:2)';
0048 
0049         Covl = coordinate_sigma_x*eye(2);
0050 
0051         %% plot point in left image
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         %% wait until a button is pressed
0062         keydown = waitforbuttonpress;
0063         % if a keyboard button was pressed, stop cycle
0064         if keydown == 1
0065             break
0066         end
0067         %% grab mouse position
0068         x = get(gca,'currentPoint');
0069         z = x(1,1:2)';
0070         
0071         Covr = coordinate_sigma_x*eye(2);
0072 
0073         %plot_square_with_background(x(1,1),x(1,2),10);
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 % conditioning
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 % estimation of H (conditioned)
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 % uncondition xr = H xl,
0106 % Tr xr = (Tr H Tl^{-1} Tl) xl
0107 % H = inv(Tr) * H * Tl
0108 H = sugr_transform_Homography_2D(Hc, inv(Tr.H), Tl.H);
0109

Generated on Sat 21-Jul-2018 20:56:10 by m2html © 2005