Changeset 1195 for trunk/src/civ.m


Ignore:
Timestamp:
Feb 26, 2026, 4:16:03 PM (5 days ago)
Author:
sommeria
Message:

format of PIV data made more compact/4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/civ.m

    r1179 r1195  
    44%
    55% OUTPUT:
    6 % xtable: set of x coordinates
    7 % ytable: set of y coordinates
    8 % utable: set of u displacements (along x)
     6% xtable: set of x positions of the first image in integer image coordinates , the measurement position is xtable-0.5+utable/2
     7% ytable: set of y coordinates of the first image in integer image coordinates (starting in the image bottom, image index= npy-ytable+1 , the measurement position is ytable-0.5+vtable/2
     8% utable: set of u displacements (along x), in pixels
    99% vtable: set of v displacements (along y)
    1010% ctable: max image correlation for each vector
     
    4444%% prepare measurement grid if not given as input
    4545if ~isfield(par_civ,'Grid')% grid points defining central positions of the sub-images in image A
    46     nbinterv_x=floor((npx_ima-1)/par_civ.Dx);
     46    nbinterv_x=floor((npx_ima-1)/par_civ.Dx);%expected number of intervals Dx
    4747    gridlength_x=nbinterv_x*par_civ.Dx;
    4848    minix=ceil((npx_ima-gridlength_x)/2);
    49     nbinterv_y=floor((npy_ima-1)/par_civ.Dy);
     49    nbinterv_y=floor((npy_ima-1)/par_civ.Dy);%expected number of intervals Dy
    5050    gridlength_y=nbinterv_y*par_civ.Dy;
    5151    miniy=ceil((npy_ima-gridlength_y)/2);
    52     [GridX,GridY]=meshgrid(minix:par_civ.Dx:npx_ima-1,miniy:par_civ.Dy:npy_ima-1);
     52    [GridX,GridY]=meshgrid(minix+0.5:par_civ.Dx:npx_ima-0.5,miniy+0.5:par_civ.Dy:npy_ima-0.5);% grid of initial positions in pixel coordinates (y upward)
    5353    par_civ.Grid(:,1)=reshape(GridX,[],1);
    5454    par_civ.Grid(:,2)=reshape(GridY,[],1);% increases with array index
     
    6666
    6767shiftx=par_civ.SearchBoxShift(:,1);%use the input shift estimate, rounded to the next integer value
    68 shifty=-par_civ.SearchBoxShift(:,2);% sign minus because image j index increases when y decreases
     68shifty=par_civ.SearchBoxShift(:,2);%
    6969if numel(shiftx)==1% case of a unique shift for the whole field( civ1)
    7070    shiftx=shiftx*ones(nbvec,1);
     
    7373
    7474%% shift the grid by half the expected displacement to get the velocity closer to the initial grid
    75 par_civ.Grid(:,1)=par_civ.Grid(:,1)-shiftx/2;
    76 par_civ.Grid(:,2)=par_civ.Grid(:,2)+shifty/2;
     75par_civ.Grid(:,1)=par_civ.Grid(:,1)-shiftx/2;% initial positions in image coordinates (y upward)
     76par_civ.Grid(:,2)=par_civ.Grid(:,2)-shifty/2;
    7777
    7878%% Array initialisation and default output  if par_civ.CorrSmooth=0 (just the grid calculated, no civ computation)
    79 xtable=round(par_civ.Grid(:,1)+0.5)-0.5;
    80 ytable=round(npy_ima-par_civ.Grid(:,2)+0.5)-0.5;% y index corresponding to the position in image coordinates
     79xtable=round(par_civ.Grid(:,1)+0.5);% tables of image indices corresponding to the input grid
     80ytable=round(npy_ima-par_civ.Grid(:,2)+0.5);% y image indices corresponding to the position in image coordinates
    8181shiftx=round(shiftx);
    8282shifty=round(shifty);
    83 utable=shiftx;%zeros(nbvec,1);
    84 vtable=shifty;%zeros(nbvec,1);
     83utable=shiftx;%zeros(nbvec,1);% expected displacements in pixel indices (y downward)
     84vtable=-shifty;%zeros(nbvec,1);
    8585ctable=zeros(nbvec,1);
    8686FF=zeros(nbvec,1);
     
    128128if par_civ.CorrSmooth~=0 % par_civ.CorrSmooth=0 implies no civ computation (just input image and grid points given)
    129129    for ivec=1:nbvec
    130         iref=round(par_civ.Grid(ivec,1)+0.5);% xindex on the image A for the middle of the correlation box
    131         jref=round(npy_ima-par_civ.Grid(ivec,2)+0.5);%  j index  for the middle of the correlation box in the image A
     130%         iref=round(par_civ.Grid(ivec,1));% xindex on the image A for the middle of the correlation box
     131%         jref=round(npy_ima-par_civ.Grid(ivec,2));%  j index  for the middle of the correlation box in the image A
     132         iref=xtable(ivec);% xindex on the image A for the middle of the correlation box
     133         jref=ytable(ivec);%  j index  for the middle of the correlation box in the image A
     134
    132135        FF(ivec)=0;
    133136        ibx2=floor(CorrBoxSizeX(ivec)/2);
     
    138141        subrange1_y=jref-iby2:jref+iby2;% y indices defining the first subimage
    139142        subrange2_x=iref+shiftx(ivec)-isx2:iref+shiftx(ivec)+isx2;%x indices defining the second subimage
    140         subrange2_y=jref+shifty(ivec)-isy2:jref+shifty(ivec)+isy2;%y indices defining the second subimage
     143        subrange2_y=jref-shifty(ivec)-isy2:jref-shifty(ivec)+isy2;%y indices defining the second subimage
    141144        image1_crop=MinA*ones(numel(subrange1_y),numel(subrange1_x));% default value=min of image A
    142145        image2_crop=MinA*ones(numel(subrange2_y),numel(subrange2_x));% default value=min of image A
     
    224227                        end
    225228                        utable(ivec)=vector(1)*mesh+shiftx(ivec);
    226                         vtable(ivec)=-(vector(2)*mesh+shifty(ivec));
    227                         xtable(ivec)=iref+utable(ivec)/2-0.5;% convec flow (velocity taken at the point middle from imgae 1 and 2)
    228                         ytable(ivec)=jref+vtable(ivec)/2-0.5;% and position of pixel 1=0.5 (convention for image coordinates=0 at the edge)
    229                         iref=round(xtable(ivec)+0.5);% nearest image index for the middle of the vector
    230                         jref=round(ytable(ivec)+0.5);
     229                        vtable(ivec)=-vector(2)*mesh+shifty(ivec);% vtable and shifty in image coordinates (opposite to pixel shift)
     230                      %  xtable(ivec)=iref+utable(ivec)/2-0.5;% convec flow (velocity taken at the point middle from imgae 1 and 2)
     231                       % ytable(ivec)=jref+vtable(ivec)/2-0.5;% and position of pixel 1=0.5 (convention for image coordinates=0 at the edge)
     232%                         iref=round(xtable(ivec)+0.5);% nearest image index for the middle of the vector
     233%                         jref=round(ytable(ivec)+0.5);
    231234                        % eliminate vectors located in the mask
    232                         if  checkmask && (iref<1 || jref<1 ||iref>npx_ima || jref>npy_ima ||( par_civ.Mask(jref,iref)<200 && par_civ.Mask(jref,iref)>=100))
    233                             utable(ivec)=0;
    234                             vtable(ivec)=0;
    235                             FF(ivec)=1;
    236                         end
     235%                         if  checkmask && (iref<1 || jref<1 ||iref>npx_ima || jref>npy_ima ||( par_civ.Mask(jref,iref)<200 && par_civ.Mask(jref,iref)>=100))
     236%                             utable(ivec)=0;
     237%                             vtable(ivec)=0;
     238%                             FF(ivec)=1;
     239%                         end
    237240                        ctable(ivec)=corrmax/sum_square;% correlation value
    238241                    catch ME
Note: See TracChangeset for help on using the changeset viewer.