Changeset 1163 for trunk


Ignore:
Timestamp:
Jul 25, 2024, 8:36:17 PM (5 months ago)
Author:
sommeria
Message:

SearchBoxSize? changed to SearchRange? in civ, possibility of a grid set by a netcdf file

Location:
trunk/src
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/filter_tps.m

    r1161 r1163  
    9393        ind_sel= find(~FF & Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub));% indices of vectors in the subdomain #isub
    9494         check_partial_domain=sum(SubRange(:,1,isub)> MinCoord' | SubRange(:,2,isub)< MaxCoord');
    95         % isub
    96         % numel(ind_sel)
    9795
    9896        % if no vector in the subdomain  #isub, skip the subdomain
  • trunk/src/filter_tps_3D.m

    r1162 r1163  
    6666CentreX=reshape(CentreX,1,[]);% X positions of subdomain centres
    6767CentreY=reshape(CentreY,1,[]);% Y positions of subdomain centres
    68 CentreZ=reshape(CentreZ,1,[]);% Y positions of subdomain centres
     68CentreZ=reshape(CentreZ,1,[]);% Z positions of subdomain centres
    6969
    7070%% smoothing parameter: CHANGED 03 May 2024 TO GET RESULTS INDEPENDENT OF SUBDOMAINSIZE
     
    9292    SubRange(1,:,isub)=[CentreX(isub)-0.55*Siz(1) CentreX(isub)+0.55*Siz(1)];%bounds of subdomain #isub in x coordinate
    9393    SubRange(2,:,isub)=[CentreY(isub)-0.55*Siz(2) CentreY(isub)+0.55*Siz(2)];%bounds of subdomain #isub in y coordinate
     94    SubRange(3,:,isub)=[CentreZ(isub)-0.55*Siz(3) CentreZ(isub)+0.55*Siz(3)];%bounds of subdomain #isub in y coordinate
    9495    ind_sel=0;%initialize set of vector indices in the subdomain
    9596    %increase iteratively the subdomain if it contains less than
  • trunk/src/mouse_motion.m

    r1158 r1163  
    265265                ibx2=floor((par_civ.CorrBoxSize(1)-1)/2);
    266266                iby2=floor((par_civ.CorrBoxSize(2)-1)/2);
    267                 isx2=floor((par_civ.SearchBoxSize(1)-1)/2);
    268                 isy2=floor((par_civ.SearchBoxSize(2)-1)/2);
     267                isx2=par_civ.SearchRange(1);
     268                isy2=par_civ.SearchRange(2);
    269269                hhh=findobj(CurrentAxes,'Tag','PIV_box_marker');
    270270                hhhh=findobj(CurrentAxes,'Tag','PIV_search_marker');
  • trunk/src/series/civ_3D.m

    r1161 r1163  
    190190Data.VarAttribute{7}.Role='ancillary';
    191191Data.VarAttribute{8}.Role='errorflag';
    192 Data.Coord_z=j1_series_Civ1;
     192% Data.Coord_z=j1_series_Civ1;
    193193% path for output nc file
    194194OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device),[Param.OutputSubDir Param.OutputDirExt]);
     
    230230    par_civ1.ImageHeight=FileInfo.Height;npy=FileInfo.Height;
    231231    par_civ1.ImageWidth=FileInfo.Width;npx=FileInfo.Width;
    232 SearchRange_z=floor(Param.ActionInput.Civ1.SearchBoxSize(3)/2);
     232SearchRange_z=Param.ActionInput.Civ1.SearchRange(3);
    233233    par_civ1.Dz=Param.ActionInput.Civ1.Dz;
    234234    par_civ1.ImageA=zeros(2*SearchRange_z+1,npy,npx);
     
    296296        par_civ1.ImageA=zeros(2*SearchRange_z+1,npy,npx);%image block initiation
    297297        par_civ1.ImageB=zeros(2*SearchRange_z+1,npy,npx);
    298        
     298        Data.Coord_z=SearchRange_z+1:par_civ1.Dz:NbSlice-1;
    299299        z_index=1;%first vertical block centered at image index z_index=SearchRange_z+1
    300300        for iz=1:2*SearchRange_z+1
     
    315315        end
    316316     % loop on slices
     317
    317318        for z_index=2:floor((NbSlice-SearchRange_z)/par_civ1.Dz)% loop on slices
    318319            par_civ1.ImageA=circshift(par_civ1.ImageA,-par_civ1.Dz,1);%shift the indices in the image block upward by par_civ1.Dz
    319320            par_civ1.ImageB=circshift(par_civ1.ImageB,-par_civ1.Dz,1);
    320321            for iz=1:par_civ1.Dz %read the new images at the end of the image block
     322                image_index=z_index*par_civ1.Dz+SearchRange_z-par_civ1.Dz+iz+1;
     323                if image_index<=size(j1_series_Civ1,1)
    321324                j_image_index=j1_series_Civ1(z_index*par_civ1.Dz+SearchRange_z-par_civ1.Dz+iz+1,1)
    322                 ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1,ifield),[],j_image_index);%
     325                ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1,ifield),[],j_image_index);%           
    323326                A= read_image(ImageName_A,FileType_A);
    324327                ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(1,ifield),[],j_image_index);
    325328                B= read_image(ImageName_B,FileType_B);
     329                else
     330                    A=zeros(1,size(par_civ1.ImageA,2),size(par_civ1.ImageA,3));
     331                    B=zeros(1,size(par_civ1.ImageA,2),size(par_civ1.ImageA,3));
     332                end
    326333                par_civ1.ImageA(2*SearchRange_z+1-par_civ1.Dz+iz,:,:) = A;
    327334                par_civ1.ImageB(2*SearchRange_z+1-par_civ1.Dz+iz,:,:) = B;
     
    338345        Data.Civ1_Y=npy-Data.Civ1_Y+1;%reverse y
    339346        [npz,npy,npx]=size(Data.Civ1_X);
    340         Data.Coord_z=SearchRange_z+1:par_civ1.Dz:NbSlice-1;
     347       
    341348      %  Data.Coord_y=flip(1:npy);
    342349       % Data.Coord_x=1:npx;
     
    422429        % list the variables to record
    423430        nbvar=length(Data.ListVarName);
    424         Data.ListVarName=[Data.ListVarName {'Civ1_U_smooth','Civ1_V_smooth','Civ1_SubRange','Civ1_NbCentres','Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps'}];
    425         Data.VarDimName=[Data.VarDimName {'nb_vec_1','nb_vec_1',{'nb_coord','nb_bounds','nb_subdomain_1'},'nb_subdomain_1',...
    426             {'nb_tps_1','nb_coord','nb_subdomain_1'},{'nb_tps_1','nb_subdomain_1'},{'nb_tps_1','nb_subdomain_1'}}];
     431        Data.ListVarName=[Data.ListVarName {'Civ1_U_smooth','Civ1_V_smooth','Civ1_W_smooth'}];
     432        Data.VarDimName=[Data.VarDimName {{'npz','npy','npx'},{'npz','npy','npx'},{'npz','npy','npx'}}];
    427433        Data.VarAttribute{nbvar+1}.Role='vector_x';
    428434        Data.VarAttribute{nbvar+2}.Role='vector_y';
    429         Data.VarAttribute{nbvar+5}.Role='coord_tps';
    430         Data.VarAttribute{nbvar+6}.Role='vector_x';
    431         Data.VarAttribute{nbvar+7}.Role='vector_y';
    432         Data.Civ1_U_smooth=Data.Civ1_U; % zeros(size(Data.Civ1_X));
    433         Data.Civ1_V_smooth=Data.Civ1_V; %zeros(size(Data.Civ1_X));
     435        Data.VarAttribute{nbvar+5}.Role='vector_z';     
     436        Data.Civ1_U_smooth=Data.Civ1_U;
     437        Data.Civ1_V_smooth=Data.Civ1_V;
     438        Data.Civ1_W_smooth=Data.Civ1_W;
    434439        if isfield(Data,'Civ1_FF')
    435440            ind_good=find(Data.Civ1_FF==0);
    436441        else
    437             ind_good=1:numel(Data.Civ1_X);
     442            disp_uvmat('ERROR','detection of error vectors (FIX operation) needed before PATCH' ,checkrun)
     443            return
    438444        end
    439445        if isempty(ind_good)
     
    443449
    444450        % perform Patch calculation using the UVMAT fct 'filter_tps'
    445 
    446         [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,~,Ures, Vres,~,FFres]=...
    447             filter_tps([Data.Civ1_X(ind_good) Data.Civ1_Y(ind_good)],Data.Civ1_U(ind_good),Data.Civ1_V(ind_good),[],Data.Patch1_SubDomainSize,Data.Patch1_FieldSmooth,Data.Patch1_MaxDiff);
    448         Data.Civ1_U_smooth(ind_good)=Ures;% take the interpolated (smoothed) velocity values for good vectors, keep civ1 data for the other
    449         Data.Civ1_V_smooth(ind_good)=Vres;
     451Civ1_Z=0.5*Data.Civ1_W(ind_good);
     452for iz=1:numel(Data.Coord_z)
     453    Civ1_Z(iz,:,:)=Civ1_Z(iz,:,:)+Data.Coord_z(iz);
     454end
     455        [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,Data.Civ1_W_tps,...
     456            Data.Civ1_U_smooth(ind_good),Data.Civ1_V_smooth(ind_good),Data.Civ1_V_smooth(ind_good),FFres]=...
     457            filter_tps_3D([Data.Civ1_X(ind_good) Data.Civ1_Y(ind_good)],Civ_1_Z,Data.Civ1_U(ind_good),Data.Civ1_V(ind_good),Data.Civ1_W(ind_good),Data.Patch1_SubDomainSize,Data.Patch1_FieldSmooth,Data.Patch1_MaxDiff);
    450458        Data.Civ1_FF(ind_good)=uint8(FFres);
    451459        time_patch1=toc(tstart_patch1);
     
    778786ibx2=floor(par_civ.CorrBoxSize(1)/2);
    779787iby2=floor(par_civ.CorrBoxSize(2)/2);
    780 isx2=floor(par_civ.SearchBoxSize(1)/2);
    781 isy2=floor(par_civ.SearchBoxSize(2)/2);
    782 isz2=floor(par_civ.SearchBoxSize(3)/2);
     788isx2=par_civ.SearchRange(1);
     789isy2=par_civ.SearchRange(2);
     790isz2=par_civ.SearchRange(3);
    783791kref=isz2+1;%middle index of the z slice
    784792shiftx=round(par_civ.SearchBoxShift(:,1));%use the input shift estimate, rounded to the next integer value
     
    891899                    % end
    892900
    893                     npxycorr=par_civ.SearchBoxSize(1:2)-par_civ.CorrBoxSize(1:2)+1;
    894                     result_conv=zeros([par_civ.SearchBoxSize(3) npxycorr]);%initialise the conv product
    895                     max_xy=zeros(par_civ.SearchBoxSize(3),1);%initialise the max correlation vs z
     901                    npxycorr=2*par_civ.SearchRange(1:2)+1;
     902                    result_conv=zeros([2*par_civ.SearchRange(3)+1 npxycorr]);%initialise the conv product
     903                    max_xy=zeros(2*par_civ.SearchRange(3)+1,1);%initialise the max correlation vs z
    896904                    xk=ones(npz,1);%initialise the x displacement corresponding to the max corr
    897905                    yk=ones(npz,1);%initialise the y displacement corresponding to the max corr
  • trunk/src/series/civ_input.m

    r1161 r1163  
    7979        set(handles.title_z,'Visible','on')
    8080        set(handles.num_CorrBoxSize_3,'Visible','on')
    81         set(handles.num_SearchBoxSize_3,'Visible','on')
     81        set(handles.num_SearchRange_3,'Visible','on')
    8282        set(handles.num_SearchBoxShift_3,'Visible','on')
    8383        set(handles.num_Dz,'Visible','on')
     
    119119            return
    120120        end
    121         if isfield(Data,'.Civ1_ImageA')
    122         %[PathCiv1_ImageA,Civ1_ImageA,FileExtA]=fileparts(Data.Civ1_ImageA);%look for the source image A
    123         %[PathCiv1_ImageB,Civ1_ImageB,FileExtA]=fileparts(Data.Civ1_ImageB);%look for the source image B
    124         end
    125         if isfield(Data,'Civ2_ImageA')
    126             %[PathCiv2_ImageA,Civ2_ImageA,FileExtA]=fileparts(Data.Civ2_ImageA);
    127             %[PathCiv2_ImageB,Civ2_ImageB,FileExtA]=fileparts(Data.Civ2_ImageB);
    128         end
     121       
    129122        if size(Param.InputTable,1)==1
    130              if isfield(Data,'.Civ1_ImageA')
    131             series('display_file_name',hhseries,Data.Civ1_ImageA,'append');%append the image series to the input list
    132                     [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(Data.Civ1_ImageA);
    133        % [~,~,~,~,~,~,~,~,NomTypeImaB]=fileparts_uvmat(Data.Civ1_ImageB);
    134              elseif isfield(Data,'Civ2_ImageA')
    135                  series('display_file_name',hhseries,Data.Civ2_ImageA,'append');%append the image series to the input list
    136                          [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(Data.Civ2_ImageA);
    137         %[RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaB]=fileparts_uvmat(Data.Civ2_ImageB);
     123           
     124            Param.InputTable(2,:)=Param.InputTable(1,:);
     125              set(hhseries.InputTable,'Data',Param.InputTable)
     126             if isfield(Data,'Civ2_ImageA')
     127                 ImageName=Data.Civ2_ImageA;
     128             elseif isfield(Data,'Civ1_ImageA')
     129                 ImageName=Data.Civ1_ImageA;
    138130             end
    139         end
    140 
    141         iview_image=2;%line # for the input images
     131            series('display_file_name',hhseries,ImageName,1);%append the image series to the input list
     132                    [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(ImageName);
     133     
     134%              elseif isfield(Data,'Civ2_ImageA')
     135%                  series('display_file_name',hhseries,Data.Civ2_ImageA,'append');%append the image series to the input list
     136%                          [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(Data.Civ2_ImageA);
     137%     
     138%              end
     139        end
     140
     141        iview_image=1;%line # for the input images
    142142    otherwise
    143143        % if ~strcmp(FileType,'image')
     
    162162     return
    163163end
    164 MaxIndex_i=Param.IndexRange.MaxIndex_i(iview_image);
    165 MinIndex_i=Param.IndexRange.MinIndex_i(iview_image);
     164MaxIndex_i=Param.IndexRange.MaxIndex_i(1);
     165MinIndex_i=Param.IndexRange.MinIndex_i(1);
    166166MaxIndex_j=1;%default
    167167MinIndex_j=1;
     
    262262        for index = 1:ind_opening
    263263            set(handles.(ListOptions{index}),'value',0)
    264         end
    265         for index = ind_opening+1:6
    266             set(handles.(ListOptions{index}),'value',1)
    267         end
     264            set(handles.(ListOptions{index}),'String',regexprep(ListOptions{index},'Check','redo '))
     265        end
     266%         for index = ind_opening+1:6
     267%             set(handles.(ListOptions{index}),'value',1)
     268%         end
    268269        set(handles.CheckCiv3,'Visible','off')% make visible the switch 'iterate/repet' for Civ2.
    269270        set(handles.CheckCiv3,'Value',0)% select'iterate/repet' by default
     
    272273            set(handles.(ListOptions{index}),'value',0)
    273274        end
    274         for index = 4:6
    275             set(handles.(ListOptions{index}),'value',1)
    276         end
     275%         for index = 4:6
     276%             set(handles.(ListOptions{index}),'value',1)
     277%         end
    277278        set(handles.CheckCiv3,'Visible','on')% make visible the switch 'iterate/repet' for Civ2.
    278279        set(handles.CheckCiv3,'Value',1)% select'iterate/repet' by default
     
    290291if ~checkrefresh && isfield(Param,'ActionInput')&& strcmp(Param.ActionInput.Program,Param.Action.ActionName)% the program fits with the stored data
    291292    fill_GUI(Param.ActionInput,hObject);%fill the GUI with the parameters retrieved from the input Param
     293
     294    if isfield(Param.ActionInput,'Civ1')&& isfield(Param.ActionInput.Civ1,'SearchBoxSize')
     295               SearchRange=round((Param.ActionInput.Civ1.SearchBoxSize-Param.ActionInput.Civ1.CorrBoxSize)/2);
     296                set(handles.num_SearchRange_1(1),'String',num2str(SearchRange(1)))
     297                set(handles.num_SearchRange_2(1),'String',num2str(SearchRange(2)))
     298            end
     299            if isfield(Param.ActionInput,'Civ2')&& isfield(Param.ActionInput.Civ2,'SearchBoxSize')
     300               SearchRange=round((Param.ActionInput.Civ2.SearchBoxSize-Param.ActionInput.Civ2.CorrBoxSize)/2);
     301                set(handles.num_SearchRange_1(2),'String',num2str(SearchRange(1)))
     302                set(handles.num_SearchRange_2(2),'String',num2str(SearchRange(2)))
     303            end
    292304    hcheckgrid=findobj(handles.civ_input,'Tag','CheckGrid');
    293305    for ilist=1:numel(hcheckgrid)
     
    416428%Param.CheckCiv1=1;
    417429Param.Civ1.CorrBoxSize=[31 31 1];
    418 Param.Civ1.SearchBoxSize=[61 61 5];
     430Param.Civ1.SearchRange=[15 15 2];
    419431Param.Civ1.SearchBoxShift=[0 0];
    420432Param.Civ1.CorrSmooth=1;
     
    439451%Param.CheckCiv2=1;
    440452Param.Civ2.CorrBoxSize=[21 21];
    441 Param.Civ2.SearchBoxSize=[27 27];
     453Param.Civ2.SearchRange=[3 3];
    442454Param.Civ2.CorrSmooth=1;
    443455Param.Civ2.Dx=10;
     
    515527%------------------------------------------------------------------------
    516528update_CivOptions(handles,0)
     529update_frame(handles,'CheckCiv1')
     530
    517531
    518532%------------------------------------------------------------------------
     
    521535%------------------------------------------------------------------------
    522536update_CivOptions(handles,0)
     537update_frame(handles,'CheckFix1')
    523538
    524539%------------------------------------------------------------------------
     
    527542%------------------------------------------------------------------------
    528543update_CivOptions(handles,0)
     544update_frame(handles,'CheckPatch1')
     545
    529546
    530547%------------------------------------------------------------------------
     
    533550%------------------------------------------------------------------------
    534551update_CivOptions(handles,0)
     552update_frame(handles,'CheckCiv2')
    535553
    536554%------------------------------------------------------------------------
     
    539557%------------------------------------------------------------------------
    540558update_CivOptions(handles,0)
     559update_frame(handles,'CheckFix2')
    541560
    542561%------------------------------------------------------------------------
     
    545564%------------------------------------------------------------------------
    546565update_CivOptions(handles,0)
     566update_frame(handles,'CheckPatch2')
     567
     568function update_frame(handles,option)
     569if get(handles.(option),'Value')
     570    option=regexprep(option,'Check','');
     571set(handles.(option),'Visible','on')
     572children=get(handles.(option),'children');
     573set(children,'Enable','on')
     574else
     575    option=regexprep(option,'Check','');
     576    set(handles.(option),'Visible','off')
     577end
    547578
    548579%------------------------------------------------------------------------
     
    591622for ilist=1:length(options)
    592623    if checkbox(ilist)
    593         set(handles.(options{ilist}),'Visible','on')
     624%          set(handles.(options{ilist}),'Visible','on')
     625        set(handles.(options{ilist}),'Enable','on')
     626%         set(handles.(['Check' options{ilist}]),'Strin
    594627    else
    595         set(handles.(options{ilist}),'Visible','off')
     628%         set(handles.(options{ilist}),'Visible','off')
     629        set(handles.(options{ilist}),'Enable','off')
    596630    end
    597631end
     
    608642    checkeven=(mod(ActionInput.Civ1.CorrBoxSize,2)==0);
    609643    ActionInput.Civ1.CorrBoxSize(checkeven)=ActionInput.Civ1.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
    610     ActionInput.Civ1.SearchBoxSize(1:2)=max(ActionInput.Civ1.SearchBoxSize(1:2),ActionInput.Civ1.CorrBoxSize(1:2)+8);% insure that the search box size is large enough
    611     checkeven=(mod(ActionInput.Civ1.SearchBoxSize,2)==0);
    612     ActionInput.Civ1.SearchBoxSize(checkeven)=ActionInput.Civ1.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
     644    %ActionInput.Civ1.SearchBoxSize(1:2)=max(ActionInput.Civ1.SearchBoxSize(1:2),ActionInput.Civ1.CorrBoxSize(1:2)+8);% insure that the search box size is large enough
     645    %checkeven=(mod(ActionInput.Civ1.SearchBoxSize,2)==0);
     646    %ActionInput.Civ1.SearchBoxSize(checkeven)=ActionInput.Civ1.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
    613647end
    614648if isfield(ActionInput,'Civ2')
    615649    checkeven=(mod(ActionInput.Civ2.CorrBoxSize,2)==0);
    616650    ActionInput.Civ2.CorrBoxSize(checkeven)=ActionInput.Civ2.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
    617     ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+4);
    618     checkeven=(mod(ActionInput.Civ2.SearchBoxSize,2)==0);
    619     ActionInput.Civ2.SearchBoxSize(checkeven)=ActionInput.Civ2.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
     651    %ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+4);
     652    % checkeven=(mod(ActionInput.Civ2.SearchBoxSize,2)==0);
     653    %ActionInput.Civ2.SearchBoxSize(checkeven)=ActionInput.Civ2.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
    620654end
    621655
     
    10021036%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    10031037%------------------------------------------------------------------------
    1004 % --- Executes on button press in SearchRange: determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2
     1038% --- Executes on button press in SearchRange: determine the search range num_SearchRange_1,num_SearchRange_2
    10051039function SearchRange_Callback(hObject, eventdata, handles)
    10061040%------------------------------------------------------------------------
     
    10241058
    10251059%------------------------------------------------------------------------
    1026 % ---  determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2 and shift
     1060% ---  determine the search range num_SearchRange_1,num_SearchRange_2 and shift
    10271061function get_search_range(hObject, eventdata, handles)
    10281062%------------------------------------------------------------------------
     
    10561090    set(handles.num_SearchBoxShift_1,'String',num2str(shiftx));
    10571091    set(handles.num_SearchBoxShift_2,'String',num2str(shifty));
    1058     set(handles.num_SearchBoxSize_1,'String',num2str(isx));
    1059     set(handles.num_SearchBoxSize_2,'String',num2str(isy));
     1092    set(handles.num_SearchRange_1,'String',num2str(isx));
     1093    set(handles.num_SearchRange_2,'String',num2str(isy));
    10601094end
    10611095
     
    10871121currentdir=pwd;
    10881122cd(Path);%move in the dir of the root name filebase
    1089 gridfiles=dir([Name '_*grid_*.grid']);%look for grid files
     1123gridfiles=dir([Name '_*grid_*.nc']);%look for grid files
    10901124cd(currentdir);%come back to the current working directory
    10911125if ~isempty(gridfiles)
     
    11681202function CheckGrid_Callback(hObject, eventdata, handles)
    11691203%------------------------------------------------------------------------
    1170 value=get(hObject,'Value');
    1171 hparent=get(hObject,'parent');%handles of the parent panel
    1172 hchildren=get(hparent,'children');
    1173 handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel
    1174 handle_dx=findobj(hchildren,'tag','num_Dx');
    1175 handle_dy=findobj(hchildren,'tag','num_Dy');
    1176 handle_title_dx=findobj(hchildren,'tag','title_Dx');
    1177 handle_title_dy=findobj(hchildren,'tag','title_Dy');
    1178 testgrid=0;
    1179 filegrid='';
    1180 if value
    1181         hseries=findobj(allchild(0),'Tag','series');
     1204hparent=get(hObject,'parent');
     1205PanelName=get(hparent,'tag');
     1206handle_txtbox=handles.Grid
     1207if strcmp(PanelName,'civ2')
     1208    handle_txtbox=handle_txtbox(2);
     1209end
     1210% hchildren=get(hparent,'children');
     1211% handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel
     1212% handle_NbSlice=findobj(hchildren,'tag','num_NbSlice');% look for the mask name box in the same panel
     1213testgrid=false;
     1214corrstatus='on';
     1215if get(hObject,'Value')% if the checkbox is activated
     1216    hseries=findobj(allchild(0),'Tag','series');
    11821217    hhseries=guidata(hseries);
    11831218    InputTable=get(hhseries.InputTable,'Data');
    1184      ind_A=1;% line index of the (first) image series
    1185     if strcmp(InputTable{1,5},'.nc');
    1186         ind_A=2;
    1187     end
    1188     filebase=InputTable{ind_A,1};
    1189     [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name
    1190     if isequal(flag_grid,1)
    1191         filegrid=[num2str(nbslice) 'grid'];
    1192         testgrid=1;
    1193     else % browse for a grid
    1194         filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData
    1195         if exist(filegrid,'file')
    1196             filebase=filegrid;
    1197         end
    1198        filegrid = uigetfile_uvmat('pick a grid file .grid:',filebase,'.grid');
    1199         set(hObject,'UserData',filegrid);%store for future use
    1200         if ~isempty(filegrid)
    1201             testgrid=1;
    1202         end
    1203         set(hObject,'UserData',filegrid);%store for future use
     1219    % browse for a grid file
     1220    filegrid= uigetfile_uvmat('pick a grid netcdf file (made by script_makegrid.m):',InputTable{1,1},'.nc');
     1221    if ~isempty(filegrid)
     1222        [FilePath,FileName,FileExt]=fileparts(filegrid);
     1223        Data=nc2struct(filegrid);
     1224        if isfield(Data,'Grid')
     1225        testgrid=true;
     1226        end
     1227        if isfield(Data,'CorrBox')
     1228        corrstatus='off';
     1229        end
    12041230    end
    12051231end
    12061232if testgrid
    1207     set(handle_dx,'Visible','off');
    1208     set(handle_dy,'Visible','off');
    1209     set(handle_title_dy,'Visible','off');
    1210     set(handle_title_dx,'Visible','off');
    12111233    set(handle_txtbox,'Visible','on')
    12121234    set(handle_txtbox,'String',filegrid)
    1213 else
    1214     set(hObject,'Value',0);
    1215     set(handle_dx,'Visible','on');
    1216     set(handle_dy,'Visible','on');
    1217     set(handle_title_dy,'Visible','on');
    1218     set(handle_title_dx,'Visible','on');
     1235    set(handles.num_Dx,'Visible','off')
     1236    set(handles.num_Dy,'Visible','off')
     1237else
     1238    set(handles.num_Dx,'Visible','on')
     1239    set(handles.num_Dy,'Visible','on')
     1240    set(hObject,'Value',0)
    12191241    set(handle_txtbox,'Visible','off')
    12201242end
    12211243
     1244set(handles.num_CorrBoxSize_1,'Visible',corrstatus)
     1245set(handles.num_CorrBoxSize_2,'Visible',corrstatus)
     1246
     1247
    12221248%% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
    1223 PanelName=get(hparent,'tag');
    1224 if strcmp(PanelName,'Civ1')
    1225     hchildren=get(handles.Civ2,'children');
    1226     handle_checkbox=findobj(hchildren,'tag','CheckGrid');
    1227     handle_txtbox=findobj(hchildren,'tag','Grid');
    1228     handle_dx=findobj(hchildren,'tag','num_Dx');
    1229     handle_dy=findobj(hchildren,'tag','num_Dy');
    1230     handle_title_dx=findobj(hchildren,'tag','title_Dx');
    1231     handle_title_dy=findobj(hchildren,'tag','title_Dy');
    1232     set(handle_checkbox,'UserData',filegrid);%store for future use
    1233     if testgrid
    1234         set(handle_checkbox,'Value',1);
    1235         set(handle_dx,'Visible','off');
    1236         set(handle_dy,'Visible','off');
    1237         set(handle_title_dx,'Visible','off');
    1238         set(handle_title_dy,'Visible','off');
    1239         set(handle_txtbox,'Visible','on')
    1240         set(handle_txtbox,'String',filegrid)
    1241     end
    1242 end
     1249% PanelName=get(hparent,'tag');
     1250% if strcmp(PanelName,'Civ1')
     1251%     hchildren=get(handles.Civ2,'children');
     1252%     handle_checkbox=findobj(hchildren,'tag','CheckGrid');
     1253%     handle_txtbox=findobj(hchildren,'tag','Grid');
     1254%     handle_dx=findobj(hchildren,'tag','num_Dx');
     1255%     handle_dy=findobj(hchildren,'tag','num_Dy');
     1256%     handle_title_dx=findobj(hchildren,'tag','title_Dx');
     1257%     handle_title_dy=findobj(hchildren,'tag','title_Dy');
     1258%     %set(handle_checkbox,'UserData',filegrid);%store for future use
     1259%     if testgrid
     1260%         set(handle_checkbox,'Value',1);
     1261%         set(handle_dx,'Visible','off');
     1262%         set(handle_dy,'Visible','off');
     1263%         set(handle_title_dx,'Visible','off');
     1264%         set(handle_title_dy,'Visible','off');
     1265%         set(handle_txtbox,'Visible','on')
     1266%         set(handle_txtbox,'String',filegrid)
     1267%     end
     1268% end
    12431269set(handles.ConfigSource,'String','NEW')
    12441270set(handles.OK,'BackgroundColor',[1 0 1])
     
    17011727%% Civ param
    17021728% lists of parameters to enter
    1703 ListParamNum={'CorrBoxSize','SearchBoxSize','SearchBoxShift','Dx','Dy','Dz','MinIma','MaxIma'};% list of numerical values (to transform in strings)
     1729ListParamNum={'CorrBoxSize','SearchRange','SearchBoxShift','Dx','Dy','Dz','MinIma','MaxIma'};% list of numerical values (to transform in strings)
    17041730ListParamValue={'CorrSmooth','CheckGrid','CheckMask','CheckThreshold'};
    17051731ListParamString={'Grid','Mask'};
     
    17381764function fill_panel(Data,handles,panel,ListParamNum,ListParamValue,ListParamString)
    17391765children=get(handles.(panel),'children');%handles of the children of the input GUI with handle 'GUI_handle'
     1766set(children,'enable','off')
     1767set(handles.(panel),'Visible','on')
    17401768handles_panel=[];
    17411769for ichild=1:numel(children)
     
    18121840    check_input=0;
    18131841    if isfield(Param,'ActionInput')
    1814         if isfield(Param.ActionInput,'Program')&& strcmp(Param.ActionInput.Program,'civ_series')
     1842        if isfield(Param.ActionInput,'Program')&& ismember(Param.ActionInput.Program,{'civ_series','civ_3D'})
    18151843            fill_GUI(Param.ActionInput,handles.civ_input)% fill the elements of the GUI series with the input parameters
    18161844            set(handles.ConfigSource,'String',filexml)
    18171845            check_input=1;
     1846            if isfield(Param.ActionInput,'Civ1')&& isfield(Param.ActionInput.Civ1,'SearchBoxSize')
     1847               SearchRange=round((Param.ActionInput.Civ1.SearchBoxSize-Param.ActionInput.Civ1.CorrBoxSize)/2);
     1848                set(handles.num_SearchRange_1(1),'String',num2str(SearchRange(1)))
     1849                set(handles.num_SearchRange_2(1),'String',num2str(SearchRange(2)))
     1850            end
     1851            if isfield(Param.ActionInput,'Civ2')&& isfield(Param.ActionInput.Civ2,'SearchBoxSize')
     1852               SearchRange=round((Param.ActionInput.Civ2.SearchBoxSize-Param.ActionInput.Civ2.CorrBoxSize)/2);
     1853                set(handles.num_SearchRange_1(2),'String',num2str(SearchRange(1)))
     1854                set(handles.num_SearchRange_2(2),'String',num2str(SearchRange(2)))
     1855            end
    18181856            update_CivOptions(handles,0)             
    18191857        end
     
    18751913
    18761914
    1877 function num_CorrBoxSize_3_Callback(hObject, eventdata, handles)
    1878 
    1879 
    1880 function num_SearchBoxSize_3_Callback(hObject, eventdata, handles)
    18811915
    18821916
     
    18861920% --- Executes on selection change in field_ref2.
    18871921function field_ref2_Callback(hObject, eventdata, handles)
     1922
     1923
     1924
     1925function num_SearchRange_3_Callback(hObject, eventdata, handles)
     1926% hObject    handle to num_SearchRange_3 (see GCBO)
     1927% eventdata  reserved - to be defined in a future version of MATLAB
     1928% handles    structure with handles and user data (see GUIDATA)
     1929
     1930% Hints: get(hObject,'String') returns contents of num_SearchRange_3 as text
     1931%        str2double(get(hObject,'String')) returns contents of num_SearchRange_3 as a double
  • trunk/src/series/civ_series.m

    r1162 r1163  
    7575    if isfield(Data,'ActionInput') && isfield(Data.ActionInput,'PairIndices') && strcmp(Data.ActionInput.PairIndices.ListPairMode,'pair j1-j2')
    7676        Data.IndexRange_j='off';%no j index display in series
    77         % if isfield(Data.ActionInput.PairIndices,'ListPairCiv2')
    78         %     str_civ=Data.ActionInput.PairIndices.ListPairCiv2;
    79         % else
    80         %     str_civ=Data.ActionInput.PairIndices.ListPairCiv1;
    81         % end
    82         % r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names');
    83         % if isempty(r)
    84         %     r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names');
    85         %     if isempty(r)
    86         %         r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names');
    87         %     end
    88         % end
    89         % if ~isempty(r)
    90         %     Data.j_index_1=stra2num(r.num1);
    91         %     Data.j_index_2=stra2num(r.num2);
    92         % end
    9377    else
    9478        Data.IndexRange_j='on';% j index display in series if relevant
     
    361345                    ImageName_A=Param.ActionInput.RefFile;
    362346                else
    363                 ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield));
     347                    ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield));
    364348                end
    365349                if strcmp(FileExt_A,'.nc')% case of input images in format netcdf
     
    393377                end
    394378                ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(ifield),[],j2_series_Civ1(ifield));
    395                 if strcmp(FileExt_B,'.nc') % case of input images in format netcdf
    396                     FieldName_B=Param.InputFields.FieldName;
    397                     [DataIn,~,~,errormsg]=nc2struct(ImageName_B,{FieldName_B});
    398                     par_civ1.ImageB=DataIn.(FieldName_B);
    399                 else % usual image formats for image B
    400                     if isempty(FileType_B)
     379                    if isempty(FileType_B)% determine the image type for the first field
    401380                        [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
    402381                        FileType_B=FileInfo_B.FileType;
     
    407386                    end
    408387                    [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(ifield));
    409                 end
    410388            catch ME % display errors in reading input images
    411389                if ~isempty(ME.message)
     
    414392                end
    415393            end
    416             par_civ1.ImageWidth=size(par_civ1.ImageA,2);
    417             par_civ1.ImageHeight=size(par_civ1.ImageA,1);
     394            % par_civ1.ImageWidth=size(par_civ1.ImageA,2);
     395            % par_civ1.ImageHeight=size(par_civ1.ImageA,1);
    418396            list_param=(fieldnames(Param.ActionInput.Civ1))';
    419397            list_param(strcmp('TestCiv1',list_param))=[];% remove the parameter TestCiv1 from the list
     
    460438        Data.VarAttribute{5}.Role='ancillary';
    461439        Data.VarAttribute{6}.Role='errorflag';
     440
    462441        % case of mask
    463442        if par_civ1.CheckMask&&~isempty(par_civ1.Mask)
    464             if isfield(par_civ1,'NbSlice')
    465                 [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ1.Mask);
     443            [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ1.Mask);
     444            j1=1;
     445            if ~isempty(j1_series_Civ1)
     446                j1=j1_series_Civ1(ifield);
     447            end
     448            if ~isempty(i2_series_Civ1)% case of volume,masks act on different j levels
     449                maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',j1);
     450            elseif isfield(par_civ1,'NbSlice')
    466451                i1_mask=mod(i1-1,par_civ1.NbSlice)+1;
    467452                maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',i1_mask);
     
    489474            end
    490475        end
    491         if strcmp(Param.ActionInput.ListCompareMode, 'PIV volume')
    492             % Data.ListVarName=[Data.ListVarName 'Civ1_Z'];
    493             % Data.Civ1_X=[];Data.Civ1_Y=[];Data.Civ1_Z=[];
    494             % Data.Civ1_U=[];Data.Civ1_V=[];Data.Civ1_C=[];
    495             % for ivol=1:NbSlice
    496             %     % caluclate velocity data (y and v in indices, reverse to y component)
    497             %     [xtable, ytable, utable, vtable, ctable, F, result_conv, errormsg] = civ (par_civ1);
    498             %     if ~isempty(errormsg)
    499             %         disp_uvmat('ERROR',errormsg,checkrun)
    500             %         return
    501             %     end
    502             %     Data.Civ1_X=[Data.Civ1_X reshape(xtable,[],1)];
    503             %     Data.Civ1_Y=[Data.Civ1_Y reshape(Param.Civ1.ImageHeight-ytable+1,[],1)];
    504             %     Data.Civ1_Z=[Data.Civ1_Z ivol*ones(numel(xtable),1)];% z=image index in image coordinates
    505             %     Data.Civ1_U=[Data.Civ1_U reshape(utable,[],1)];
    506             %     Data.Civ1_V=[Data.Civ1_V reshape(-vtable,[],1)];
    507             %     Data.Civ1_C=[Data.Civ1_C reshape(ctable,[],1)];
    508             %     Data.Civ1_FF=[Data.Civ1_FF reshape(F,[],1)];
    509             % end
    510         else %usual PIV
    511             % caluclate velocity data (y and v in indices, reverse to y component)
    512             tstart_civ1=tic;
    513             [xtable, ytable, utable, vtable, ctable, FF, result_conv, errormsg] = civ (par_civ1);
    514             if ~isempty(errormsg)
    515                 disp_uvmat('ERROR',errormsg,checkrun)
    516                 return
    517             end
    518             Data.Civ1_X=reshape(xtable,[],1);
    519             Data.Civ1_Y=reshape(par_civ1.ImageHeight-ytable+1,[],1);
    520             Data.Civ1_U=reshape(utable,[],1);
    521             Data.Civ1_V=reshape(-vtable,[],1);
    522             Data.Civ1_C=reshape(ctable,[],1);
    523             Data.Civ1_FF=reshape(FF,[],1);
    524             time_civ1=toc(tstart_civ1);
    525         end
     476
     477        % case of input grid
     478        if par_civ1.CheckGrid &&~isempty(par_civ1.Grid)
     479            GridData=nc2struct(Param.ActionInput.Civ1.Grid);
     480            par_civ1.Grid=GridData.Grid;
     481            par_civ1.CorrBoxSize=GridData.CorrBox;
     482        end
     483
     484        % caluclate velocity data
     485        tstart_civ1=tic;
     486        [Data.Civ1_X,Data.Civ1_Y,Data.Civ1_U,Data.Civ1_V,Data.Civ1_C,Data.Civ1_FF, result_conv, errormsg] = civ (par_civ1);
     487        if ~isempty(errormsg)
     488            disp_uvmat('ERROR',errormsg,checkrun)
     489            return
     490        end
     491
    526492    else% we use existing Civ1 data
    527493        if exist('ncfile','var')
     
    603569
    604570        % perform Patch calculation using the UVMAT fct 'filter_tps'
    605         [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,tild,Ures, Vres,tild,FFres]=...
     571        [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,~,Ures, Vres,~,FFres]=...
    606572            filter_tps([Data.Civ1_X(ind_good) Data.Civ1_Y(ind_good)],Data.Civ1_U(ind_good),Data.Civ1_V(ind_good),[],Data.Patch1_SubDomainSize,Data.Patch1_FieldSmooth,Data.Patch1_MaxDiff);
    607573        Data.Civ1_U_smooth(ind_good)=Ures;% take the interpolated (smoothed) velocity values for good vectors, keep civ1 data for the other
     
    637603            end
    638604            [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A_Civ2);
    639             par_civ2.ImageWidth=FileInfo_A.Width;
    640             par_civ2.ImageHeight=FileInfo_A.Height;
    641             if isfield(par_civ2,'Grid')% grid points set as input file
    642                 if ischar(par_civ2.Grid)%read the grid file if the input is a file name
    643                     par_civ2.Grid=dlmread(par_civ2.Grid);
    644                     par_civ2.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
    645                 end
     605            [npy_ima,npx_ima]=size(par_civ2.ImageA(:,:));
     606            % par_civ2.ImageWidth=FileInfo_A.Width;
     607            % par_civ2.ImageHeight=FileInfo_A.Height;
     608
     609            if par_civ2.CheckGrid &&~isempty(par_civ2.Grid) % case of input grid
     610                GridData=nc2struct(Param.ActionInput.Civ2.Grid);
     611                par_civ2.Grid=GridData.Grid;
     612                par_civ2.CorrBoxSize=GridData.CorrBox;
     613
    646614            else% automatic grid
    647                 minix=floor(par_civ2.Dx/2)-0.5;
    648                 maxix=minix+par_civ2.Dx*floor((par_civ2.ImageWidth-1)/par_civ2.Dx);
    649                 miniy=floor(par_civ2.Dy/2)-0.5;
    650                 maxiy=minix+par_civ2.Dy*floor((par_civ2.ImageHeight-1)/par_civ2.Dy);
    651                 [GridX,GridY]=meshgrid(minix:par_civ2.Dx:maxix,miniy:par_civ2.Dy:maxiy);
     615                nbinterv_x=floor((npx_ima-1)/par_civ2.Dx);
     616                gridlength_x=nbinterv_x*par_civ2.Dx;
     617                minix=ceil((npx_ima-gridlength_x)/2);
     618                nbinterv_y=floor((npy_ima-1)/par_civ2.Dy);
     619                gridlength_y=nbinterv_y*par_civ2.Dy;
     620                miniy=ceil((npy_ima-gridlength_y)/2);
     621                [GridX,GridY]=meshgrid(minix:par_civ2.Dx:npx_ima-1,miniy:par_civ2.Dy:npy_ima-1);
     622                par_civ2.Grid=zeros(numel(GridX),2);
    652623                par_civ2.Grid(:,1)=reshape(GridX,[],1);
    653                 par_civ2.Grid(:,2)=reshape(GridY,[],1);
    654             end
    655         end
    656        
     624                par_civ2.Grid(:,2)=reshape(GridY,[],1);% increases with array index
     625
     626            end
     627        end
     628
    657629        % get the guess from patch1 or patch2 (case 'CheckCiv3')
    658         if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
    659             if isfield (par_civ2,'CheckCiv3') && par_civ2.CheckCiv3 %get the guess from  patch2
    660                 SubRange= Data.Civ2_SubRange;
    661                 NbCentres=Data.Civ2_NbCentres;
    662                 Coord_tps=Data.Civ2_Coord_tps;
    663                 U_tps=Data.Civ2_U_tps;
    664                 V_tps=Data.Civ2_V_tps;
    665                 CivStage=Data.CivStage;%store the current CivStage
    666                 Civ1_Dt=Data.Civ2_Dt;
    667                 Data=[];%reinitialise the result structure Data
    668                 Data.ListGlobalAttribute={'Conventions','Program','CivStage'};
    669                 Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes
    670                 Data.Program='civ_series';
    671                 Data.CivStage=CivStage+1;%update the current civStage after reinitialisation of Data
    672                 Data.ListVarName={};
    673                 Data.VarDimName={};
    674             else % get the guess from patch1
    675                 SubRange= Data.Civ1_SubRange;
    676                 NbCentres=Data.Civ1_NbCentres;
    677                 Coord_tps=Data.Civ1_Coord_tps;
    678                 U_tps=Data.Civ1_U_tps;
    679                 V_tps=Data.Civ1_V_tps;
    680                 Civ1_Dt=Data.Civ1_Dt;
    681                 Data.CivStage=4;
    682             end
    683         else
    684             SubRange= par_civ2.Civ1_SubRange;
    685             NbCentres=par_civ2.Civ1_NbCentres;
    686             Coord_tps=par_civ2.Civ1_Coord_tps;
    687             U_tps=par_civ2.Civ1_U_tps;
    688             V_tps=par_civ2.Civ1_V_tps;
    689             Civ1_Dt=par_civ2.Civ1_Dt;
    690             Civ2_Dt=par_civ2.Civ1_Dt;
     630        % if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
     631        if isfield (par_civ2,'CheckCiv3') && par_civ2.CheckCiv3 %get the guess from  patch2
     632            SubRange= Data.Civ2_SubRange;
     633            NbCentres=Data.Civ2_NbCentres;
     634            Coord_tps=Data.Civ2_Coord_tps;
     635            U_tps=Data.Civ2_U_tps;
     636            V_tps=Data.Civ2_V_tps;
     637            CivStage=Data.CivStage;%store the current CivStage
     638            Civ1_Dt=Data.Civ2_Dt;
     639            Data=[];%reinitialise the result structure Data
     640            Data.ListGlobalAttribute={'Conventions','Program','CivStage'};
     641            Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes
     642            Data.Program='civ_series';
     643            Data.CivStage=CivStage+1;%update the current civStage after reinitialisation of Data
    691644            Data.ListVarName={};
    692645            Data.VarDimName={};
    693         end
     646        else % get the guess from patch1
     647            SubRange= Data.Civ1_SubRange;
     648            NbCentres=Data.Civ1_NbCentres;
     649            Coord_tps=Data.Civ1_Coord_tps;
     650            U_tps=Data.Civ1_U_tps;
     651            V_tps=Data.Civ1_V_tps;
     652            Civ1_Dt=Data.Civ1_Dt;
     653            Data.CivStage=4;
     654        end
     655        % else
     656        %     SubRange= par_civ2.Civ1_SubRange;
     657        %     NbCentres=par_civ2.Civ1_NbCentres;
     658        %     Coord_tps=par_civ2.Civ1_Coord_tps;
     659        %     U_tps=par_civ2.Civ1_U_tps;
     660        %     V_tps=par_civ2.Civ1_V_tps;
     661        %     Civ1_Dt=par_civ2.Civ1_Dt;
     662        %     Civ2_Dt=par_civ2.Civ1_Dt;
     663        %     Data.ListVarName={};
     664        %     Data.VarDimName={};
     665        % end
    694666        Shiftx=zeros(size(par_civ2.Grid,1),1);% shift expected from civ1 data
    695667        Shifty=zeros(size(par_civ2.Grid,1),1);
     
    709681                epoints = par_civ2.Grid(ind_sel,:);% coordinates of interpolation sites (measurement grids)
    710682                ctrs=Coord_tps(1:nbvec_sub,:,isub) ;%(=initial points) ctrs
    711                 nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for each interpolation point (in case of subdomain overlap)
    712683                EM = tps_eval(epoints,ctrs);% thin plate spline (tps) coefficient
    713                 Shiftx(ind_sel)=Shiftx(ind_sel)+EM*U_tps(1:nbvec_sub+3,isub);%velocity shift estimated by tps from civ1
    714                 Shifty(ind_sel)=Shifty(ind_sel)+EM*V_tps(1:nbvec_sub+3,isub);
     684                CentreX=(SubRange(1,1,isub)+SubRange(1,2,isub))/2; %x posiion of the subdomain center
     685                CentreY=(SubRange(2,1,isub)+SubRange(2,2,isub))/2; %y posiion of the subdomain center
     686                xwidth=(SubRange(1,2,isub)-SubRange(1,1,isub))/pi;
     687                ywidth=(SubRange(2,2,isub)-SubRange(2,1,isub))/pi;
     688                x_dist=(epoints(:,1)-CentreX)/xwidth;
     689                y_dist=(epoints(:,2)-CentreY)/ywidth;
     690                weight=cos(x_dist).*cos(y_dist);%weighting fct =1 at the rectangle center and 0 at edge
     691                nbval(ind_sel)=nbval(ind_sel)+weight;% records the number of values for each interpolation point (in case of subdomain overlap)
     692                Shiftx(ind_sel)=Shiftx(ind_sel)+weight.*(EM*U_tps(1:nbvec_sub+3,isub));%velocity shift estimated by tps from civ1
     693                Shifty(ind_sel)=Shifty(ind_sel)+weight.*(EM*V_tps(1:nbvec_sub+3,isub));
    715694                if par_civ2.CheckDeformation
    716695                    [EMDX,EMDY] = tps_eval_dxy(epoints,ctrs);%2D matrix of distances between extrapolation points epoints and spline centres (=site points) ctrs
    717                     DUDX(ind_sel)=DUDX(ind_sel)+EMDX*U_tps(1:nbvec_sub+3,isub);
    718                     DUDY(ind_sel)=DUDY(ind_sel)+EMDY*U_tps(1:nbvec_sub+3,isub);
    719                     DVDX(ind_sel)=DVDX(ind_sel)+EMDX*V_tps(1:nbvec_sub+3,isub);
    720                     DVDY(ind_sel)=DVDY(ind_sel)+EMDY*V_tps(1:nbvec_sub+3,isub);
    721                 end
    722             end
    723         end
    724         i1=i1_series_Civ2(ifield);
    725         i2=i1;
    726         if ~isempty(i2_series_Civ2)
    727             i2=i2_series_Civ1(ifield);
    728         end
    729         j1=1;
    730         if ~isempty(j1_series_Civ2)
    731             j1=j1_series_Civ1(ifield);
    732         end
    733         j2=j1;
    734         if ~isempty(j2_series_Civ2)
    735             j2=j2_series_Civ2(ifield);
    736         end
    737         if par_civ2.CheckMask&&~isempty(par_civ2.Mask)
    738             if isfield(par_civ2,'NbSlice')
    739                 [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ2.Mask);
     696                    DUDX(ind_sel)=DUDX(ind_sel)+weight.*(EMDX*U_tps(1:nbvec_sub+3,isub));
     697                    DUDY(ind_sel)=DUDY(ind_sel)+weight.*(EMDY*U_tps(1:nbvec_sub+3,isub));
     698                    DVDX(ind_sel)=DVDX(ind_sel)+weight.*(EMDX*V_tps(1:nbvec_sub+3,isub));
     699                    DVDY(ind_sel)=DVDY(ind_sel)+weight.*(EMDY*V_tps(1:nbvec_sub+3,isub));
     700                end
     701            end
     702        end
     703        Shiftx(nbval>0)=Shiftx(nbval>0)./nbval(nbval>0);
     704        Shifty(nbval>0)=Shifty(nbval>0)./nbval(nbval>0);
     705
     706        % introduce mask
     707        if par_civ2.CheckMask && ~isempty(par_civ2.Mask)
     708            [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ2.Mask);
     709            if ~isempty(i2_series_Civ2) % we do PIV among indices i,  at given indices j (volume scan), mask depends on position j
     710                j1=1;
     711                if ~isempty(j1_series_Civ2)
     712                    j1=j1_series_Civ1(ifield);
     713                end
     714                maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',j1);
     715            elseif isfield(par_civ2,'NbSlice')
     716                i1=i1_series_Civ2(ifield);
    740717                i1_mask=mod(i1-1,par_civ2.NbSlice)+1;
    741718                maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',i1_mask);
     
    747724            else
    748725                if exist(maskname,'file')
    749                 try
    750                     par_civ2.Mask=imread(maskname);%update the mask, an store it for future use
    751                 catch ME
    752                     if ~isempty(ME.message)
    753                         errormsg=['error reading input image: ' ME.message];
    754                         disp_uvmat('ERROR',errormsg,checkrun)
    755                         return
     726                    try
     727                        par_civ2.Mask=imread(maskname);%update the mask, an store it for future use
     728                    catch ME
     729                        if ~isempty(ME.message)
     730                            errormsg=['error reading input image: ' ME.message];
     731                            disp_uvmat('ERROR',errormsg,checkrun)
     732                            return
     733                        end
    756734                    end
    757                 end
    758735                else
    759736                    par_civ2.Mask=[];
     
    772749            end
    773750        end
    774         par_civ2.SearchBoxShift=(Civ2_Dt/Civ1_Dt)*[Shiftx(nbval>=1)./nbval(nbval>=1) Shifty(nbval>=1)./nbval(nbval>=1)];
     751        par_civ2.SearchBoxShift=zeros(size(par_civ2.Grid));
     752        par_civ2.SearchBoxShift(:,1)=(Civ2_Dt/Civ1_Dt)*Shiftx;
     753        par_civ2.SearchBoxShift(:,2)=(Civ2_Dt/Civ1_Dt)*Shifty;
    775754        % shift the grid points by half the expected shift to provide the correlation box position in image A
    776         par_civ2.Grid=[par_civ2.Grid(nbval>=1,1)-par_civ2.SearchBoxShift(:,1)/2 par_civ2.Grid(nbval>=1,2)-par_civ2.SearchBoxShift(:,2)/2];
     755        %par_civ2.Grid=[par_civ2.Grid(nbval>=1,1)-par_civ2.SearchBoxShift(:,1)/2 par_civ2.Grid(nbval>=1,2)-par_civ2.SearchBoxShift(:,2)/2];
     756
    777757        if par_civ2.CheckDeformation
    778             par_civ2.DUDX=DUDX(nbval>=1)./nbval(nbval>=1);
    779             par_civ2.DUDY=DUDY(nbval>=1)./nbval(nbval>=1);
    780             par_civ2.DVDX=DVDX(nbval>=1)./nbval(nbval>=1);
    781             par_civ2.DVDY=DVDY(nbval>=1)./nbval(nbval>=1);
    782         end
    783        
     758            par_civ2.DUDX(nbval>0)=DUDX(nbval>0)./nbval(nbval>0);
     759            par_civ2.DUDY(nbval>0)=DUDY(nbval>0)./nbval(nbval>0);
     760            par_civ2.DVDX(nbval>0)=DVDX(nbval>0)./nbval(nbval>0);
     761            par_civ2.DVDY(nbval>0)=DVDY(nbval>0)./nbval(nbval>0);
     762        end
     763
    784764        % calculate velocity data (y and v in image indices, reverse to y component)
    785        
    786         [xtable, ytable, utable, vtable, ctable, FF,result_conv,errormsg] = civ (par_civ2);
    787        
     765
     766        [Data.Civ2_X,Data.Civ2_Y,Data.Civ2_U,Data.Civ2_V,Data.Civ2_C,Data.Civ2_FF,~, errormsg] = civ (par_civ2);
     767
    788768        list_param=(fieldnames(Param.ActionInput.Civ2))';
    789769        list_param(strcmp('TestCiv2',list_param))=[];% remove the parameter TestCiv2 from the list
     
    806786        end
    807787        Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ2_param];
    808        
     788
    809789        nbvar=numel(Data.ListVarName);
    810790        % define the Civ2 variable (if Civ2 data are not replaced from previous calculation)
     
    819799            Data.VarAttribute{nbvar+6}.Role='errorflag';
    820800        end
    821         Data.Civ2_X=reshape(xtable,[],1);
    822         Data.Civ2_Y=reshape(size(par_civ2.ImageA,1)-ytable+1,[],1);
    823         Data.Civ2_U=reshape(utable,[],1);
    824         Data.Civ2_V=reshape(-vtable,[],1);
    825         Data.Civ2_C=reshape(ctable,[],1);
    826         Data.Civ2_FF=reshape(FF,[],1);
    827801        disp('civ2 performed')
    828802        time_civ2=toc(tstart_civ2);
     
    837811        end
    838812    end
    839    
     813
    840814    %% Fix2
    841815    if isfield (Param.ActionInput,'Fix2')
     
    847821            Data.(Fix2_param{ilist})=Param.ActionInput.Fix2.(list_param{ilist});
    848822        end
    849         Data.ListGlobalAttribute=[Data.ListGlobalAttribute Fix2_param];     
     823        Data.ListGlobalAttribute=[Data.ListGlobalAttribute Fix2_param];
    850824        Data.Civ2_FF=double(detect_false(Param.ActionInput.Fix2,Data.Civ2_C,Data.Civ2_U,Data.Civ2_V,Data.Civ2_FF));
    851825        Data.CivStage=Data.CivStage+1;
     
    916890            disp(['time other ' num2str((time_total-time_input-time_civ1-time_patch1-time_civ2-time_patch2),2) ' s'])
    917891        end
    918     end
    919 end
    920 
    921 
    922 % 'civ': function piv.m adapted from PIVlab http://pivlab.blogspot.com/
    923 %--------------------------------------------------------------------------
    924 % function [xtable ytable utable vtable typevector] = civ (image1,image2,ibx,iby step, subpixfinder, mask, roi)
    925 %
    926 % OUTPUT:
    927 % xtable: set of x coordinates
    928 % ytable: set of y coordinates
    929 % utable: set of u displacements (along x)
    930 % vtable: set of v displacements (along y)
    931 % ctable: max image correlation for each vector
    932 % typevector: set of flags, =1 for good, =0 for NaN vectors
    933 %
    934 %INPUT:
    935 % par_civ: structure of input parameters, with fields:
    936 %  .ImageA: first image for correlation (matrix)
    937 %  .ImageB: second image for correlation(matrix)
    938 %  .CorrBoxSize: 1,2 vector giving the size of the correlation box in x and y
    939 %  .SearchBoxSize:  1,2 vector giving the size of the search box in x and y
    940 %  .SearchBoxShift: 1,2 vector or 2 column matrix (for civ2) giving the shift of the search box in x and y
    941 %  .CorrSmooth: =1 or 2 determines the choice of the sub-pixel determination of the correlation max
    942 %  .ImageWidth: nb of pixels of the image in x
    943 %  .Dx, Dy: mesh for the PIV calculation
    944 %  .Grid: grid giving the PIV calculation points (alternative to .Dx .Dy): centres of the correlation boxes in Image A
    945 %  .Mask: name of a mask file or mask image matrix itself
    946 %  .MinIma: thresholds for image luminosity
    947 %  .MaxIma
    948 %  .CheckDeformation=1 for subpixel interpolation and image deformation (linear transform)
    949 %  .DUDX: matrix of deformation obtained from patch at each grid point
    950 %  .DUDY
    951 %  .DVDX:
    952 %  .DVDY
    953 
    954 function [xtable,ytable,utable,vtable,ctable,FF,result_conv,errormsg] = civ (par_civ)
    955 
    956 %% prepare measurement grid
    957 if isfield(par_civ,'Grid')% grid points set as input, central positions of the sub-images in image A
    958     if ischar(par_civ.Grid)%read the grid file if the input is a file name (grid in x, y image coordinates)
    959         par_civ.Grid=dlmread(par_civ.Grid);
    960         par_civ.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
    961     end
    962     % else par_civ.Grid is already an array, no action here
    963 else% automatic grid in x, y image coordinates
    964 nbinterv_x=floor((par_civ.ImageWidth-1)/par_civ.Dx);
    965 gridlength_x=nbinterv_x*par_civ.Dx;
    966 minix=ceil((par_civ.ImageWidth-gridlength_x)/2);
    967 nbinterv_y=floor((par_civ.ImageHeight-1)/par_civ.Dy);
    968 gridlength_y=nbinterv_y*par_civ.Dy;
    969 miniy=ceil((par_civ.ImageHeight-gridlength_y)/2);
    970 [GridX,GridY]=meshgrid(minix:par_civ.Dx:par_civ.ImageWidth-1,miniy:par_civ.Dy:par_civ.ImageHeight-1);
    971     par_civ.Grid(:,1)=reshape(GridX,[],1);
    972     par_civ.Grid(:,2)=reshape(GridY,[],1);% increases with array index
    973     %
    974     % minix=floor(par_civ.Dx/2)-0.5;
    975     % maxix=minix+par_civ.Dx*floor((par_civ.ImageWidth-1)/par_civ.Dx);
    976     % miniy=floor(par_civ.Dy/2)-0.5;% first automatic grid point at half the mesh Dy
    977     % maxiy=minix+par_civ.Dy*floor((par_civ.ImageHeight-1)/par_civ.Dy);
    978     % [GridX,GridY]=meshgrid(minix:par_civ.Dx:maxix,miniy:par_civ.Dy:maxiy);
    979     % par_civ.Grid(:,1)=reshape(GridX,[],1);
    980     % par_civ.Grid(:,2)=reshape(GridY,[],1);% increases with array index
    981 end
    982 nbvec=size(par_civ.Grid,1);
    983 
    984 %% prepare correlation and search boxes
    985 ibx2=floor(par_civ.CorrBoxSize(1)/2);
    986 iby2=floor(par_civ.CorrBoxSize(2)/2);
    987 isx2=floor(par_civ.SearchBoxSize(1)/2);
    988 isy2=floor(par_civ.SearchBoxSize(2)/2);
    989 shiftx=round(par_civ.SearchBoxShift(:,1));%use the input shift estimate, rounded to the next integer value
    990 shifty=-round(par_civ.SearchBoxShift(:,2));% sign minus because image j index increases when y decreases
    991 if numel(shiftx)==1% case of a unique shift for the whole field( civ1)
    992     shiftx=shiftx*ones(nbvec,1);
    993     shifty=shifty*ones(nbvec,1);
    994 end
    995 %TODO: shift the origin by -shift/2
    996 
    997 %% Array initialisation and default output  if par_civ.CorrSmooth=0 (just the grid calculated, no civ computation)
    998 xtable=round(par_civ.Grid(:,1)+0.5)-0.5;
    999 ytable=round(par_civ.ImageHeight-par_civ.Grid(:,2)+0.5)-0.5;% y index corresponding to the position in image coordiantes
    1000 utable=shiftx;%zeros(nbvec,1);
    1001 vtable=shifty;%zeros(nbvec,1);
    1002 ctable=zeros(nbvec,1);
    1003 FF=zeros(nbvec,1);
    1004 result_conv=[];
    1005 errormsg='';
    1006 
    1007 %% prepare mask
    1008 if isfield(par_civ,'Mask') && ~isempty(par_civ.Mask)
    1009     if strcmp(par_civ.Mask,'all')
    1010         return    % get the grid only, no civ calculation
    1011     elseif ischar(par_civ.Mask)
    1012         par_civ.Mask=imread(par_civ.Mask);% read the mask if not allready done
    1013     end
    1014 end
    1015 check_MinIma=isfield(par_civ,'MinIma');% test for image luminosity threshold
    1016 check_MaxIma=isfield(par_civ,'MaxIma') && ~isempty(par_civ.MaxIma);
    1017 
    1018 par_civ.ImageA=sum(double(par_civ.ImageA),3);%sum over rgb component for color images
    1019 par_civ.ImageB=sum(double(par_civ.ImageB),3);
    1020 [npy_ima,npx_ima]=size(par_civ.ImageA);
    1021 if ~isequal(size(par_civ.ImageB),[npy_ima npx_ima])
    1022     errormsg='image pair with unequal size';
    1023     return
    1024 end
    1025 
    1026 %% Apply mask
    1027 % Convention for mask, IDEAS NOT IMPLEMENTED
    1028 % mask >200 : velocity calculated
    1029 %  200 >=mask>150;velocity not calculated, interpolation allowed (bad spots)
    1030 % 150>=mask >100: velocity not calculated, nor interpolated
    1031 %  100>=mask> 20: velocity not calculated, impermeable (no flux through mask boundaries)
    1032 %  20>=mask: velocity=0
    1033 checkmask=0;
    1034 MinA=min(min(par_civ.ImageA));
    1035 %MinB=min(min(par_civ.ImageB));
    1036 %check_undefined=false(size(par_civ.ImageA));
    1037 if isfield(par_civ,'Mask') && ~isempty(par_civ.Mask)
    1038     checkmask=1;
    1039     if ~isequal(size(par_civ.Mask),[npy_ima npx_ima])
    1040         errormsg='mask must be an image with the same size as the images';
    1041         return
    1042     end
    1043     check_undefined=(par_civ.Mask<200 & par_civ.Mask>=20 );
    1044 end
    1045 
    1046 %% compute image correlations: MAINLOOP on velocity vectors
    1047 corrmax=0;
    1048 sum_square=1;% default
    1049 mesh=1;% default
    1050 CheckDeformation=isfield(par_civ,'CheckDeformation')&& par_civ.CheckDeformation==1;
    1051 if CheckDeformation
    1052     mesh=0.25;%mesh in pixels for subpixel image interpolation (x 4 in each direction)
    1053     par_civ.CorrSmooth=2;% use SUBPIX2DGAUSS (take into account more points near the max)
    1054 end
    1055  
    1056 if par_civ.CorrSmooth~=0 % par_civ.CorrSmooth=0 implies no civ computation (just input image and grid points given)
    1057     for ivec=1:nbvec
    1058         iref=round(par_civ.Grid(ivec,1)+0.5);% xindex on the image A for the middle of the correlation box
    1059         jref=round(par_civ.ImageHeight-par_civ.Grid(ivec,2)+0.5);%  j index  for the middle of the correlation box in the image A
    1060         FF(ivec)=0;
    1061         subrange1_x=iref-ibx2:iref+ibx2;% x indices defining the first subimage
    1062         subrange1_y=jref-iby2:jref+iby2;% y indices defining the first subimage
    1063         subrange2_x=iref+shiftx(ivec)-isx2:iref+shiftx(ivec)+isx2;%x indices defining the second subimage
    1064         subrange2_y=jref+shifty(ivec)-isy2:jref+shifty(ivec)+isy2;%y indices defining the second subimage
    1065         image1_crop=MinA*ones(numel(subrange1_y),numel(subrange1_x));% default value=min of image A
    1066         image2_crop=MinA*ones(numel(subrange2_y),numel(subrange2_x));% default value=min of image A
    1067         check1_x=subrange1_x>=1 & subrange1_x<=par_civ.ImageWidth;% check which points in the subimage 1 are contained in the initial image 1
    1068         check1_y=subrange1_y>=1 & subrange1_y<=par_civ.ImageHeight;
    1069         check2_x=subrange2_x>=1 & subrange2_x<=par_civ.ImageWidth;% check which points in the subimage 2 are contained in the initial image 2
    1070         check2_y=subrange2_y>=1 & subrange2_y<=par_civ.ImageHeight;
    1071         image1_crop(check1_y,check1_x)=par_civ.ImageA(subrange1_y(check1_y),subrange1_x(check1_x));%extract a subimage (correlation box) from image A
    1072         image2_crop(check2_y,check2_x)=par_civ.ImageB(subrange2_y(check2_y),subrange2_x(check2_x));%extract a larger subimage (search box) from image B
    1073         if checkmask
    1074             mask1_crop=ones(numel(subrange1_y),numel(subrange1_x));% default value=1 for mask
    1075             mask2_crop=ones(numel(subrange2_y),numel(subrange2_x));% default value=1 for mask
    1076             mask1_crop(check1_y,check1_x)=check_undefined(subrange1_y(check1_y),subrange1_x(check1_x));%extract a mask subimage (correlation box) from image A
    1077             mask2_crop(check2_y,check2_x)=check_undefined(subrange2_y(check2_y),subrange2_x(check2_x));%extract a mask subimage (search box) from image B
    1078             sizemask=sum(sum(mask1_crop))/(numel(subrange1_y)*numel(subrange1_x));%size of the masked part relative to the correlation sub-image
    1079             if sizemask > 1/2% eliminate point if more than half of the correlation box is masked
    1080                 FF(ivec)=1; %
    1081                 utable(ivec)=NaN;
    1082                 vtable(ivec)=NaN;
    1083             else
    1084                 image1_crop=image1_crop.*~mask1_crop;% put to zero the masked pixels (mask1_crop='true'=1)
    1085                 image2_crop=image2_crop.*~mask2_crop;
    1086                 image1_mean=mean(mean(image1_crop))/(1-sizemask);
    1087                 image2_mean=mean(mean(image2_crop))/(1-sizemask);
    1088             end
    1089         else
    1090             image1_mean=mean(mean(image1_crop));
    1091             image2_mean=mean(mean(image2_crop));
    1092         end
    1093         %threshold on image minimum
    1094         if FF(ivec)==0
    1095             if check_MinIma && (image1_mean < par_civ.MinIma || image2_mean < par_civ.MinIma)
    1096                 FF(ivec)=1;
    1097                 %threshold on image maximum
    1098             elseif check_MaxIma && (image1_mean > par_civ.MaxIma || image2_mean > par_civ.MaxIma)
    1099                 FF(ivec)=1;
    1100             end
    1101             if FF(ivec)==1
    1102                 utable(ivec)=NaN;
    1103                 vtable(ivec)=NaN;
    1104             else
    1105                 %mask
    1106                 if checkmask
    1107                     image1_crop=(image1_crop-image1_mean).*~mask1_crop;%substract the mean, put to zero the masked parts
    1108                     image2_crop=(image2_crop-image2_mean).*~mask2_crop;
    1109                 else
    1110                     image1_crop=(image1_crop-image1_mean);
    1111                     image2_crop=(image2_crop-image2_mean);
    1112                 end
    1113                 %deformation
    1114                 if CheckDeformation
    1115                     xi=(1:mesh:size(image1_crop,2));
    1116                     yi=(1:mesh:size(image1_crop,1))';
    1117                     [XI,YI]=meshgrid(xi-ceil(size(image1_crop,2)/2),yi-ceil(size(image1_crop,1)/2));
    1118                     XIant=XI-par_civ.DUDX(ivec)*XI+par_civ.DUDY(ivec)*YI+ceil(size(image1_crop,2)/2);
    1119                     YIant=YI+par_civ.DVDX(ivec)*XI-par_civ.DVDY(ivec)*YI+ceil(size(image1_crop,1)/2);
    1120                     image1_crop=interp2(image1_crop,XIant,YIant);
    1121                     image1_crop(isnan(image1_crop))=0;
    1122                     xi=(1:mesh:size(image2_crop,2));
    1123                     yi=(1:mesh:size(image2_crop,1))';
    1124                     image2_crop=interp2(image2_crop,xi,yi,'*spline');
    1125                     image2_crop(isnan(image2_crop))=0;
    1126                 end
    1127                 sum_square=sum(sum(image1_crop.*image1_crop));
    1128                 %reference: Oliver Pust, PIV: Direct Cross-Correlation
    1129                 %%%%%% correlation calculation
    1130                 result_conv= conv2(image2_crop,flip(flip(image1_crop,2),1),'valid');
    1131                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1132                 corrmax= max(max(result_conv));
    1133        
    1134                 %result_conv=(result_conv/corrmax); %normalize, peak=always 255
    1135                 %Find the correlation max, at 255
    1136                 [y,x] = find(result_conv==corrmax,1);
    1137                 subimage2_crop=image2_crop(y:y+2*iby2/mesh,x:x+2*ibx2/mesh);%subimage of image 2 corresponding to the optimum displacement of first image
    1138                 sum_square=sum_square*sum(sum(subimage2_crop.*subimage2_crop));% product of variances of image 1 and 2
    1139                 sum_square=sqrt(sum_square);% srt of the variance product to normalise correlation
    1140                 if ~isempty(y) && ~isempty(x)
    1141                     try
    1142                         if par_civ.CorrSmooth==1
    1143                             [vector,FF(ivec)] = SUBPIXGAUSS (result_conv,x,y);
    1144                         elseif par_civ.CorrSmooth==2
    1145                             [vector,FF(ivec)] = SUBPIX2DGAUSS (result_conv,x,y);
    1146                         else
    1147                             [vector,FF(ivec)] = quadr_fit(result_conv,x,y);
    1148                         end
    1149                         utable(ivec)=vector(1)*mesh+shiftx(ivec);
    1150                         vtable(ivec)=vector(2)*mesh+shifty(ivec);
    1151                         xtable(ivec)=iref+utable(ivec)/2-0.5;% convec flow (velocity taken at the point middle from imgae 1 and 2)
    1152                         ytable(ivec)=jref+vtable(ivec)/2-0.5;% and position of pixel 1=0.5 (convention for image coordinates=0 at the edge)
    1153                         iref=round(xtable(ivec)+0.5);% nearest image index for the middle of the vector
    1154                         jref=round(ytable(ivec)+0.5);
    1155                         % eliminate vectors located in the mask
    1156                         if  checkmask && (iref<1 || jref<1 ||iref>npx_ima || jref>npy_ima ||( par_civ.Mask(jref,iref)<200 && par_civ.Mask(jref,iref)>=100))
    1157                             utable(ivec)=0;
    1158                             vtable(ivec)=0;
    1159                             FF(ivec)=1;
    1160                         end
    1161                         ctable(ivec)=corrmax/sum_square;% correlation value
    1162                     catch ME
    1163                         FF(ivec)=1;
    1164                         disp(ME.message)
    1165                     end
    1166                 else
    1167                     FF(ivec)=1;
    1168                 end
    1169             end
    1170         end
    1171     end
    1172 end
    1173 result_conv=result_conv*corrmax/sum_square;% keep the last (not normalised) correlation matrix for output
    1174 
    1175 %------------------------------------------------------------------------
    1176 % --- Find the maximum of the correlation function with subpixel resolution
    1177 % make a fit with a gaussian curve from the three correlation values across the max, along each direction.
    1178 % OUPUT:
    1179 % vector = optimum displacement vector with subpixel correction
    1180 % FF =flag: =0 OK
    1181 %           =1 , max too close to the edge of the search box (1 pixel margin)
    1182 % INPUT:
    1183 % result_conv: 2D correlation fct
    1184 % x,y: position of the maximum correlation at integer values
    1185 
    1186 function [vector,FF] = SUBPIXGAUSS (result_conv,x,y)
    1187 %------------------------------------------------------------------------
    1188 % vector=[0 0]; %default
    1189 FF=true;% error flag for vector truncated by the limited search box
    1190 [npy,npx]=size(result_conv);
    1191 
    1192 peaky = y; peakx=x;
    1193 if y < npy && y > 1 && x < npx-1 && x > 1
    1194    FF=false; % no error by the limited search box
    1195     max_conv=result_conv(y,x);% max correlation
    1196     %peak2noise= max(4,max_conv/std(reshape(result_conv,1,[])));% ratio of max conv to standard deviation of correlations (estiamtion of noise level), set to value 4 if it is too low
    1197     peak2noise=100;% TODO: make this threshold more precise, depending on the image noise
    1198     result_conv=result_conv*peak2noise/max_conv;% renormalise the correlation with respect to the noise
    1199     result_conv(result_conv<1)=1; %set to 1 correlation values smaller than 1  (=0 by discretisation, to avoid divergence in the log)
    1200    
    1201     f0 = log(result_conv(y,x));
    1202     f1 = log(result_conv(y-1,x));
    1203     f2 = log(result_conv(y+1,x));
    1204     peaky = peaky+ (f1-f2)/(2*f1-4*f0+2*f2);
    1205     f1 = log(result_conv(y,x-1));
    1206     f2 = log(result_conv(y,x+1));
    1207     peakx = peakx+ (f1-f2)/(2*f1-4*f0+2*f2);
    1208 end
    1209 
    1210 vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];
    1211 
    1212 %------------------------------------------------------------------------
    1213 % --- Find the maximum of the correlation function after interpolation
    1214 function [vector,FF] = SUBPIX2DGAUSS (result_conv,x,y)
    1215 %------------------------------------------------------------------------
    1216 % vector=[0 0]; %default
    1217 FF=true;
    1218 peaky=y;
    1219 peakx=x;
    1220 [npy,npx]=size(result_conv);
    1221 if (x < npx) && (y < npy) && (x > 1) && (y > 1)
    1222     FF=false;
    1223 max_conv=result_conv(y,x);% max correlation
    1224     peak2noise= max(4,max_conv/std(reshape(result_conv,1,[])));% ratio of max conv to standard deviation of correlations (estiamtion of noise level), set to value 4 if it is too low
    1225     result_conv=result_conv*peak2noise/max_conv;% renormalise the correlation with respect to the noise
    1226     result_conv(result_conv<1)=1; %set to 1 correlation values smaller than 1  (=0 by discretisation, to avoid divergence in the log)
    1227     for i=-1:1
    1228         for j=-1:1
    1229   %following 15 lines based on  H. Nobach and M. Honkanen (2005)
    1230   % Two-dimensional Gaussian regression for sub-pixel displacement
    1231   % estimation in particle image velocimetry or particle position
    1232   % estimation in particle tracking velocimetry
    1233   % Experiments in Fluids (2005) 38: 511-515
    1234             c10(j+2,i+2)=i*log(result_conv(y+j, x+i));
    1235             c01(j+2,i+2)=j*log(result_conv(y+j, x+i));
    1236             c11(j+2,i+2)=i*j*log(result_conv(y+j, x+i));
    1237             c20(j+2,i+2)=(3*i^2-2)*log(result_conv(y+j, x+i));
    1238             c02(j+2,i+2)=(3*j^2-2)*log(result_conv(y+j, x+i));
    1239         end
    1240     end
    1241     c10=(1/6)*sum(sum(c10));
    1242     c01=(1/6)*sum(sum(c01));
    1243     c11=(1/4)*sum(sum(c11));
    1244     c20=(1/6)*sum(sum(c20));
    1245     c02=(1/6)*sum(sum(c02));
    1246     deltax=(c11*c01-2*c10*c02)/(4*c20*c02-c11*c11);
    1247     deltay=(c11*c10-2*c01*c20)/(4*c20*c02-c11*c11);
    1248     if abs(deltax)<1
    1249         peakx=x+deltax;
    1250     end
    1251     if abs(deltay)<1
    1252         peaky=y+deltay;
    1253     end
    1254 end
    1255 vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];
    1256 
    1257 %------------------------------------------------------------------------
    1258 % --- Find the maximum of the correlation function after quadratic interpolation
    1259 function [vector,F] = quadr_fit(result_conv,x,y)
    1260 [npy,npx]=size(result_conv);
    1261 if x<4 || y<4 || npx-x<4 ||npy-y <4
    1262     F=1;
    1263     vector=[x y];
    1264 else
    1265     F=0;
    1266     x_ind=x-4:x+4;
    1267     y_ind=y-4:y+4;
    1268     x_vec=0.25*(x_ind-x);
    1269     y_vec=0.25*(y_ind-y);
    1270     [X,Y]=meshgrid(x_vec,y_vec);
    1271     coord=[reshape(X,[],1) reshape(Y,[],1)];
    1272     result_conv=reshape(result_conv(y_ind,x_ind),[],1);
    1273    
    1274    
    1275     % n=numel(X);
    1276     % x=[X Y];
    1277     % X=X-0.5;
    1278     % Y=Y+0.5;
    1279     % y = (X.*X+2*Y.*Y+X.*Y+6) + 0.1*rand(n,1);
    1280     p = polyfitn(coord,result_conv,2);
    1281     A(1,1)=2*p.Coefficients(1);
    1282     A(1,2)=p.Coefficients(2);
    1283     A(2,1)=p.Coefficients(2);
    1284     A(2,2)=2*p.Coefficients(4);
    1285     vector=[x y]'-A\[p.Coefficients(3) p.Coefficients(5)]';
    1286     vector=vector'-[floor(npx/2) floor(npy/2)]-1 ;
    1287     % zg = polyvaln(p,coord);
    1288     % figure
    1289     % surf(x_vec,y_vec,reshape(zg,9,9))
    1290     % hold on
    1291     % plot3(X,Y,reshape(result_conv,9,9),'o')
    1292     % hold off
    1293 end
    1294 
    1295 
    1296 function FF=detect_false(Param,C,U,V,FFIn)
    1297 FF=FFIn;%default, good vectors
    1298 % FF=1, for correlation max at edge, not set in this function
    1299 % FF=2, for too small correlation
    1300 % FF=3, for velocity outside bounds
    1301 % FF=4 for exclusion by difference with the smoothed field, set by call to function filter_tps
    1302 
    1303 if isfield (Param,'MinCorr')
    1304      FF(C<Param.MinCorr & FFIn==0)=2;
    1305 end
    1306 if (isfield(Param,'MinVel')&&~isempty(Param.MinVel))||(isfield (Param,'MaxVel')&&~isempty(Param.MaxVel))
    1307     Umod= U.*U+V.*V;
    1308     if isfield (Param,'MinVel')&&~isempty(Param.MinVel)
    1309         U2Min=Param.MinVel*Param.MinVel;
    1310         FF(Umod<U2Min & FFIn==0)=3;
    1311     end
    1312     if isfield (Param,'MaxVel')&&~isempty(Param.MaxVel)
    1313          U2Max=Param.MaxVel*Param.MaxVel;
    1314         FF(Umod>U2Max & FFIn==0)=3;
    1315892    end
    1316893end
     
    1378955end
    1379956
    1380 
    1381 
    1382 
     957function FF=detect_false(Param,C,U,V,FFIn)
     958FF=FFIn;%default, good vectors
     959% FF=1, for correlation max at edge, not set in this function
     960% FF=2, for too small correlation
     961% FF=3, for velocity outside bounds
     962% FF=4 for exclusion by difference with the smoothed field, set by call to function filter_tps
     963
     964if isfield (Param,'MinCorr')
     965     FF(C<Param.MinCorr & FFIn==0)=2;
     966end
     967if (isfield(Param,'MinVel')&&~isempty(Param.MinVel))||(isfield (Param,'MaxVel')&&~isempty(Param.MaxVel))
     968    Umod= U.*U+V.*V;
     969    if isfield (Param,'MinVel')&&~isempty(Param.MinVel)
     970        U2Min=Param.MinVel*Param.MinVel;
     971        FF(Umod<U2Min & FFIn==0)=3;
     972    end
     973    if isfield (Param,'MaxVel')&&~isempty(Param.MaxVel)
     974         U2Max=Param.MaxVel*Param.MaxVel;
     975        FF(Umod>U2Max & FFIn==0)=3;
     976    end
     977end
     978
     979
     980
  • trunk/src/series/extract_multitif.m

    r1149 r1163  
    8585    ParamOut.OutputDirExt='.png';%set the output dir extension
    8686    ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
    87     ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1)
     87    ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default='off')
    8888    ParamOut.CPUTime=10;% expected time for writting the output of one source image ( in minute)
    8989    %% root input file(s) and type
     90 
    9091    % check the existence of the first file in the series
    91         first_j=[];% note that the function will propose to cover the whole range of indices
    92     if isfield(Param.IndexRange,'MinIndex_j'); first_j=Param.IndexRange.MinIndex_j; end
     92    first_j=[];% note that the function will propose to cover the whole range of indices
     93    if isfield(Param.IndexRange,'MinIndex_j')
     94        first_j=Param.IndexRange.MinIndex_j;
     95    else
     96        msgbox_uvmat('ERROR',['select a multitif file labeled by a number, like im@0001.tif '])
     97        return
     98    end
    9399    PairString='';
    94100    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
     
    99105        msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
    100106    end
    101     ParamOut.NbSlice=Param.IndexRange.MaxIndex_i;
    102     %% check the validity of  input file types
    103     FileInfo=get_file_info(FirstFileName);
    104     if ~strcmp(FileInfo.FileType,'multimage')
     107       FileInfo=get_file_info(FirstFileName);
     108    if ~strcmp(FileInfo.FileType,'multimage')%check the validity of  input file types
    105109        msgbox_uvmat('ERROR',['invalid file type input: ' FileInfo.FileType ' not a tiff image series'])
    106110        return
    107111    end
     112   
     113    ParamOut.NbSlice=Param.IndexRange.MaxIndex_i;
     114   
    108115    ParamOut.ActionInput.XmlFile=uigetfile_uvmat('pick xml file for timing',fileparts(fileparts(FirstFileName)),'.xml'); 
    109116    return
  • trunk/src/series/extract_rdvision.m

    r1161 r1163  
    7171        ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
    7272        ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
    73         ParamOut.CPUTime=0.1;% expected time for writting one image ( in minute)
     73         ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1)
     74        ParamOut.CPUTime=0.25;% expected time for writting one image ( in minute)
    7475    ParamOut.OutputDirExt='.extract';%set the output dir extension
    7576    ParamOut.OutputSubDirMode='one'; %output folder given by the folder name of the first input line
     
    159160            timestamp(ii)=m.Data(ii).timestamp;
    160161        end
     162       
     163%         
     164%         %%%%%BRICOLAGE EXP40
     165%         ind1=5*59-10;
     166%         ind2=12*59-10;
     167%         ind3=119*59-10;
     168%         ind4=483*59-10;
     169%         timestamp=[timestamp(1:ind4) timestamp(ind4) timestamp(ind4+1:end)];
     170%          timestamp=[timestamp(1:ind3) timestamp(ind3) timestamp(ind3+1:end)];
     171%           timestamp=[timestamp(1:ind2) timestamp(ind2) timestamp(ind2+1:end)];
     172%            timestamp=[timestamp(1:ind1) timestamp(ind1) timestamp(ind1+1:end)];
     173%            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     174           
     175           
    161176        if ParamOut.ActionInput.Createxml
    162177            ParamOut.ActionInput.XmlData.Camera.BurstTiming=time2xmlburst(timestamp,ParamOut.ActionInput.BurstLength);
     
    174189        difftime=timestamp-timexml;
    175190        %if max(difftime)>0.01
     191
    176192        figure
    177193        plot(timestamp,difftime)
     
    367383end
    368384
    369 [BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew,Param.IndexRange.first_i,Param.IndexRange.last_i);
     385[BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew,Param.IndexRange.first_i,Param.IndexRange.last_i,Param.CheckOverwrite);
    370386if ~isempty(errormsg)
    371387    disp_uvmat('ERROR',errormsg,checkrun)
     
    387403
    388404%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    389 function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew,first,last)
     405function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew,first,last,checkoverwrite)
    390406% BINREAD_RDV Permet de lire les fichiers bin g???n???r???s par Hiris ??? partir du
    391407% fichier seq associ???.
     
    442458bin_file_counter=0;
    443459%for ii=1:SeqData.nb_frames
     460 %%%%%BRICOLAGE EXP40
     461        ind1=5*59-10;
     462        ind2=12*59-10;
     463        ind3=119*59-10;
     464        ind4=483*59-10;
     465
    444466for ii=first:last
    445467    j1=[];
     468    iinew=ii;
     469%     %%%%%BRICOLAGE EXP40
     470%     switch ii
     471%         case  ii>=ind1 && ii<ind2
     472%       iinew=ii+1;
     473%         case ii>=ind2 && ii<ind3
     474%         iinew=ii+2;
     475%         case  ii>=ind3 && ii<ind4
     476%       iinew=ii+3;
     477%         case       ii>=ind4 && ii<ind3
     478%         iinew=ii+4;   
     479%     end
     480%      %%%%%%%%%
    446481    if ~isequal(nbfield2,1)
    447         j1=mod(ii-1,nbfield2)+1;
    448     end
    449     i1=floor((ii-1)/nbfield2)+1;
     482        j1=mod(iinew-1,nbfield2)+1;
     483    end
     484    i1=floor((iinew-1)/nbfield2)+1;
     485   
    450486    OutputFile=fullfile_uvmat(PathDir,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
    451487    fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx));
    452     if exist(OutputFile,'file')% do not recreate existing image file
     488    if  ~checkoverwrite && exist(OutputFile,'file') % manage the overwrite of existing files (default=1) % manage the overwrite of existing files (default=1)exist(OutputFile,'file')% do not recreate existing image file
    453489        fid=0;
    454490    else
  • trunk/src/uvmat.m

    r1162 r1163  
    20632063set(hhseries.ActionName,'Value',index_action);
    20642064series('ActionName_Callback',hObject,[],hhseries); %file input with xml reading  in uvmat, show the image in phys coordinates
     2065series('ActionInput_Callback',hObject,[],hhseries); %open the menu or options from INPUT in series
    20652066end
    20662067
Note: See TracChangeset for help on using the changeset viewer.