Home > Matching_SYM_LSM > src > 2D_LSM_62 > 2D_LSM_62_sym_warp > LSM_62_sym_warp_find_observation_positions.m

LSM_62_sym_warp_find_observation_positions

PURPOSE ^

% LSM_find_observation_positions in the common area

SYNOPSIS ^

function [Nf,yi,zi,w]=LSM_62_sym_warp_find_observation_positions(g,h,vg,vh,xa,Nf_MIN,pt)

DESCRIPTION ^

% LSM_find_observation_positions in the common area
 with distance to boundary <= BOUND

 call:
 [Nf,yi,zi,w] =
 LSM_62_sym_warp_find_observation_positions(g,h,vg,vh,xa,pt)

 g, h   = two images
 vg,vh  = 256-vectors with variances of g and h: g, h in [0:1:255]
 xa     = parameters of approximate transformations B and S
          xa(1:6) geoemtric parameters, xa(7:8) radiometric parameters
 Nf_MIN = minimum size of overlap (radius of window f)
 pt     = boolean for plot/print

 Nf     = size of refence image (radius/half side length)
 yi     = Kg vector, list of (i,j) in g, left upper corner [1,1]
 zi     = Kh-vector, list of (i,j) in h, left upper corner [1,1]
 w      = (Kg+Kh)-vectorvector of weights

 wf 08/2018

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% LSM_find_observation_positions in the common area
0002 % with distance to boundary <= BOUND
0003 %
0004 % call:
0005 % [Nf,yi,zi,w] =
0006 % LSM_62_sym_warp_find_observation_positions(g,h,vg,vh,xa,pt)
0007 %
0008 % g, h   = two images
0009 % vg,vh  = 256-vectors with variances of g and h: g, h in [0:1:255]
0010 % xa     = parameters of approximate transformations B and S
0011 %          xa(1:6) geoemtric parameters, xa(7:8) radiometric parameters
0012 % Nf_MIN = minimum size of overlap (radius of window f)
0013 % pt     = boolean for plot/print
0014 %
0015 % Nf     = size of refence image (radius/half side length)
0016 % yi     = Kg vector, list of (i,j) in g, left upper corner [1,1]
0017 % zi     = Kh-vector, list of (i,j) in h, left upper corner [1,1]
0018 % w      = (Kg+Kh)-vectorvector of weights
0019 %
0020 % wf 08/2018
0021 
0022 function [Nf,yi,zi,w]= ...
0023     LSM_62_sym_warp_find_observation_positions(g,h,vg,vh,xa,Nf_MIN,pt)
0024 %% Constant, control
0025 BOUND  = 3;
0026 
0027 %% size of images
0028 Mg  = size(g,1);
0029 Mh  = size(h,1);
0030 Ng=(Mg-1)/2;
0031 Nh=(Mh-1)/2;
0032 
0033 %% determine transfromation y->x, x->h
0034 B  = [xa(1) xa(3) xa(5);xa(2) xa(4) xa(6);0 0 1];
0035 Bi = inv(B);
0036 
0037 %% find region in x-space
0038 % transform boundary, take 3-pixel distance
0039 Ngr   = Ng-BOUND;
0040 bbg   = square_corners(Ngr);    % bb in g
0041 bbgf  = B*bbg;                  % corresponding quadrangle in f
0042 bbgfp = [bbgf,bbgf(:,1)];       % closed
0043 
0044 Nhr   = Nh-BOUND;
0045 bbh   = square_corners(Nhr);    % bb in h
0046 bbhf  = Bi*bbh;                 % corresponding quadrangle in f
0047 bbhfp = [bbhf,bbhf(:,1)];       % closed
0048 
0049 %% find size of square, check 4 diagonals
0050 % - determine intersection f of four diagonals l with four sides m of quadrangle
0051 %   f=l x m, l = s x t, m = [0,0,1] x w, s = [a,b,1], t=[c,d,1], w=[u,v,0]
0052 %   fx = (u*(a*d - b*c))/den, den = b*u - a*v + c*v - d*u
0053 %   fy = (v*(a*d - b*c))/den
0054 % - find minimum distance
0055 dmin=10000;
0056 % for each diagonal
0057 for i=1:4
0058     % direction of i-th diagonal
0059     u   = cos(pi/4*(2*i-1));
0060     v   = sin(pi/4*(2*i-1));
0061     % for each side
0062     for j=1:4
0063         % distances to polygon g and h
0064         distg = dist_poly_ray(bbgfp,j,u,v);
0065         disth = dist_poly_ray(bbhfp,j,u,v);
0066         % take minimum
0067         dmin  = min([dmin,distg,disth]);
0068     end
0069 end
0070 % size of square of f
0071 Nf  = floor((dmin)/sqrt(2)+0.0001);   %% +++++++++++++++++++++++++++++++
0072 Nfr = Nf-BOUND;
0073 
0074 if Nf < Nf_MIN
0075     yi=0;
0076     zi=0;
0077     w=0;
0078     return
0079 end
0080 
0081 
0082 %% pixels in the first image g
0083 k=0;
0084 yi=[];
0085 fg=[];
0086 w=[];
0087 
0088 % parallel
0089 [y,x] = meshgrid(1:Mg,1:Mg);
0090 ijh = [x(:),y(:),ones(length(x(:)),1)];
0091 xh_v = ijh * (B*[1 0 -Ngr-1; 0 1 -Ngr-1;0 0 1])';
0092 indh = find((round(xh_v(:,1)) >= -Nfr) & (round(xh_v(:,1)) <= Nfr) ...
0093     & (round(xh_v(:,2)) >= -Nfr) & (round(xh_v(:,2)) <= Nfr));
0094 %yi_v = [x(indh)'+BOUND;y(indh)'+BOUND];
0095 yi_v = [x(indh)'+BOUND-1;y(indh)'+BOUND-1];
0096 Kg = length(indh);
0097 w_v = 1./vg(g(yi_v(1,:)'+Mg*(yi_v(2,:)'-1))+1);
0098 w_v = w_v(:);
0099 
0100 % % number of pixels in g
0101 % Kg=size(yi,2);
0102 yi=yi_v;
0103 
0104 %% pixels in the second image z, away by bound from the boundary
0105 k=0;
0106 zi=[];
0107 fh=[];
0108 % parallel
0109 [y,x] = meshgrid(1:Mh,1:Mh);
0110 ijh = [x(:),y(:),ones(length(x(:)),1)];
0111 xh_v = ijh * (Bi*[1 0 -Nhr-1; 0 1 -Nhr-1;0 0 1])';
0112 indh = find((round(xh_v(:,1)) >= -Nfr) & (round(xh_v(:,1)) <= Nfr) ...
0113     & (round(xh_v(:,2)) >= -Nfr) & (round(xh_v(:,2)) <= Nfr));
0114 zi_v = [x(indh)'+BOUND-1;y(indh)'+BOUND-1];
0115 %zi_v = [x(indh)'+BOUND;y(indh)'+BOUND];
0116 Kh = length(indh);
0117 w_vh =1./vh(h(zi_v(1,:)'+Mh*(zi_v(2,:)'-1))+1);
0118 w_vh = w_vh(:);
0119 w_v = [w_v;w_vh];
0120 
0121 % % number of pixels in h
0122 % Kh=size(zi,2);
0123 
0124 zi = zi_v;
0125 
0126 % % enforce column of w
0127 % w = w(:);
0128 
0129 w= w_v;
0130 
0131 if pt > 1
0132     
0133     figure(14)
0134     hold on
0135     axis equal
0136     Nfb=Nf-BOUND;
0137     % plot bb for f
0138     
0139     plot_quadrangle([-Nf,-Nf,Nf,Nf;...
0140         -Nf,Nf,+Nf,-Nf],'-r');
0141     % plot bb reduced for f
0142     plot_quadrangle([-Nfb,-Nfb,Nfb,Nfb;...
0143         -Nfb,Nfb,+Nfb,-Nfb],'--r')
0144     plot_quadrangle(bbgfp,'-b')
0145     plot_quadrangle(bbhfp,'-g')
0146     plot(1.5*[-Nf,Nf],1.5*[+Nf,-Nf],'--k')
0147     plot(1.5*[-Nf,Nf],1.5*[-Nf,+Nf],'--k')
0148     
0149     % second image  in coordinate system f
0150     xih = Bi*[zi-Nh*ones(2,Kh);ones(1,Kh)];
0151     plot(xih(2,:),xih(1,:),'og','MarkerSize',8)
0152     
0153     % first image in coordinate system f
0154     xig = B*[yi-Ng*ones(2,Kg);ones(1,Kg)];
0155     plot(xig(2,:),xig(1,:),'ob','MarkerSize',8)
0156     title('areas in middle image')
0157     
0158 end
0159 return

Generated on Sun 19-Jul-2020 23:00:25 by m2html © 2005