Changeset 856 for trunk/src


Ignore:
Timestamp:
Jan 26, 2015, 12:37:56 AM (9 years ago)
Author:
sommeria
Message:

civtest_implemented_civ2

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/browse_data.m

    r837 r856  
    2424function varargout = browse_data(varargin)
    2525
    26 % Last Modified by GUIDE v2.5 11-Mar-2014 22:09:37
     26% Last Modified by GUIDE v2.5 24-Jan-2015 16:55:04
    2727
    2828% Begin initialization code - DO NOT EDIT
     
    4747%------------------------------------------------------------------------
    4848% --- Executes just before browse_data is made visible.
    49 function browse_data_OpeningFcn(hObject, eventdata, handles, Campaign,EnableMirror)
     49function browse_data_OpeningFcn(hObject, eventdata, handles, DataSeries,EnableMirror)
    5050%------------------------------------------------------------------------
    5151
     
    8080    set(handles.mirror_txt,'Visible','off')
    8181end
    82 if exist('Campaign','var')
    83     [tild,CampaignName]=fileparts(Campaign);
    84     RootXml=fullfile(Campaign,[CampaignName '.xml']);
    85     s=[];
    86     if exist(RootXml,'file')
    87         [s,Heading]=xml2struct(RootXml);%read the xml file
    88         if isfield(s,'SourceDir')
    89             set(handles.SourceDir,'String',s.SourceDir);%display the source dir if a mirror has been opened
    90             set(handles.MirrorDir,'Visible','on');%  mirror dir display
    91             set(handles.MirrorDir,'String',Campaign);%display the opened mirror dir
    92             set(handles.CreateMirror,'String','update_mirror')
    93         end
    94     end
    95     if isempty(s) %a source dir has been opened
    96         set(handles.SourceDir,'String',Campaign);
    97         set(handles.MirrorDir,'Visible','off');% no mirror dir display
    98         set(handles.CreateMirror,'String','create_mirror')
    99     end
    100     errormsg=scan_campaign(handles,Campaign);
    101     if ~isempty(errormsg)
    102         msgbox_uvmat('ERROR',errormsg)
    103         return
    104     end
    105     set(handles.OK,'Visible','on')
    106     set(handles.Cancel,'Visible','on')
    107     set(handles.browse_data,'WindowStyle','modal')% Make the GUI modal
    108     set(hObject,'Visible','on')
    109     drawnow
    110     % UIWAIT makes GUI wait for user response (see UIRESUME)
    111     uiwait(handles.browse_data);
    112 end
     82
     83%% initialize the GUI
     84if ~(exist('DataSeries','var') && exist(DataSeries,'dir'))
     85    DataSeries=pwd;% current dir is the starting data series by default
     86end
     87[Experiment,DataSeries,Ext]=fileparts(DataSeries);
     88DataSeries=[DataSeries Ext];
     89[Campaign,Experiment,Ext]=fileparts(Experiment);
     90Experiment=[Experiment Ext];
     91[tild,CampaignName]=fileparts(Campaign);
     92RootXml=fullfile(Campaign,[CampaignName '.xml']);
     93s=[];
     94if exist(RootXml,'file')
     95    [s,Heading]=xml2struct(RootXml);%read the xml file
     96    if isfield(s,'SourceDir')
     97        set(handles.SourceDir,'String',s.SourceDir);%display the source dir if a mirror has been opened
     98        set(handles.MirrorDir,'Visible','on');%  mirror dir display
     99        set(handles.MirrorDir,'String',Campaign);%display the opened mirror dir
     100        set(handles.CreateMirror,'String','update_mirror')
     101    end
     102end
     103if isempty(s) %a source dir has been opened
     104    set(handles.SourceDir,'String',Campaign);
     105    set(handles.MirrorDir,'Visible','off');% no mirror dir display
     106    set(handles.CreateMirror,'String','create_mirror')
     107end
     108errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries);
     109if ~isempty(errormsg)
     110    msgbox_uvmat('ERROR',errormsg)
     111    return
     112end
     113set(handles.OK,'Visible','on')
     114set(handles.Cancel,'Visible','on')
     115
     116set(handles.browse_data,'WindowStyle','modal')% Make the GUI modal
     117set(hObject,'Visible','on')
     118drawnow
     119% UIWAIT makes GUI wait for user response (see UIRESUME)
     120uiwait(handles.browse_data);
     121
    113122
    114123
     
    190199set(handles.SourceDir,'BackgroundColor',[1 1 1])
    191200
    192 
    193 %------------------------------------------------------------------------
    194 function errormsg=scan_campaign(handles,Campaign)
    195 %------------------------------------------------------------------------
    196 %set(handles.SourceDir,'BackgroundColor',[1 1 0])
    197 %drawnow
    198 %SourceDir=get(handles.SourceDir,'String');
    199 %MirrorDir=get(handles.MirrorDir,'String');
    200 % ExpName={''};
     201%------------------------------------------------------------------------
     202% List the experiments in a campaign, filling the menu ListExperiments
     203%------------------------------------------------------------------------
     204function errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries)
     205%------------------------------------------------------------------------
    201206errormsg='';
    202207if exist(Campaign,'dir')
     
    213218    check_keep=cellfun('isempty', cell_remove);
    214219    ListFiles=sort((ListFiles(check_keep))');
     220    index=find(strcmp(['+/' Experiment],ListFiles));
     221    if isempty(index), index=0; end
    215222    set(handles.ListExperiments,'String',[{'*'};ListFiles])
    216     set(handles.ListExperiments,'Value',1)
     223    set(handles.ListExperiments,'Value',index+1)% initialise the menu selection with the folder defined by the input
    217224    ListExperiments_Callback([],[], handles)
     225    ListDevices=get(handles.ListDevices,'String');
     226    index=find(strcmp(['+/' DataSeries],ListDevices));
     227    if isempty(index)
     228        index=find(strcmp(['~/' DataSeries],ListDevices));
     229    end
     230    if ~isempty(index)
     231          set(handles.ListDevices,'Value',index)
     232    end
    218233else
    219234    msgbox_uvmat('ERROR',['The input ' Campaign ' is not a directory'])
    220235end
    221 %set(handles.SourceDir,'BackgroundColor',[1 1 1])
    222 
    223236
    224237%------------------------------------------------------------------------
     
    668681
    669682
    670 % --- Executes during object deletion, before destroying properties.
    671 function browse_data_DeleteFcn(hObject, eventdata, handles)
     683% --- Executes on button press in Browse.
     684function Browse_Callback(hObject, eventdata, handles)
     685ListDevices=get(handles.ListDevices,'String');
     686Device=ListDevices{get(handles.ListDevices,'Value')};
     687DataSeries=uigetfile_uvmat('open a data folder',Device,'uigetdir');
     688uiresume(handles.browse_data);
     689browse_data(DataSeries)
  • trunk/src/check_files.m

    r828 r856  
    4545    'civ_3D';... % function associated with the interface 'civ_3D.fig' for PIV in volume (TODO: combine with civ.m)
    4646    'civ_3D.fig';...
    47     'civ_matlab';...% civ programs, Matlab version (called by civ.m, option Civprogram/Matlab in the upper menu bar)
    4847    'compile';...% compile a Matlab function, create a binary in a subdirectory /bin
    4948    'copyfields';...% copy fields between two matlab structures
  • trunk/src/geometry_calib.m

    r851 r856  
    239239    InputDir=fileparts(fileparts(CalibData.XmlInputFile));
    240240end
    241 SubProject=uigetfile_uvmat('open folder of subproject to calibrate',InputDir,'uigetdir');
    242 % answer=msgbox_uvmat('INPUT_TXT','Campaign to calibrate?',InputDir);
    243 % if strcmp(answer,'Cancel')
    244 %     return
    245 % end
    246 OutPut=browse_data(SubProject);
     241DataSeries=uigetfile_uvmat('open a folder of images to calibrate',InputDir,'uigetdir');
     242%SubProject=uigetfile_uvmat('open folder of subproject to calibrate',InputDir,'uigetdir');
     243OutPut=browse_data(DataSeries);
    247244nbcalib=0;
    248245for ilist=1:numel(OutPut.Experiment)
  • trunk/src/mouse_motion.m

    r855 r856  
    6464end
    6565test_piv=0;
    66 if isfield(FigData,'CivHandle')
     66if isfield(FigData,'CivHandle')% look for handle of the civ_input GUI
    6767    if ~ishandle(FigData.CivHandle)
    6868        delete(hObject)
     
    7070        return
    7171    end
    72     hhciv=guidata(FigData.CivHandle);
     72    hhciv=guidata(FigData.CivHandle);% list of handles in the GUI civ_input
    7373    test_piv=1;
    7474end
     
    236236            % case of PIV correlation display
    237237            if test_piv
    238                 par=read_GUI(hhciv.Civ1);
    239                 [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2)));
     238               [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2)));
     239               if (isfield(hhciv,'TestCiv2')&& get(hhciv.TestCiv2,'Value'))% if TestCiv2 is activated
     240                   CivOption='Civ2';
     241                   Param.CheckCiv1=0;
     242                   par_civ=read_GUI(hhciv.Civ2);%read the Civ2 panel in civ_input
     243                   par_civ.Civ1_SubRange=Field.Civ1_SubRange;
     244                   par_civ.Civ1_NbCentres=Field.Civ1_NbCentres;
     245                   par_civ.Civ1_Coord_tps=Field.Civ1_Coord_tps;
     246                   par_civ.Civ1_U_tps=Field.Civ1_U_tps;
     247                   par_civ.Civ1_V_tps=Field.Civ1_V_tps;
     248                   par_civ.Civ1_Dt=Field.Civ1_Dt;
     249                   shiftx=Field.ShiftX(ind_pt);
     250                   shifty=Field.ShiftY(ind_pt);
     251               else
     252                   CivOption='Civ1';
     253                   Param.CheckCiv2=0;
     254                   par_civ=read_GUI(hhciv.Civ1);%read the Civ1 panel in civ_input
     255                   shiftx=par_civ.SearchBoxShift(1);
     256                   shifty=par_civ.SearchBoxShift(2);
     257               end
    240258                xround=Field.X(ind_pt);
    241259                yround=Field.Y(ind_pt);
    242                 par.Grid=[xround yround];
     260               
    243261                % mark the correlation box with a rectangle
    244                 par.ImageA=Field.A;
    245                 par.ImageB=Field.B;
    246                 par.ImageHeight=size(par.ImageA,1);
    247                 par.ImageWidth=size(par.ImageA,2);
    248                 Param.ActionInput.Civ1=par;
    249                 ibx2=floor((par.CorrBoxSize(1)-1)/2);
    250                 iby2=floor((par.CorrBoxSize(2)-1)/2);
    251                 isx2=floor((par.SearchBoxSize(1)-1)/2);
    252                 isy2=floor((par.SearchBoxSize(2)-1)/2);
    253                 shiftx=par.SearchBoxShift(1);
    254                 shifty=par.SearchBoxShift(2);
     262                ibx2=floor((par_civ.CorrBoxSize(1)-1)/2);
     263                iby2=floor((par_civ.CorrBoxSize(2)-1)/2);
     264                isx2=floor((par_civ.SearchBoxSize(1)-1)/2);
     265                isy2=floor((par_civ.SearchBoxSize(2)-1)/2);
    255266                hhh=findobj(CurrentAxes,'Tag','PIV_box_marker');
    256267                hhhh=findobj(CurrentAxes,'Tag','PIV_search_marker');
     
    268279                    set(hhhh,'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2])
    269280                end
     281               
     282                % perform the PIV calculation as the single point xround yround
     283                Param.CheckFix1=0;
     284                Param.CheckPatch1=0;%desactivate all calculations except Civ2 or Civ1
    270285                Param.Action.RUN=1;
    271286                Param.ActionInput.ListCompareMode='PIV';
     287                par_civ.ImageA=Field.A;
     288                par_civ.ImageB=Field.B;
     289                par_civ.ImageHeight=size(par_civ.ImageA,1);
     290                par_civ.ImageWidth=size(par_civ.ImageA,2);
     291                par_civ.Grid=[xround yround];% PIV calculation with a single point
     292                Param.ActionInput.(CivOption)=par_civ;
     293               
     294                %  .ImageA: first image for correlation (matrix)
     295%  .ImageB: second image for correlation(matrix)
     296%  .CorrBoxSize: 1,2 vector giving the size of the correlation box in x and y
     297%  .SearchBoxSize:  1,2 vector giving the size of the search box in x and y
     298%  .SearchBoxShift: 1,2 vector or 2 column matrix (for civ2) giving the shift of the search box in x and y
     299%  .CorrSmooth: =1 or 2 determines the choice of the sub-pixel determination of the correlation max
     300%  .ImageWidth: nb of pixels of the image in x
     301%  .Dx, Dy: mesh for the PIV calculation
     302%  .Grid: grid giving the PIV calculation points (alternative to .Dx .Dy)
     303%  .Mask: name of a mask file or mask image matrix itself
     304%  .MinIma: thresholds for image luminosity
     305%  .MaxIma
     306%  .CheckDeformation=1 for subpixel interpolation and image deformation (linear transform)
     307%  .DUDX: matrix of deformation obtained from patch at each grid point
     308%  .DUDY
     309%  .DVDX:
     310%  .DVDY
     311               
    272312                [Data,errormsg,result_conv]= civ_series(Param);
    273313                if ~isempty(errormsg)
  • trunk/src/series.m

    r855 r856  
    429429
    430430%------------------------------------------------------------------------
    431 % --- fct activated by the browser under 'Open campaign'
     431% --- fct activated by the browser under 'Open campaign/Browse...'
    432432%------------------------------------------------------------------------
    433433function MenuBrowseCampaign_Callback(hObject, eventdata, handles)
    434434
     435%% look for the previously opened file 'oldfile'
     436InputTable=get(handles.InputTable,'Data');
     437RootPathCell=InputTable(:,1);
     438SubDirCell=InputTable(:,2);
     439oldfile=fullfile(RootPathCell{1},SubDirCell{1});
     440if isempty(oldfile)
     441    % use a file name stored in prefdir
     442    dir_perso=prefdir;
     443    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
     444    if exist(profil_perso,'file')
     445        h=load (profil_perso);
     446        if isfield(h,'RootPath') && ischar(h.RootPath)
     447            oldfile=h.RootPath;
     448        end
     449    end
     450end
     451%% launch the browser
     452fileinput=uigetfile_uvmat('pick an input file in the series',oldfile);
     453hh=dir(fileinput);
     454if numel(hh)>1
     455    msgbox_uvmat('ERROR','invalid input, probably a broken link');
     456else
     457    if ~isempty(fileinput)
     458        display_file_name(handles,fileinput,'one')
     459    end
     460end
     461append='one';
    435462set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0])
    436463drawnow
    437 InputTable=get(handles.InputTable,'Data');
    438 RootPath=InputTable{1,1};
    439 CampaignPath=fileparts(fileparts(RootPath));
    440 DirFull=uigetfile_uvmat('define this path as the Campaign folder:',CampaignPath,'uigetdir');
    441 if ~ischar(DirFull)|| ~exist(DirFull,'dir')
    442     return
    443 end
    444 OutPut=browse_data(DirFull);% open the GUI browse_data to get select a campaign dir, experiment and device
     464browse_campaign(handles,append);
     465
     466%------------------------------------------------------------------------
     467% --- fct activated by the browser under 'Open campaign/Browse...'
     468%------------------------------------------------------------------------
     469function MenuBrowseCampaignAppend_Callback(hObject, eventdata, handles)
     470append='append';
     471browse_campaign(handles,append);
     472
     473%------------------------------------------------------------------------
     474function browse_campaign(handles,append);
     475
     476%% look for the previously opened file 'oldfile'
     477
     478%
     479%
     480% InputTable=get(handles.InputTable,'Data');
     481% RootPath=InputTable{1,1};
     482% CampaignPath=fileparts(fileparts(RootPath));
     483% DirFull=uigetfile_uvmat('define this path as the Campaign folder:',CampaignPath,'uigetdir');
     484% if ~ischar(DirFull)|| ~exist(DirFull,'dir')
     485%     return
     486% end
     487OutPut=browse_data(oldfile);% open the GUI browse_data to get select a campaign dir, experiment and device
    445488if ~isfield(OutPut,'Campaign')
    446489    return
     
    468511MenuCampaign=[{get(handles.MenuCampaign_1,'Label')};{get(handles.MenuCampaign_2,'Label')};...
    469512    {get(handles.MenuCampaign_3,'Label')};{get(handles.MenuCampaign_4,'Label')};{get(handles.MenuCampaign_5,'Label')}];
    470 check_dir=isempty(find(strcmp(DirFull,MenuCampaign)));
     513check_dir=isempty(find(strcmp(DirName,MenuCampaign)));
    471514if check_dir %insert the new campaign in the list if it is not found
    472515    MenuCampaign(end)=[]; %suppress the last item
    473     MenuCampaign=[{DirFull};MenuCampaign];%insert the new campaign
     516    MenuCampaign=[{DirName};MenuCampaign];%insert the new campaign
    474517    for ilist=1:numel(MenuCampaign)
    475518        set(handles.(['MenuCampaign_' num2str(ilist)]),'Label',MenuCampaign{ilist})
     
    479522    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    480523    if exist(profil_perso,'file')
    481         save (profil_perso,'MenuCampaign','RootPath','-append'); %store the file names for future opening of uvmat
     524        save (profil_perso,'MenuCampaign','-append'); %store the file names for future opening of uvmat
    482525    else
    483         save (profil_perso,'MenuCampaign','RootPath','-V6'); %store the file names for future opening of uvmat
     526        save (profil_perso,'MenuCampaign','-V6'); %store the file names for future opening of uvmat
    484527    end
    485528end
     
    19551998end
    19561999
    1957 %% Activate the Action fct
     2000%% Activate the Action fct to adapt the configuration of the GUI series and bring specific parameters in SeriesData
    19582001Param=read_GUI_series(handles);% read the parameters from the GUI series
    19592002ParamOut=h_fun(Param);%run the selected Action function to get the relevant input
  • trunk/src/series/civ_input.m

    r855 r856  
    165165    set(handles.ref_j,'String',num2str(Param.IndexRange.first_j))
    166166end
     167set(handles.ConfigSource,'String','\default')
    167168
    168169%%  set the menus of image pairs and default selection for civ_input   %%%%%%%%%%%%%%%%%%%
     
    340341set(handles.civ_input,'WindowStyle','modal')% Make the GUI modal
    341342drawnow
    342 uiwait(handles.civ_input);
     343uiwait(handles.civ_input);% wait for OK action to end the function
    343344
    344345
     
    368369%------------------------------------------------------------------------
    369370function SetDefaultParam_Callback(hObject, eventdata, handles)
    370    
    371 hseries=findobj(allchild(0),'Name','series');% look for the GUI series
    372 hhseries=guidata(hseries);%handles of elements in the GUI series
    373 SeriesData=get(hseries,'UserData');%read parameters on the GUI series
    374 if isfield (SeriesData,'ActionInput')
    375     SeriesData=rmfield(SeriesData,'ActionInput');% remove recorded civ parameters
    376 end
    377 set(hseries,'UserData',SeriesData)
    378 series('ActionName_Callback',hObject,eventdata,hhseries); %
     371
     372Param.ConfigSource='\default';
     373
     374%% Civ1 parameters
     375Param.Civ1.CorrBoxSize=[25 25];
     376Param.Civ1.SearchBoxSize=[55 55];
     377Param.Civ1.SearchBoxShift=[0 0];
     378Param.Civ1.CorrSmooth=1;
     379Param.Civ1.Dx=20;
     380Param.Civ1.Dy=20;
     381Param.Civ1.CheckGrid=0;
     382Param.Civ1.CheckMask=0;
     383Param.Civ1.CheckThreshold=0;
     384Param.Civ1.TestCiv1=0;
     385
     386%% Fix1 parameters
     387Param.Fix1.CheckFmin2=1;
     388Param.Fix1.CheckF3=1;
     389Param.Fix1.MinCorr=0.2000;
     390
     391%% Patch1 parameters
     392Param.Patch1.FieldSmooth=10;
     393Param.Patch1.MaxDiff=1.5000;
     394Param.Patch1.SubDomainSize=1000;
     395Param.Patch1.TestPatch1=0;
     396
     397%% Civ2 parameters
     398Param.Civ2.CorrBoxSize=[21 21];
     399Param.Civ2.SearchBoxSize=[31 31];
     400Param.Civ2.CorrSmooth=1;
     401Param.Civ2.Dx=10;
     402Param.Civ2.Dy=10;
     403Param.Civ2.CheckGrid=0;
     404Param.Civ2.CheckMask=0;
     405Param.Civ2.CheckThreshold=0;
     406Param.Civ2.TestCiv2=0;
     407
     408%% Fix2 parameters
     409Param.Fix2.CheckFmin2=1;
     410Param.Fix2.CheckF4=1;
     411Param.Fix2.CheckF3=1;
     412Param.Fix2.MinCorr=0.2000;
     413
     414%% Patch2 parameters
     415Param.Patch2.FieldSmooth=2;
     416Param.Patch2.MaxDiff=1.5000;
     417Param.Patch2.SubDomainSize=1000;
     418Param.Patch2.TestPatch2=0;
     419
     420fill_GUI(Param,handles.civ_input)% fill the elements of the GUI series with the input parameters
     421
     422%update_CivOptions(handles,0)
     423%set(handles.ConfigSource,'String','\default')
     424
     425% %Param=read_GUI(handles.civ_input)
     426% hseries=findobj(allchild(0),'Name','series');% look for the GUI series
     427% hhseries=guidata(hseries);%handles of elements in the GUI series
     428% SeriesData=get(hseries,'UserData');%read parameters on the GUI series
     429% if isfield (SeriesData,'ActionInput')
     430%     SeriesData=rmfield(SeriesData,'ActionInput');% remove recorded civ parameters
     431% end
     432% set(hseries,'UserData',SeriesData)
     433% %% exit the GUI and close it
     434% %handles.output.ActionInput=rmfield(ActionInput;
     435% guidata(hObject, handles);% Update handles structure
     436% uiresume(handles.civ_input);
     437% set(hhseries.ActionName,'BusyAction','cancel')
     438% series('ActionName_Callback',hObject,eventdata,hhseries); %
     439
    379440
    380441% -----------------------------------------------------------------------
     
    771832if isempty(errormsg)
    772833    set(handles.ref_i,'BackgroundColor',[1 1 1])
     834    set(handles.ref_j,'BackgroundColor',[1 1 1])
    773835else
    774836    msgbox_uvmat('ERROR',errormsg)
     
    827889
    828890%% determine nom_type_nc, nomenclature type of the .nc files:
    829 [nom_type_nc]=nomtype2pair(nom_type_ima,mode);
     891%[nom_type_nc]=nomtype2pair(nom_type_ima,mode);
    830892
    831893%% reads .nc subdirectoy and image numbers from the interface
     
    920982
    921983%% determine the default selection in the pair menu for Civ1
    922 ichoice=find(select,1);% index of selected pair
     984ichoice=find(select,1);% index of first selected pair
    923985if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
    924986initial=get(handles.ListPairCiv1,'Value');%initial choice of pair
     
    10811143
    10821144%------------------------------------------------------------------------
    1083 % --- Executes on button press in CheckMask.
     1145% --- Executes on selection in menu CorrSmooth.
    10841146function num_CorrSmooth_Callback(hObject, eventdata, handles)
    10851147set(handles.configSource,'String','NEW')
    1086 set(handles.configSource,'BackgroundColor',[1 0 1])
     1148set(handles.OK,'BackgroundColor',[1 0 1])
    10871149%------------------------------------------------------------------------
    10881150
     
    14231485set(hObject,'BackgroundColor',[1 0 1])
    14241486set(handles.configSource,'String','NEW')
    1425 set(handles.configSource,'BackgroundColor',[1 0 1])
     1487set(handles.OK,'BackgroundColor',[1 0 1])
    14261488%------------------------------------------------------------------------
    14271489% --- Executes on button press in CheckMask: common to all panels (civ1, Civ2..)
     
    16851747end
    16861748set(handles.configSource,'String','NEW')
    1687 set(handles.configSource,'BackgroundColor',[1 0 1])
     1749set(handles.OK,'BackgroundColor',[1 0 1])
    16881750%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    16891751%%%%%%%%%%%%%%   TEST functions
     
    18201882if get(handles.TestCiv2,'Value')
    18211883    set(handles.TestCiv2,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch
    1822     % TO UPDATE TO UPDATE TO UPDATE TO UPDATE
    1823     [Data,Param.Civ2]=get_param_civ2(handles);
    1824     Grid=civ_matlab(Param);% get the grid of x, y positions set for PIV
    1825     hview_field=view_field(Data); %view the image in the GUI view_field
     1884      hseries=findobj(allchild(0),'Tag','series');
     1885     Param=read_GUI(hseries);
     1886     Param.Action.RUN=1;
     1887     Param.ActionInput=read_GUI(handles.civ_input);
     1888     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
     1889     Param.ActionInput.Civ2.SmoothParam=0;% launch Civ2 with no data point (to get the image names for A and B)
     1890     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
     1891     
     1892     %% create image data ImageData for display
     1893     ImageData.ListVarName={'ny','nx','A'};
     1894     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
     1895     ImageData.A=imread(Data.Civ2_ImageA); % read the first image
     1896     if ndims(ImageData.A)==3 %case of color image
     1897         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
     1898     end
     1899     ImageData.ny=[size(ImageData.A,1) 1];
     1900     ImageData.nx=[1 size(ImageData.A,2)];
     1901     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
     1902
     1903     %% create the figure view_field for image visualization
     1904    hview_field=view_field(ImageData); %view the image in the GUI view_field
    18261905    set(0,'CurrentFigure',hview_field)
     1906    RectCentre=squeeze(mean(Data.Civ1_SubRange,2));
     1907    for isub=1:size(Data.Civ1_SubRange,3);
     1908        pos_x=Data.Civ1_SubRange(1,1,isub);
     1909        pos_y=Data.Civ1_SubRange(2,1,isub);
     1910        width=Data.Civ1_SubRange(1,2,isub)-Data.Civ1_SubRange(1,1,isub);
     1911        height=Data.Civ1_SubRange(2,2,isub)-Data.Civ1_SubRange(2,1,isub);
     1912        rectangle('Position',[pos_x pos_y width height],'EdgeColor',[0 0 1])
     1913    end
    18271914    hhview_field=guihandles(hview_field);
    18281915    set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
    18291916    ViewData=get(hview_field,'UserData');
    18301917    ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
    1831     ViewData.PlotAxes.B=imread(Param.Civ1.ImageName_B);%store the second image in the UserData of the GUI view_field
    1832     ViewData.PlotAxes.X=Grid.Civ1_X; %keep the set of points in memeory
    1833     ViewData.PlotAxes.Y=Grid.Civ1_Y;
    1834     set(hview_field,'UserData',ViewData)
    1835     corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
     1918    ViewData.PlotAxes.B=imread(Data.Civ2_ImageB);%store the second image in the UserData of the GUI view_field
     1919    ViewData.PlotAxes.X=Data.Civ2_X';
     1920    ViewData.PlotAxes.Y=Data.Civ2_Y';
     1921    ViewData.PlotAxes.ShiftX=Data.Civ2_U';
     1922    ViewData.PlotAxes.ShiftY=Data.Civ2_V';
     1923    ViewData.PlotAxes.Civ1_SubRange=Data.Civ1_SubRange;
     1924    ViewData.PlotAxes.Civ1_NbCentres=Data.Civ1_NbCentres;
     1925    ViewData.PlotAxes.Civ1_Coord_tps=Data.Civ1_Coord_tps;
     1926    ViewData.PlotAxes.Civ1_U_tps=Data.Civ1_U_tps;
     1927    ViewData.PlotAxes.Civ1_V_tps=Data.Civ1_V_tps;
     1928    ViewData.PlotAxes.Civ1_Dt=Data.Civ1_Dt;
     1929    set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
     1930   
     1931    %% look for a current figure for image correlation display
     1932    corrfig=findobj(allchild(0),'tag','corrfig');
    18361933    if isempty(corrfig)
    18371934        corrfig=figure;
     
    18391936        set(corrfig,'name','image correlation')
    18401937        set(corrfig,'DeleteFcn',{@closeview_field})%
    1841         % end
    18421938        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
    18431939    else
     
    18511947            delete(hview_field)
    18521948        end
    1853     end
     1949    end   
    18541950else
    18551951    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
     
    20842180
    20852181%------------------------------------------------------------------------
    2086 % --- Executes on button press in InportParam.
    2087 %------------------------------------------------------------------------
    2088 function InportParam_Callback(hObject, eventdata, handles)
     2182% --- Executes on button press in ImportParam.
     2183%------------------------------------------------------------------------
     2184function ImportParam_Callback(hObject, eventdata, handles)
    20892185hseries=findobj(allchild(0),'Tag','series');
    20902186hhseries=guidata(hseries);
     
    21162212        if isfield(Param.ActionInput,'Program')&& strcmp(Param.ActionInput.Program,'civ_series')
    21172213            fill_GUI(Param.ActionInput,handles.civ_input)% fill the elements of the GUI series with the input parameters
     2214            set(handles.ConfigSource,'String',filexml)
    21182215            check_input=1;
    2119             update_CivOptions(handles,0)
    2120                
     2216            update_CivOptions(handles,0)             
    21212217        end
    21222218    end
     
    21382234if isempty(find(strcmp(get(gco,'Tag'),ListExclude),1))% if the selected uicontrol is not in the Exclude list
    21392235    set(handles.ConfigSource,'String','NEW')% indicate that the configuration is new
    2140     set(handles.ConfigSource,'BackgroundColor',[1 0 1])%
    2141 end
     2236    set(handles.OK,'BackgroundColor',[1 0 1])%
     2237    drawnow
     2238end
     2239
     2240
     2241% --- Executes on button press in TestPatch2.
     2242function TestPatch2_Callback(hObject, eventdata, handles)
  • trunk/src/series/civ_series.m

    r855 r856  
    5858    Data.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
    5959    Data.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    60     if isfield(Data,'ActionInput') && strcmp(Data.ActionInput.PairIndices.ListPairMode,'pair j1-j2')
     60    if isfield(Data,'ActionInput') && isfield(Data.ActionInput,'PairIndices')&& strcmp(Data.ActionInput.PairIndices.ListPairMode,'pair j1-j2')
    6161        Data.Desable_j_index='on';% hide the j index in series (set by the pair choice in civ_input)
    6262    end
     
    174174                j1_series_Civ2=j1_series_Civ1;
    175175                j2_series_Civ2=j2_series_Civ1;
    176                 NomTypeNc=NomType;
     176                NomTypeNc=Param.InputTable{1,4};
    177177            case 'PIV volume'
    178178                % TODO, TODO
     
    329329
    330330%%%%% MAIN LOOP %%%%%%
     331maskname='';% initiate the mask name
    331332for ifield=1:NbField
    332333    if ~isempty(RUNHandle)% update the waitbar in interactive mode with GUI series  (checkrun=1)
     
    360361    if isfield (Param.ActionInput,'Civ1')
    361362        par_civ1=Param.ActionInput.Civ1;
    362         if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1)
     363        if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
    363364            try
    364365                ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield));
     
    422423        Data.VarAttribute{4}.Role='vector_y';
    423424        Data.VarAttribute{5}.Role='warnflag';
    424        
     425        if par_civ1.CheckMask&&~isempty(par_civ1.Mask)
     426            if strcmp(maskname,par_civ1.Mask)% mask exist, not already read in civ1
     427                par_civ1.Mask=mask; %use mask already opened
     428            else
     429                par_civ1.Mask=imread(par_civ1.Mask);%update the mask, an store it for future use
     430                mask=par_civ1.Mask;
     431                maskname=par_civ1.Mask;
     432            end
     433        end
    425434        if strcmp(Param.ActionInput.ListCompareMode, 'PIV volume')
    426435            Data.ListVarName=[Data.ListVarName 'Civ1_Z'];
     
    429438            for ivol=1:NbSlice
    430439                % caluclate velocity data (y and v in indices, reverse to y component)
    431                 [xtable ytable utable vtable ctable F result_conv errormsg] = civ (par_civ1);
     440                [xtable, ytable, utable, vtable, ctable, F, result_conv, errormsg] = civ (par_civ1);
    432441                if ~isempty(errormsg)
    433442                     disp_uvmat('ERROR',errormsg,checkrun)
     
    444453        else %usual PIV
    445454            % caluclate velocity data (y and v in indices, reverse to y component)
    446             [xtable ytable utable vtable ctable F result_conv errormsg] = civ (par_civ1);
     455            [xtable, ytable, utable, vtable, ctable, F, result_conv, errormsg] = civ (par_civ1);
    447456            if ~isempty(errormsg)
    448457                disp_uvmat('ERROR',errormsg,checkrun)
     
    473482                [Data,tild,tild,errormsg]=nc2struct(CivFile);%read civ1 and fix1 data in the existing netcdf file
    474483            end
    475         else
     484        elseif isfield(Param,'Civ1_X')
    476485            Data.ListGlobalAttribute={};
    477486            Data.ListVarName={};
     
    572581    if isfield (Param.ActionInput,'Civ2')
    573582        par_civ2=Param.ActionInput.Civ2;
    574         par_civ2.ImageA=[];
    575         par_civ2.ImageB=[];
    576         i1=i1_series_Civ2(ifield);
    577         i2=i1;
    578         if ~isempty(i2_series_Civ2)
    579             i2=i2_series_Civ2(ifield);
    580         end
    581         j1=1;
    582         if ~isempty(j1_series_Civ2)
    583             j1=j1_series_Civ2(ifield);
    584         end
    585         j2=j1;
    586         if ~isempty(j2_series_Civ2)
    587             j2=j2_series_Civ2(ifield);
    588         end
    589         ImageName_A_Civ2=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1,[],j1);
    590 
    591         if strcmp(ImageName_A_Civ2,ImageName_A) && isequal(FrameIndex_A_Civ1(ifield),FrameIndex_A_Civ2(ifield))
    592             par_civ2.ImageA=par_civ1.ImageA;
    593         else
    594             [par_civ2.ImageA,VideoObject_A] = read_image(ImageName_A_Civ2,FileType_A,VideoObject_A,FrameIndex_A_Civ2(ifield));
    595         end
    596         ImageName_B_Civ2=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2,[],j2);
    597         if strcmp(ImageName_B_Civ2,ImageName_B) && isequal(FrameIndex_B_Civ1(ifield),FrameIndex_B_Civ2)
    598             par_civ2.ImageB=par_civ1.ImageB;
    599         else
    600             [par_civ2.ImageB,VideoObject_B] = read_image(ImageName_B_Civ2,FileType_B,VideoObject_B,FrameIndex_B_Civ2(ifield));
    601         end     
    602        
    603         ncfile=fullfile_uvmat(RootPath_A,OutputDir,RootFile_A,'.nc',NomTypeNc,i1,i2,j1,j2);
    604         par_civ2.ImageWidth=FileInfo_A.Width;
    605         par_civ2.ImageHeight=FileInfo_A.Height;
    606        
    607         if isfield(par_civ2,'Grid')% grid points set as input file
    608             if ischar(par_civ2.Grid)%read the grid file if the input is a file name
    609                 par_civ2.Grid=dlmread(par_civ2.Grid);
    610                 par_civ2.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
    611             end
    612         else% automatic grid
    613             minix=floor(par_civ2.Dx/2)-0.5;
    614             maxix=minix+par_civ2.Dx*floor((par_civ2.ImageWidth-1)/par_civ2.Dx);
    615             miniy=floor(par_civ2.Dy/2)-0.5;
    616             maxiy=minix+par_civ2.Dy*floor((par_civ2.ImageHeight-1)/par_civ2.Dy);
    617             [GridX,GridY]=meshgrid(minix:par_civ2.Dx:maxix,miniy:par_civ2.Dy:maxiy);
    618             par_civ2.Grid(:,1)=reshape(GridX,[],1);
    619             par_civ2.Grid(:,2)=reshape(GridY,[],1);
    620         end
    621         Shiftx=zeros(size(par_civ2.Grid,1),1);% shift expected from civ1 data
    622         Shifty=zeros(size(par_civ2.Grid,1),1);
    623         nbval=zeros(size(par_civ2.Grid,1),1);
     583        if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
     584            par_civ2.ImageA=[];
     585            par_civ2.ImageB=[];
     586            i1=i1_series_Civ2(ifield);
     587            i2=i1;
     588            if ~isempty(i2_series_Civ2)
     589                i2=i2_series_Civ2(ifield);
     590            end
     591            j1=1;
     592            if ~isempty(j1_series_Civ2)
     593                j1=j1_series_Civ2(ifield);
     594            end
     595            j2=j1;
     596            if ~isempty(j2_series_Civ2)
     597                j2=j2_series_Civ2(ifield);
     598            end
     599            ImageName_A_Civ2=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1,[],j1);
     600           
     601            if strcmp(ImageName_A_Civ2,ImageName_A) && isequal(FrameIndex_A_Civ1(ifield),FrameIndex_A_Civ2(ifield))
     602                par_civ2.ImageA=par_civ1.ImageA;
     603            else
     604                [par_civ2.ImageA,VideoObject_A] = read_image(ImageName_A_Civ2,FileType_A,VideoObject_A,FrameIndex_A_Civ2(ifield));
     605            end
     606            ImageName_B_Civ2=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2,[],j2);
     607            if strcmp(ImageName_B_Civ2,ImageName_B) && isequal(FrameIndex_B_Civ1(ifield),FrameIndex_B_Civ2)
     608                par_civ2.ImageB=par_civ1.ImageB;
     609            else
     610                [par_civ2.ImageB,VideoObject_B] = read_image(ImageName_B_Civ2,FileType_B,VideoObject_B,FrameIndex_B_Civ2(ifield));
     611            end
     612            if strcmp(Param.ActionInput.ListCompareMode,'PIV')
     613                ncfile=fullfile_uvmat(RootPath_A,OutputDir,RootFile_A,'.nc',NomTypeNc,i1,i2,j1,j2);
     614            else % displacement
     615                ncfile=fullfile_uvmat(RootPath_A,OutputDir,RootFile_A,'.nc',NomTypeNc,i2,[],j2);
     616            end
     617            par_civ2.ImageWidth=FileInfo_A.Width;
     618            par_civ2.ImageHeight=FileInfo_A.Height;
     619            if isfield(par_civ2,'Grid')% grid points set as input file
     620                if ischar(par_civ2.Grid)%read the grid file if the input is a file name
     621                    par_civ2.Grid=dlmread(par_civ2.Grid);
     622                    par_civ2.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
     623                end
     624            else% automatic grid
     625                minix=floor(par_civ2.Dx/2)-0.5;
     626                maxix=minix+par_civ2.Dx*floor((par_civ2.ImageWidth-1)/par_civ2.Dx);
     627                miniy=floor(par_civ2.Dy/2)-0.5;
     628                maxiy=minix+par_civ2.Dy*floor((par_civ2.ImageHeight-1)/par_civ2.Dy);
     629                [GridX,GridY]=meshgrid(minix:par_civ2.Dx:maxix,miniy:par_civ2.Dy:maxiy);
     630                par_civ2.Grid(:,1)=reshape(GridX,[],1);
     631                par_civ2.Grid(:,2)=reshape(GridY,[],1);
     632            end
     633        end
    624634        if par_civ2.CheckDeformation
    625635            DUDX=zeros(size(par_civ2.Grid,1),1);
     
    629639        end
    630640       
    631          % get the guess from patch1 or patch2 (case 'CheckCiv3')
    632         if isfield (par_civ2,'CheckCiv3') && par_civ2.CheckCiv3 %get the guess from  patch2
    633            SubRange= Data.Civ2_SubRange;
    634            NbCentres=Data.Civ2_NbCentres;
    635            Coord_tps=Data.Civ2_Coord_tps;
    636            U_tps=Data.Civ2_U_tps;
    637            V_tps=Data.Civ2_V_tps;
    638            CivStage=Data.CivStage;
    639            Civ1_Dt=Data.Civ2_Dt;
    640            Data=[];%reinitialise the result structure Data
    641            Data.ListGlobalAttribute={'Conventions','Program','CivStage'};
    642            Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes
    643            Data.Program='civ_series';
    644            Data.CivStage=CivStage;
    645            Data.ListVarName={};
    646            Data.VarDimName={};
    647         else % get the guess from patch1
    648            SubRange= Data.Civ1_SubRange;
    649            NbCentres=Data.Civ1_NbCentres;
    650            Coord_tps=Data.Civ1_Coord_tps;
    651            U_tps=Data.Civ1_U_tps;
    652            V_tps=Data.Civ1_V_tps;
    653            Civ1_Dt=Data.Civ1_Dt;
    654         end
    655         NbSubDomain=size(SubRange,3);       
     641        % get the guess from patch1 or patch2 (case 'CheckCiv3')
     642        if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
     643            if isfield (par_civ2,'CheckCiv3') && par_civ2.CheckCiv3 %get the guess from  patch2
     644                SubRange= Data.Civ2_SubRange;
     645                NbCentres=Data.Civ2_NbCentres;
     646                Coord_tps=Data.Civ2_Coord_tps;
     647                U_tps=Data.Civ2_U_tps;
     648                V_tps=Data.Civ2_V_tps;
     649                CivStage=Data.CivStage;
     650                Civ1_Dt=Data.Civ2_Dt;
     651                Data=[];%reinitialise the result structure Data
     652                Data.ListGlobalAttribute={'Conventions','Program','CivStage'};
     653                Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes
     654                Data.Program='civ_series';
     655                Data.CivStage=CivStage;
     656                Data.ListVarName={};
     657                Data.VarDimName={};
     658            else % get the guess from patch1
     659                SubRange= Data.Civ1_SubRange;
     660                NbCentres=Data.Civ1_NbCentres;
     661                Coord_tps=Data.Civ1_Coord_tps;
     662                U_tps=Data.Civ1_U_tps;
     663                V_tps=Data.Civ1_V_tps;
     664                Civ1_Dt=Data.Civ1_Dt;
     665            end
     666        else
     667            SubRange= par_civ2.Civ1_SubRange;
     668            NbCentres=par_civ2.Civ1_NbCentres;
     669            Coord_tps=par_civ2.Civ1_Coord_tps;
     670            U_tps=par_civ2.Civ1_U_tps;
     671            V_tps=par_civ2.Civ1_V_tps;
     672            Civ1_Dt=par_civ2.Civ1_Dt;
     673                         Data.ListVarName={};
     674                Data.VarDimName={};
     675        end
     676        Shiftx=zeros(size(par_civ2.Grid,1),1);% shift expected from civ1 data
     677        Shifty=zeros(size(par_civ2.Grid,1),1);
     678        nbval=zeros(size(par_civ2.Grid,1),1);% nbre of interpolated values at each grid point (from the different patch subdomains)
     679        NbSubDomain=size(SubRange,3);
    656680        for isub=1:NbSubDomain% for each sub-domain of Patch1
    657681            nbvec_sub=NbCentres(isub);% nbre of Civ vectors in the subdomain
     
    660684            epoints = par_civ2.Grid(ind_sel,:);% coordinates of interpolation sites
    661685            ctrs=Coord_tps(1:nbvec_sub,:,isub) ;%(=initial points) ctrs
    662             nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for eacn interpolation point (in case of subdomain overlap)
    663             EM = tps_eval(epoints,ctrs);               
     686            nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for each interpolation point (in case of subdomain overlap)
     687            EM = tps_eval(epoints,ctrs);
    664688            Shiftx(ind_sel)=Shiftx(ind_sel)+EM*U_tps(1:nbvec_sub+3,isub);
    665689            Shifty(ind_sel)=Shifty(ind_sel)+EM*V_tps(1:nbvec_sub+3,isub);
     
    672696            end
    673697        end
    674         mask='';
    675         if par_civ2.CheckMask&&~isempty(par_civ2.Mask)&& ~strcmp(maskname,par_civ2.Mask)% mask exist, not already read in civ1
    676             mask=imread(par_civ2.Mask);
     698        if par_civ2.CheckMask&&~isempty(par_civ2.Mask)
     699            if strcmp(maskname,par_civ2.Mask)% mask exist, not already read in civ1
     700                par_civ2.Mask=mask; %use mask already opened
     701            else
     702                par_civ2.Mask=imread(par_civ2.Mask);%update the mask, and store it for future use
     703                mask=par_civ2.Mask;
     704                maskname=par_civ2.Mask;
     705            end
    677706        end
    678707        ibx2=ceil(par_civ2.CorrBoxSize(1)/2);
     
    680709        par_civ2.SearchBoxSize(1)=2*ibx2+9;% search ara +-4 pixels around the guess
    681710        par_civ2.SearchBoxSize(2)=2*iby2+9;
    682         Civ2_Dt=time(i2+1,j2+1)-time(i1+1,j1+1);
     711        if strcmp(Param.ActionInput.ListCompareMode,'displacement')
     712            Civ1_Dt=1;
     713            Civ2_Dt=1;
     714        elseif exist('time','var')
     715            Civ2_Dt=time(i2+1,j2+1)-time(i1+1,j1+1);
     716        else
     717            Civ2_Dt=1;%TO CHECK, TEST
     718        end
    683719        par_civ2.SearchBoxShift=(Civ2_Dt/Civ1_Dt)*[Shiftx(nbval>=1)./nbval(nbval>=1) Shifty(nbval>=1)./nbval(nbval>=1)];
    684720        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];% grid taken at the extrapolated origin of the displacement vectors
     
    690726        end
    691727        % calculate velocity data (y and v in indices, reverse to y component)
    692         [xtable ytable utable vtable ctable F] = civ (par_civ2);
     728        [xtable, ytable, utable, vtable, ctable, F,result_conv,errormsg] = civ (par_civ2);
     729       
    693730        list_param=(fieldnames(Param.ActionInput.Civ2))';
    694731        Civ2_param=regexprep(list_param,'^.+','Civ2_$0');% insert 'Civ2_' before  each string in list_param
    695732        Civ2_param=[{'Civ2_ImageA','Civ2_ImageB','Civ2_Time','Civ2_Dt'} Civ2_param]; %insert the names of the two input images
    696         %indicate the values of all the global attributes in the output data
     733        %indicate the values of all the global attributes in the output data
     734        if exist('ImageName_A','var')
    697735        Data.Civ2_ImageA=ImageName_A;
    698736        Data.Civ2_ImageB=ImageName_B;
    699737        Data.Civ2_Time=(time(i2+1,j2+1)+time(i1+1,j1+1))/2;
    700738        Data.Civ2_Dt=Civ2_Dt;
    701 %         Data.Civ2_Time=1;
    702 %         Data.Civ2_Dt=1;
     739        end
     740        %         Data.Civ2_Time=1;
     741        %         Data.Civ2_Dt=1;
    703742        for ilist=1:length(list_param)
    704743            Data.(Civ2_param{4+ilist})=Param.ActionInput.Civ2.(list_param{ilist});
     
    725764    %% Fix2
    726765    if isfield (Param.ActionInput,'Fix2')
    727                 list_param=fieldnames(Param.ActionInput.Fix2)';
     766        list_param=fieldnames(Param.ActionInput.Fix2)';
    728767        Fix2_param=regexprep(list_param,'^.+','Fix2_$0');% insert 'Fix1_' before  each string in ListFixParam
    729768        %indicate the values of all the global attributes in the output data
     
    824863%INPUT:
    825864% par_civ: structure of input parameters, with fields:
    826 %  .CorrBoxSize
    827 %  .SearchBoxSize
    828 %  .SearchBoxShift
    829 %  .ImageHeight
    830 %  .ImageWidth
    831 %  .Dx, Dy
    832 %  .Grid
    833 %  .Mask
    834 %  .MinIma
     865%  .ImageA: first image for correlation (matrix)
     866%  .ImageB: second image for correlation(matrix)
     867%  .CorrBoxSize: 1,2 vector giving the size of the correlation box in x and y
     868%  .SearchBoxSize:  1,2 vector giving the size of the search box in x and y
     869%  .SearchBoxShift: 1,2 vector or 2 column matrix (for civ2) giving the shift of the search box in x and y
     870%  .CorrSmooth: =1 or 2 determines the choice of the sub-pixel determination of the correlation max
     871%  .ImageWidth: nb of pixels of the image in x
     872%  .Dx, Dy: mesh for the PIV calculation
     873%  .Grid: grid giving the PIV calculation points (alternative to .Dx .Dy)
     874%  .Mask: name of a mask file or mask image matrix itself
     875%  .MinIma: thresholds for image luminosity
    835876%  .MaxIma
    836 %  .image1:first image (matrix)
    837 % image2: second image (matrix)
    838 % ibx2,iby2: half size of the correlation box along x and y, in px (size=(2*iby2+1,2*ibx2+1)
    839 % isx2,isy2: half size of the search box along x and y, in px (size=(2*isy2+1,2*isx2+1)
    840 % shiftx, shifty: shift of the search box (in pixel index, yshift reversed)
    841 % step: mesh of the measurement points (in px)
    842 % subpixfinder=1 or 2 controls the curve fitting of the image correlation
    843 % mask: =[] for no mask
    844 % roi: 4 element vector defining a region of interest: x position, y position, width, height, (in image indices), for the whole image, roi=[];
     877%  .CheckDeformation=1 for subpixel interpolation and image deformation (linear transform)
     878%  .DUDX: matrix of deformation obtained from patch at each grid point
     879%  .DUDY
     880%  .DVDX:
     881%  .DVDY
     882
    845883function [xtable,ytable,utable,vtable,ctable,F,result_conv,errormsg] = civ (par_civ)
    846884
    847885%% prepare measurement grid
    848886if isfield(par_civ,'Grid')% grid points set as input
    849     if ischar(par_civ.Grid)%read the drid file if the input is a file name
     887    if ischar(par_civ.Grid)%read the grid file if the input is a file name
    850888        par_civ.Grid=dlmread(par_civ.Grid);
    851889        par_civ.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
    852890    end
     891    % else par_civ.Grid is already an array
    853892else% automatic grid
    854893    minix=floor(par_civ.Dx/2)-0.5;
     
    889928        return    % get the grid only, no civ calculation
    890929    elseif ischar(par_civ.Mask)
    891         par_civ.Mask=imread(par_civ.Mask);
     930        par_civ.Mask=imread(par_civ.Mask);% read the mask if not allready done
    892931    end
    893932end
     
    948987sum_square=1;% default
    949988mesh=1;% default
    950 CheckDecimal=isfield(par_civ,'CheckDecimal')&& par_civ.CheckDecimal==1;
    951 if CheckDecimal
    952     mesh=0.2;%mesh in pixels for subpixel image interpolation
    953     CheckDeformation=isfield(par_civ,'CheckDeformation')&& par_civ.CheckDeformation==1;
    954 end
    955 % vector=[0 0];%default
    956 for ivec=1:nbvec
    957     iref=round(par_civ.Grid(ivec,1)+0.5);% xindex on the image A for the middle of the correlation box
    958     jref=round(par_civ.ImageHeight-par_civ.Grid(ivec,2)+0.5);% yindex on the image B for the middle of the correlation box
    959     %if ~(checkmask && par_civ.Mask(jref,iref)<=20) %velocity not set to zero by the black mask
    960     %         if jref-iby2<1 || jref+iby2>par_civ.ImageHeight|| iref-ibx2<1 || iref+ibx2>par_civ.ImageWidth||...
    961     %               jref+shifty(ivec)-isy2<1||jref+shifty(ivec)+isy2>par_civ.ImageHeight|| iref+shiftx(ivec)-isx2<1 || iref+shiftx(ivec)+isx2>par_civ.ImageWidth  % we are outside the image
    962     %             F(ivec)=3;
    963     %         else
    964     F(ivec)=0;
    965     subrange1_x=iref-ibx2:iref+ibx2;% x indices defining the first subimage
    966     subrange1_y=jref-iby2:jref+iby2;% y indices defining the first subimage
    967     subrange2_x=iref+shiftx(ivec)-isx2:iref+shiftx(ivec)+isx2;%x indices defining the second subimage
    968     subrange2_y=jref+shifty(ivec)-isy2:jref+shifty(ivec)+isy2;%y indices defining the second subimage
    969     image1_crop=MinA*ones(numel(subrange1_y),numel(subrange1_x));% default value=min of image A
    970     image2_crop=MinA*ones(numel(subrange2_y),numel(subrange2_x));% default value=min of image A
    971     check1_x=subrange1_x>=1 & subrange1_x<=par_civ.ImageWidth;% check which points in the subimage 1 are contained in the initial image 1
    972     check1_y=subrange1_y>=1 & subrange1_y<=par_civ.ImageHeight;
    973     check2_x=subrange2_x>=1 & subrange2_x<=par_civ.ImageWidth;% check which points in the subimage 2 are contained in the initial image 2
    974     check2_y=subrange2_y>=1 & subrange2_y<=par_civ.ImageHeight;
    975    
    976     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
    977     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
    978     image1_mean=mean(mean(image1_crop));
    979     image2_mean=mean(mean(image2_crop));
    980     %threshold on image minimum
    981     if check_MinIma && (image1_mean < par_civ.MinIma || image2_mean < par_civ.MinIma)
    982         F(ivec)=3;
    983     end
    984     %threshold on image maximum
    985     if check_MaxIma && (image1_mean > par_civ.MaxIma || image2_mean > par_civ.MaxIma)
    986         F(ivec)=3;
    987     end
    988     %         end
    989     if F(ivec)~=3
    990         image1_crop=image1_crop-image1_mean;%substract the mean
    991         image2_crop=image2_crop-image2_mean;
    992         if CheckDecimal
    993             xi=(1:mesh:size(image1_crop,2));
    994             yi=(1:mesh:size(image1_crop,1))';
     989CheckDeformation=isfield(par_civ,'CheckDeformation')&& par_civ.CheckDeformation==1;
     990if CheckDeformation
     991    mesh=0.25;%mesh in pixels for subpixel image interpolation (x 4 in each direction)
     992end
     993if par_civ.CorrSmooth~=0 % par_civ.CorrSmooth=0 implies no civ computation (just input image and grid points viven)
     994    for ivec=1:nbvec
     995        iref=round(par_civ.Grid(ivec,1)+0.5);% xindex on the image A for the middle of the correlation box
     996        jref=round(par_civ.ImageHeight-par_civ.Grid(ivec,2)+0.5);% yindex on the image B for the middle of the correlation box
     997        F(ivec)=0;
     998        subrange1_x=iref-ibx2:iref+ibx2;% x indices defining the first subimage
     999        subrange1_y=jref-iby2:jref+iby2;% y indices defining the first subimage
     1000        subrange2_x=iref+shiftx(ivec)-isx2:iref+shiftx(ivec)+isx2;%x indices defining the second subimage
     1001        subrange2_y=jref+shifty(ivec)-isy2:jref+shifty(ivec)+isy2;%y indices defining the second subimage
     1002        image1_crop=MinA*ones(numel(subrange1_y),numel(subrange1_x));% default value=min of image A
     1003        image2_crop=MinA*ones(numel(subrange2_y),numel(subrange2_x));% default value=min of image A
     1004        check1_x=subrange1_x>=1 & subrange1_x<=par_civ.ImageWidth;% check which points in the subimage 1 are contained in the initial image 1
     1005        check1_y=subrange1_y>=1 & subrange1_y<=par_civ.ImageHeight;
     1006        check2_x=subrange2_x>=1 & subrange2_x<=par_civ.ImageWidth;% check which points in the subimage 2 are contained in the initial image 2
     1007        check2_y=subrange2_y>=1 & subrange2_y<=par_civ.ImageHeight;     
     1008        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
     1009        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
     1010        image1_mean=mean(mean(image1_crop));
     1011        image2_mean=mean(mean(image2_crop));
     1012        %threshold on image minimum
     1013        if check_MinIma && (image1_mean < par_civ.MinIma || image2_mean < par_civ.MinIma)
     1014            F(ivec)=3;
     1015        end
     1016        %threshold on image maximum
     1017        if check_MaxIma && (image1_mean > par_civ.MaxIma || image2_mean > par_civ.MaxIma)
     1018            F(ivec)=3;
     1019        end
     1020       
     1021        if F(ivec)~=3
     1022            image1_crop=image1_crop-image1_mean;%substract the mean
     1023            image2_crop=image2_crop-image2_mean;
    9951024            if CheckDeformation
     1025                xi=(1:mesh:size(image1_crop,2));
     1026                yi=(1:mesh:size(image1_crop,1))';
    9961027                [XI,YI]=meshgrid(xi-ceil(size(image1_crop,2)/2),yi-ceil(size(image1_crop,1)/2));
    9971028                XIant=XI-par_civ.DUDX(ivec)*XI-par_civ.DUDY(ivec)*YI+ceil(size(image1_crop,2)/2);
    9981029                YIant=YI-par_civ.DVDX(ivec)*XI-par_civ.DVDY(ivec)*YI+ceil(size(image1_crop,1)/2);
    9991030                image1_crop=interp2(image1_crop,XIant,YIant);
    1000             else
    1001                 image1_crop=interp2(image1_crop,xi,yi);
    1002             end
    1003             xi=(1:mesh:size(image2_crop,2));
    1004             yi=(1:mesh:size(image2_crop,1))';
    1005             image2_crop=interp2(image2_crop,xi,yi);
    1006         end
    1007         sum_square=sum(sum(image1_crop.*image1_crop));
    1008         %reference: Oliver Pust, PIV: Direct Cross-Correlation
    1009         result_conv= conv2(image2_crop,flipdim(flipdim(image1_crop,2),1),'valid');
    1010         corrmax= max(max(result_conv));
    1011         result_conv=(result_conv/corrmax)*255; %normalize, peak=always 255
    1012         %Find the correlation max, at 255
    1013         [y,x] = find(result_conv==255,1);
    1014         if ~isempty(y) && ~isempty(x)
    1015             try
    1016                 if par_civ.CorrSmooth==1
    1017                     [vector,F(ivec)] = SUBPIXGAUSS (result_conv,x,y);
    1018                 elseif par_civ.CorrSmooth==2
    1019                     [vector,F(ivec)] = SUBPIX2DGAUSS (result_conv,x,y);
    1020                 end
    1021 %                 if ~isfield(par_civ,'CheckDeformation')
    1022                 utable(ivec)=vector(1)*mesh+shiftx(ivec);
    1023                 vtable(ivec)=vector(2)*mesh+shifty(ivec);
    1024 %                 else
    1025 %                                 utable(ivec)=shiftx(ivec);% TEST TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    1026 %                 vtable(ivec)=shifty(ivec);
    1027 %                 end
    1028                 xtable(ivec)=iref+utable(ivec)/2-0.5;% convec flow (velocity taken at the point middle from imgae 1 and 2)
    1029                 ytable(ivec)=jref+vtable(ivec)/2-0.5;% and position of pixel 1=0.5 (convention for image coordinates=0 at the edge)
    1030                 iref=round(xtable(ivec));% image index for the middle of the vector
    1031                 jref=round(ytable(ivec));
    1032                 if checkmask && par_civ.Mask(jref,iref)<200 && par_civ.Mask(jref,iref)>=100
    1033                     utable(ivec)=0;
    1034                     vtable(ivec)=0;
     1031                xi=(1:mesh:size(image2_crop,2));
     1032                yi=(1:mesh:size(image2_crop,1))';
     1033                image2_crop=interp2(image2_crop,xi,yi);
     1034            end
     1035            sum_square=sum(sum(image1_crop.*image1_crop));
     1036            %reference: Oliver Pust, PIV: Direct Cross-Correlation
     1037            result_conv= conv2(image2_crop,flipdim(flipdim(image1_crop,2),1),'valid');
     1038            corrmax= max(max(result_conv));
     1039            result_conv=(result_conv/corrmax)*255; %normalize, peak=always 255
     1040            %Find the correlation max, at 255
     1041            [y,x] = find(result_conv==255,1);
     1042            if ~isempty(y) && ~isempty(x)
     1043                try
     1044                    if par_civ.CorrSmooth==1
     1045                        [vector,F(ivec)] = SUBPIXGAUSS (result_conv,x,y);
     1046                    elseif par_civ.CorrSmooth==2
     1047                        [vector,F(ivec)] = SUBPIX2DGAUSS (result_conv,x,y);
     1048                    end
     1049                    utable(ivec)=vector(1)*mesh+shiftx(ivec);
     1050                    vtable(ivec)=vector(2)*mesh+shifty(ivec);
     1051                    xtable(ivec)=iref+utable(ivec)/2-0.5;% convec flow (velocity taken at the point middle from imgae 1 and 2)
     1052                    ytable(ivec)=jref+vtable(ivec)/2-0.5;% and position of pixel 1=0.5 (convention for image coordinates=0 at the edge)
     1053                    iref=round(xtable(ivec));% image index for the middle of the vector
     1054                    jref=round(ytable(ivec));
     1055                    if checkmask && par_civ.Mask(jref,iref)<200 && par_civ.Mask(jref,iref)>=100
     1056                        utable(ivec)=0;
     1057                        vtable(ivec)=0;
     1058                        F(ivec)=3;
     1059                    end
     1060                    ctable(ivec)=corrmax/sum_square;% correlation value
     1061                catch ME
    10351062                    F(ivec)=3;
    10361063                end
    1037                 ctable(ivec)=corrmax/sum_square;% correlation value
    1038             catch ME
     1064            else
    10391065                F(ivec)=3;
    10401066            end
    1041         else
    1042             F(ivec)=3;
    10431067        end
    10441068    end
  • trunk/src/uvmat.m

    r853 r856  
    487487set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0])
    488488drawnow
    489 RootPath=get(handles.RootPath,'String');
    490 if isempty(RootPath)
    491     RootPath=get(handles.RootPath,'UserData');%use Rootpath recored from the personal file at uvmat opening
    492 end
    493 CampaignPath=fileparts(fileparts(RootPath));
    494 DirFull=uigetfile_uvmat('define this path as the Campaign folder:',CampaignPath,'uigetdir');
    495 %DirFull = uigetdir(CampaignPath,'Select a Campaign dir, then press OK');
    496 if isempty(DirFull)
    497     return
    498 end
    499 OutPut=browse_data(DirFull,'on');% open the GUI browse_data to get select a campaign dir, experiment and device
     489[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     490DataSeries=fullfile(RootPath,SubDir);
     491if isempty(DataSeries) %loads the previously stored file name and set it as default in the file_input box
     492    DataSeries=get(handles.RootPath,'UserData');
     493end
     494% RootPath=get(handles.RootPath,'String');
     495% if isempty(RootPath)
     496%     RootPath=get(handles.RootPath,'UserData');%use Rootpath recored from the personal file at uvmat opening
     497% end
     498% CampaignPath=fileparts(fileparts(RootPath));
     499% DirFull=uigetfile_uvmat('define this path as the Campaign folder:',CampaignPath,'uigetdir');
     500% %DirFull = uigetdir(CampaignPath,'Select a Campaign dir, then press OK');
     501% if isempty(DirFull)
     502%     return
     503% end
     504if isempty(DataSeries)||~ischar(DataSeries)
     505    DataSeries=pwd;
     506end
     507OutPut=browse_data(DataSeries,'on');% open the GUI browse_data to get select a campaign dir, experiment and device
    500508if ~isfield(OutPut,'Campaign')
    501509    return
    502510end
    503 fileinput=uigetfile_uvmat('pick an input file',fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1}));
     511DataSeries=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1});
     512fileinput=uigetfile_uvmat('pick an input file',DataSeries);
    504513hh=dir(fileinput);
    505514if numel(hh)>1
     
    511520MenuCampaign=[{get(handles.MenuCampaign_1,'Label')};{get(handles.MenuCampaign_2,'Label')};...
    512521    {get(handles.MenuCampaign_3,'Label')};{get(handles.MenuCampaign_4,'Label')};{get(handles.MenuCampaign_5,'Label')}];
    513 check_dir=isempty(find(strcmp(DirFull,MenuCampaign)));
     522check_dir=isempty(find(strcmp(DataSeries,MenuCampaign)));
    514523if check_dir %insert the new campaign in the list if it is not found
    515524    MenuCampaign(end)=[]; %suppress the last item
    516     MenuCampaign=[{DirFull};MenuCampaign];%insert the new campaign
     525    MenuCampaign=[{DataSeries};MenuCampaign];%insert the new campaign
    517526    for ilist=1:numel(MenuCampaign)
    518527        set(handles.(['MenuCampaign_' num2str(ilist)]),'Label',MenuCampaign{ilist})
Note: See TracChangeset for help on using the changeset viewer.