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

h_transfer_grid

PURPOSE ^

demo_h_transfer_grid: transfer point in demo_homography

SYNOPSIS ^

function h_transfer_grid(H,CP,Image_l,Image_r,magnification,grid_out)

DESCRIPTION ^

 demo_h_transfer_grid: transfer point in demo_homography

 demo_h_transfer_grid(H,X,Image_l,Image_r,magnification,grid_inp,grid_out);

 grid_inp = 4 x 2 array: x',y' coordinates in left images 00 01 11 10
 grid_out = .Nx,.xa,.xe,.Ny,.ya,.ye of unit square 00 01 11 10

 Wolfgang Förstner 7/2011
 wfoerstn@uni-bonn.de

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % demo_h_transfer_grid: transfer point in demo_homography
0002 %
0003 % demo_h_transfer_grid(H,X,Image_l,Image_r,magnification,grid_inp,grid_out);
0004 %
0005 % grid_inp = 4 x 2 array: x',y' coordinates in left images 00 01 11 10
0006 % grid_out = .Nx,.xa,.xe,.Ny,.ya,.ye of unit square 00 01 11 10
0007 %
0008 % Wolfgang Förstner 7/2011
0009 % wfoerstn@uni-bonn.de
0010 
0011 function h_transfer_grid(H,CP,Image_l,Image_r,magnification,grid_out)
0012 
0013 ss = plot_init;
0014 
0015 global coordinate_sigma_x
0016 
0017 % left image
0018 figure('Color','w','Name', 'left image','Position',[50,100,0.45*ss(1),0.45*ss(1)]);
0019 imshow(127+0.5*Image_l);
0020 hold on
0021 xy = CP;
0022 
0023 % reference quadrangle
0024 for n=1:4
0025     plot_square_with_background(xy(n,1),xy(n,2),10);
0026     plot_square_with_background(xy(n,1),xy(n,2),10);
0027 end
0028 
0029 plot([xy(1,1),xy(2,1)],[xy(1,2),xy(2,2)],'-y','LineWidth',3);
0030 plot([xy(2,1),xy(3,1)],[xy(2,2),xy(3,2)],'-y','LineWidth',3);
0031 plot([xy(3,1),xy(4,1)],[xy(3,2),xy(4,2)],'-y','LineWidth',3);
0032 plot([xy(4,1),xy(1,1)],[xy(4,2),xy(1,2)],'-y','LineWidth',3);
0033 
0034 
0035 plot([xy(1,1),xy(2,1)],[xy(1,2),xy(2,2)],'-k','LineWidth',1);
0036 plot([xy(2,1),xy(3,1)],[xy(2,2),xy(3,2)],'-k','LineWidth',1);
0037 plot([xy(3,1),xy(4,1)],[xy(3,2),xy(4,2)],'-k','LineWidth',1);
0038 plot([xy(4,1),xy(1,1)],[xy(4,2),xy(1,2)],'-k','LineWidth',1);
0039 
0040 % homography from unit square to reference quadrangle
0041 P.h = [...
0042     0 0 1 xy(1,1) xy(1,2) 1;...
0043     0 1 1 xy(2,1) xy(2,2) 1;...
0044     1 1 1 xy(3,1) xy(3,2) 1;...
0045     1 0 1 xy(4,1) xy(4,2) 1;...
0046     ];
0047 P.Crr = zeros(4,4,4);
0048 H1 = sugr_estimation_algebraic_Homography_2D_from_point_pairs(P);
0049 
0050 
0051 % define grid
0052 Nx = grid_out(1);
0053 xa = grid_out(2);
0054 xe = grid_out(3);
0055 dx = (xe-xa)/(Nx-1);
0056 Ny = grid_out(4);
0057 ya = grid_out(5);
0058 ye = grid_out(6);
0059 dy = (ye-ya)/(Ny-1);
0060 N = Nx*Ny;
0061 n = 0;
0062 C0 = coordinate_sigma_x*diag([1,1]);
0063 %C0=1*diag([1,1]);
0064 for x = xa:dx:xe
0065     for y = ya:dy:ye
0066         n = n+1; 
0067         xyt = ([x,y,1]*H1.H')';
0068         xye = xyt(1:2)./xyt(3);
0069         gr1(n) = sugr_Point_2D(xye,C0);                                    %#ok<*AGROW>
0070         sugr_plot_Point_2D(gr1(n),'.k','-k',6,magnification);
0071         sugr_plot_Point_2D(gr1(n),'oy','-y',2,magnification);
0072     end
0073 end
0074 
0075 % transform grid an plot into 2. image with ellipse
0076 figure('Color','w','Name', 'right image','Position',[100+0.45*ss(1),100,0.45*ss(1),0.45*ss(1)])
0077 imshow(127+0.5*Image_r);
0078 hold on
0079  % reference quadrangle
0080 d=2; 
0081 for n=1:4
0082     plot_square_with_background(xy(n,1+d),xy(n,2+d),10);
0083     plot_square_with_background(xy(n,1+d),xy(n,2+d),10);
0084 end
0085 
0086 plot([xy(1,1+d),xy(2,1+d)],[xy(1,2+d),xy(2,2+d)],'-k','LineWidth',6);
0087 plot([xy(2,1+d),xy(3,1+d)],[xy(2,2+d),xy(3,2+d)],'-k','LineWidth',6);
0088 plot([xy(3,1+d),xy(4,1+d)],[xy(3,2+d),xy(4,2+d)],'-k','LineWidth',6);
0089 plot([xy(4,1+d),xy(1,1+d)],[xy(4,2+d),xy(1,2+d)],'-k','LineWidth',6);
0090 
0091 
0092 plot([xy(1,1+d),xy(2,1+d)],[xy(1,2+d),xy(2,2+d)],'-y','LineWidth',2);
0093 plot([xy(2,1+d),xy(3,1+d)],[xy(2,2+d),xy(3,2+d)],'-y','LineWidth',2);
0094 plot([xy(3,1+d),xy(4,1+d)],[xy(3,2+d),xy(4,2+d)],'-y','LineWidth',2);
0095 plot([xy(4,1+d),xy(1,1+d)],[xy(4,2+d),xy(1,2+d)],'-y','LineWidth',2);
0096 
0097 
0098 for n=1:N
0099     % transform with uncertainty
0100     gr2(n) = sugr_transform_with_Homography_2D(H,gr1(n));
0101     %% plot ellipse in right image
0102     sugr_plot_Point_2D(gr2(n),'ow','-w',4,magnification);
0103     sugr_plot_Point_2D(gr2(n),'.k','-k',2,magnification);
0104 end

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