Home > Matching_SYM_LSM > src > 2D_LSM_62 > 2D_LSM_62_sym > LSM_62_sym_find_observation_positions.m

LSM_62_sym_find_observation_positions

PURPOSE ^

LSM_find_observation_positions in the common area

SYNOPSIS ^

function [Nf,yi,zi,w]=LSM_62_sym_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

 [Nf,yi,zi,w] =
 LSM_62_sym_find_observation_positions(g,h,vg,vh,xa,BOUND,pt)
 
 g1, g2 = two images
 vg,vh  = parameters (s,t) variance functions, e.g. V(g)=vg(1)+vg(2)*g
 xa     = parameters of approximate transformations
 Nf_MIN = minimum size of overlap (radius of window f)
 pt     = boolean for plot/print

 Nf     = size of refence image
 yi     = lists of (i,j) coordinates in g
 zi     = lists of (i,j) coordinates in h
 w      = vector of weights

 wf 08/2012

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 % [Nf,yi,zi,w] =
0005 % LSM_62_sym_find_observation_positions(g,h,vg,vh,xa,BOUND,pt)
0006 %
0007 % g1, g2 = two images
0008 % vg,vh  = parameters (s,t) variance functions, e.g. V(g)=vg(1)+vg(2)*g
0009 % xa     = parameters of approximate transformations
0010 % Nf_MIN = minimum size of overlap (radius of window f)
0011 % pt     = boolean for plot/print
0012 %
0013 % Nf     = size of refence image
0014 % yi     = lists of (i,j) coordinates in g
0015 % zi     = lists of (i,j) coordinates in h
0016 % w      = vector of weights
0017 %
0018 % wf 08/2012
0019 
0020 function [Nf,yi,zi,w]= ...
0021     LSM_62_sym_find_observation_positions(g,h,vg,vh,xa,Nf_MIN,pt)
0022 %% Constant, control
0023 BOUND  = 3;
0024 
0025 %% size of images
0026 Ng=(size(g,1)-1)/2;
0027 Nh=(size(h,1)-1)/2;
0028 
0029 %% determine transfromation y->x, x->h
0030 B  = [xa(1) xa(3) xa(5);xa(2) xa(4) xa(6);0 0 1];
0031 Bi = inv(B);
0032 
0033 %% find region in x-space
0034 % transform boundary, take 3-pixel distance
0035 Ngr   = Ng-BOUND;
0036 bbg   = square_corners(Ngr);    % bb in g
0037 bbgf  = B*bbg;                  % corresponding quadrangle in f
0038 bbgfp = [bbgf,bbgf(:,1)];       % closed
0039 
0040 Nhr   = Nh-BOUND;
0041 bbh   = square_corners(Nhr);    % bb in h
0042 bbhf  = Bi*bbh;                 % corresponding quadrangle in f
0043 bbhfp = [bbhf,bbhf(:,1)];       % closed
0044 % find size of square, check 4 diagonals
0045 dmin=10000;
0046 for i=1:4
0047     % direction of i-th diagonal
0048     u   = cos(pi/4*(2*i-1));
0049     v   = sin(pi/4*(2*i-1));
0050     % for each side
0051     for j=1:4
0052         % distances to polygon g and h
0053         distg = dist_poly_ray(bbgfp,j,u,v);
0054         disth = dist_poly_ray(bbhfp,j,u,v);
0055         % take minimum
0056         dmin  = min([dmin,distg,disth]);
0057     end
0058 end
0059 % sizeof square of f
0060 Nf  = floor((dmin)/sqrt(2))-1;   %% -1 appears to be necessary
0061 Nfr = Nf-BOUND;
0062 
0063 if Nf < Nf_MIN
0064     yi=0;
0065     zi=0;
0066     w=0;
0067     return
0068 end
0069 
0070 
0071 %% pixels in the first image g
0072 k=0;
0073 yi=[];
0074 yi=[];
0075 fg=[];
0076 w=[];
0077 for i=-Ngr:Ngr
0078     for j=-Ngr:Ngr
0079         xh = B*[i;j;1];  % coordinates from g transformed into f
0080         x  = xh(1)/xh(3);
0081         y  = xh(2)/xh(3);
0082         % check offset from boundary in second image
0083         if (round(x) >  -Nfr) && (round(x) <  Nfr) ...
0084                 && (round(y) >  -Nfr) && (round(y) <  Nfr)
0085             k=k+1;                              % next pixel in g
0086             % store coordinates
0087             % referring to [-Ng,-Ng] (pixels are +1)
0088             yi(1:2,k)=[i+Ng;j+Ng];
0089             w(k) = 1/vg(g(i+Ng,j+Ng)+1);   % determine weight
0090         end
0091     end
0092 end
0093 % number of pixels in g
0094 Kg=size(yi,2);
0095 
0096 %% pixels in the second image z, away by BOUND from the boundary
0097 k=0;
0098 zi=[];
0099 zi=[];
0100 fh=[];
0101 for i=-Nhr:Nhr
0102     for j=-Nhr:Nhr
0103         xh  = Bi*[i;j;1];  % coordinates from h transformed into f
0104         x1  = xh(1)/xh(3);
0105         y1  = xh(2)/xh(3);
0106         % check offset from boundary in first image
0107         %if (x1 >= 1+BOUND) && (x1 <= N1-BOUND) && (y1 >= 1+BOUND) && (y1 <= N1-BOUND)
0108         if (round(x1) > -Nfr) && (round(x1) < Nfr) ...
0109                 && (round(y1) > -Nfr) && (round(y1) < Nfr)
0110             k=k+1;                                  % next pixel in g
0111             % store coordinates
0112             % referring to [-Nh,-Nh] (pixels are +1)
0113             zi(1:2,k)=[i+Nh;j+Nh];
0114             w(Kg+k) = 1/vh(h(i+Nh,j+Nh)+1);    % determine weight
0115         end
0116     end
0117 end
0118 % number of pixels in h
0119 Kh=size(zi,2);
0120 
0121 % enforce column of w
0122 w = w(:);
0123 
0124 if pt > 1
0125     
0126     figure('Name','areas in middle image')
0127     hold on
0128     axis equal
0129     Nfb=Nf-BOUND;
0130     % plot bb for f
0131     
0132     plot_quadrangle([-Nf,-Nf,Nf,Nf;...
0133         -Nf,Nf,+Nf,-Nf],'-r');
0134     % plot bb reduced for f
0135     plot_quadrangle([-Nfb,-Nfb,Nfb,Nfb;...
0136         -Nfb,Nfb,+Nfb,-Nfb],'--r')
0137     plot_quadrangle(bbgfp,'-g')
0138     plot_quadrangle(bbhfp,'-b')
0139     plot(1.5*[-Nf,Nf],1.5*[+Nf,-Nf],'--k')
0140     plot(1.5*[-Nf,Nf],1.5*[-Nf,+Nf],'--k')
0141     
0142     % second image  in coordinate system f
0143     xih = Bi*[zi-Nh*ones(2,Kh);ones(1,Kh)];
0144     plot(xih(1,:),xih(2,:),'og','MarkerSize',8)
0145     
0146     % first image in coordinate system f
0147     xig = B*[yi-Ng*ones(2,Kg);ones(1,Kg)];
0148     plot(xig(1,:),xig(2,:),'ob','MarkerSize',8)
0149     
0150 end
0151 return

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