| [598] | 1 | %'civ_series': PIV function activated by the general GUI series |
|---|
| 2 | % --- call the sub-functions: |
|---|
| 3 | % civ: PIV function itself |
|---|
| [1143] | 4 | % detect_false: put a flag to false vectors after detection by various criteria |
|---|
| [1169] | 5 | % filter_tps: make interpolation-smoothing |
|---|
| [597] | 6 | %------------------------------------------------------------------------ |
|---|
| [855] | 7 | % function [Data,errormsg,result_conv]= civ_series(Param) |
|---|
| [597] | 8 | % |
|---|
| 9 | %OUTPUT |
|---|
| [598] | 10 | % Data=structure containing the PIV results and information on the processing parameters |
|---|
| [995] | 11 | % errormsg=error message char string, decd ..fault='' |
|---|
| [598] | 12 | % resul_conv: image inter-correlation function for the last grid point (used for tests) |
|---|
| [597] | 13 | % |
|---|
| 14 | %INPUT: |
|---|
| [855] | 15 | % Param: Matlab structure of input parameters |
|---|
| 16 | % Param contains info of the GUI series using the fct read_GUI. |
|---|
| [1169] | 17 | % Param.Action.RUN = 0 (to set the status of the GUI series) or =1 to RUN the computation |
|---|
| [855] | 18 | % Param.InputTable: sets the input file(s) |
|---|
| 19 | % if absent, the fct looks for input data in Param.ActionInput (test mode) |
|---|
| 20 | % Param.OutputSubDir: sets the folder name of output file(s, |
|---|
| 21 | % if absent no file is produced, result in the output structure Data (test mode) |
|---|
| [859] | 22 | % Param.ActionInput: substructure with the parameters provided by the GUI civ_input |
|---|
| [1131] | 23 | % .Civ1: parameters for civ1cc |
|---|
| [1143] | 24 | % .Fix1: parameters for detect_false1 |
|---|
| [859] | 25 | % .Patch1: |
|---|
| [855] | 26 | % .Civ2: for civ2 |
|---|
| [859] | 27 | % .Fix2: |
|---|
| [855] | 28 | % .Patch2: |
|---|
| 29 | |
|---|
| [924] | 30 | %======================================================================= |
|---|
| [1126] | 31 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
|---|
| [924] | 32 | % http://www.legi.grenoble-inp.fr |
|---|
| [1127] | 33 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr |
|---|
| [859] | 34 | % |
|---|
| [924] | 35 | % This file is part of the toolbox UVMAT. |
|---|
| 36 | % |
|---|
| [598] | 37 | % UVMAT is free software; you can redistribute it and/or modify |
|---|
| [924] | 38 | % it under the terms of the GNU General Public License as published |
|---|
| 39 | % by the Free Software Foundation; either version 2 of the license, |
|---|
| 40 | % or (at your option) any later version. |
|---|
| [859] | 41 | % |
|---|
| [598] | 42 | % UVMAT is distributed in the hope that it will be useful, |
|---|
| 43 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 44 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| [924] | 45 | % GNU General Public License (see LICENSE.txt) for more details. |
|---|
| 46 | %======================================================================= |
|---|
| [597] | 47 | |
|---|
| [724] | 48 | function [Data,errormsg,result_conv]= civ_series(Param) |
|---|
| [598] | 49 | errormsg=''; |
|---|
| [763] | 50 | |
|---|
| [606] | 51 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed |
|---|
| [859] | 52 | if isstruct(Param) && isequal(Param.Action.RUN,0)% function activated from the GUI series but not RUN |
|---|
| [1175] | 53 | if 0==1 %never satisfied but trigger compilation with the appropriate transform functions ('eval' inactive for compilation) |
|---|
| 54 | ima_rescale |
|---|
| 55 | end |
|---|
| [763] | 56 | path_series=fileparts(which('series')); |
|---|
| 57 | addpath(fullfile(path_series,'series')) |
|---|
| [598] | 58 | Data=civ_input(Param);% introduce the civ parameters using the GUI civ_input |
|---|
| [1148] | 59 | % TODO: change from guide to App: modify the input procedure, adapt read_GUI function |
|---|
| 60 | %App=civ_input_App |
|---|
| [1089] | 61 | %Data=civ_input_App(Param);% introduce the civ parameters using the GUI civ_input |
|---|
| [1148] | 62 | % if isempty(App) |
|---|
| 63 | % Data=Param;% if civ_input has been cancelled, keep previous parameters |
|---|
| 64 | % end |
|---|
| [606] | 65 | Data.Program=mfilename;%gives the name of the current function |
|---|
| 66 | Data.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
|---|
| 67 | Data.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
|---|
| 68 | Data.NbSlice='off'; %nbre of slices ('off' by default) |
|---|
| 69 | Data.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
|---|
| [781] | 70 | Data.FieldName='on';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
|---|
| [1181] | 71 | Data.FieldTransform = 'off';%can use a transform function |
|---|
| [606] | 72 | Data.ProjObject='off';%can use projection object(option 'off'/'on', |
|---|
| 73 | Data.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
|---|
| 74 | Data.OutputDirExt='.civ';%set the output dir extension |
|---|
| [711] | 75 | Data.OutputSubDirMode='last'; %select the last subDir in the input table as root of the output subdir name (option 'all'/'first'/'last', 'all' by default) |
|---|
| [645] | 76 | Data.OutputFileMode='NbInput_i';% one output file expected per value of i index (used for waitbar) |
|---|
| [904] | 77 | Data.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1) |
|---|
| [1170] | 78 | if isfield(Data,'ActionInput') && isfield(Data.ActionInput,'PairIndices') && isequal(Data.ActionInput.PairIndices.ListPairMode,'pair j1-j2') |
|---|
| [1156] | 79 | Data.IndexRange_j='off';%no j index display in series |
|---|
| 80 | else |
|---|
| 81 | Data.IndexRange_j='on';% j index display in series if relevant |
|---|
| [993] | 82 | end |
|---|
| [598] | 83 | return |
|---|
| [597] | 84 | end |
|---|
| 85 | |
|---|
| 86 | %% read input parameters from an xml file if input is a file name (batch mode) |
|---|
| 87 | checkrun=1; |
|---|
| 88 | if ischar(Param) |
|---|
| 89 | Param=xml2struct(Param);% read Param as input file (batch case) |
|---|
| 90 | checkrun=0; |
|---|
| 91 | end |
|---|
| [855] | 92 | |
|---|
| 93 | %% test input |
|---|
| [668] | 94 | if ~isfield(Param,'ActionInput') |
|---|
| [859] | 95 | disp_uvmat('ERROR','no parameter set for PIV',checkrun) |
|---|
| 96 | return |
|---|
| [668] | 97 | end |
|---|
| [1169] | 98 | %iview_A=0;%default values |
|---|
| [855] | 99 | NbField=1; |
|---|
| 100 | RUNHandle=[]; |
|---|
| [1169] | 101 | % CheckInputFile=isfield(Param,'InputTable');%= 1 in test use for TestCiv (no nc file involved) |
|---|
| 102 | % CheckOutputFile=isfield(Param,'OutputSubDir');%= 1 in test use for TestPatch (no nc file produced) |
|---|
| [597] | 103 | |
|---|
| [1175] | 104 | %% input files and indexing |
|---|
| [1169] | 105 | hseries=findobj(allchild(0),'Tag','series'); |
|---|
| 106 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
|---|
| 107 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
|---|
| 108 | MaxIndex_i=Param.IndexRange.MaxIndex_i; |
|---|
| 109 | MinIndex_i=Param.IndexRange.MinIndex_i; |
|---|
| 110 | MaxIndex_j=ones(size(MaxIndex_i));MinIndex_j=ones(size(MinIndex_i)); |
|---|
| 111 | if isfield(Param.IndexRange,'MaxIndex_j')&& isfield(Param.IndexRange,'MinIndex_j') |
|---|
| 112 | MaxIndex_j=Param.IndexRange.MaxIndex_j; |
|---|
| 113 | MinIndex_j=Param.IndexRange.MinIndex_j; |
|---|
| 114 | end |
|---|
| 115 | if isfield(Param,'InputTable') |
|---|
| 116 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
|---|
| 117 | iview_B=0;% series index (iview) for the second image series (only non zero for option 'shift' comparing two image series ) |
|---|
| 118 | if Param.ActionInput.CheckCiv1 |
|---|
| 119 | iview_A=1;% usual PIV, the image series is on the first line of the table |
|---|
| 120 | else % Civ1 has been already stored in a netcdf file input |
|---|
| 121 | iview_A=2;% the second line is used for the input images |
|---|
| [609] | 122 | end |
|---|
| [1169] | 123 | RootPath_A=Param.InputTable{iview_A,1}; |
|---|
| 124 | RootFile_A=Param.InputTable{iview_A,3}; |
|---|
| 125 | SubDir_A=Param.InputTable{iview_A,2}; |
|---|
| 126 | NomType_A=Param.InputTable{iview_A,4}; |
|---|
| 127 | FileExt_A=Param.InputTable{iview_A,5}; |
|---|
| 128 | if iview_B==0 |
|---|
| 129 | iview_B=iview_A;% the second image series is the same as the first |
|---|
| 130 | end |
|---|
| 131 | RootPath_B=Param.InputTable{iview_B,1}; |
|---|
| 132 | RootFile_B=Param.InputTable{iview_B,3}; |
|---|
| 133 | SubDir_B=Param.InputTable{iview_B,2}; |
|---|
| 134 | NomType_B=Param.InputTable{iview_B,4}; |
|---|
| 135 | FileExt_B=Param.InputTable{iview_B,5}; |
|---|
| 136 | PairCiv2=''; |
|---|
| 137 | |
|---|
| 138 | switch Param.ActionInput.ListCompareMode |
|---|
| 139 | case 'PIV' |
|---|
| 140 | PairCiv1=Param.ActionInput.PairIndices.ListPairCiv1; |
|---|
| 141 | if isfield(Param.ActionInput.PairIndices,'ListPairCiv2') |
|---|
| 142 | PairCiv2=Param.ActionInput.PairIndices.ListPairCiv2;%string which determines the civ2 pair |
|---|
| [758] | 143 | end |
|---|
| [1169] | 144 | if iview_A==1% if Civ1 is performed |
|---|
| 145 | [i1_series_Civ1,i2_series_Civ1,j1_series_Civ1,j2_series_Civ1,check_bounds,NomTypeNc]=... |
|---|
| 146 | find_pair_indices(PairCiv1,i1_series{1},j1_series{1},MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j); |
|---|
| 147 | if ~isempty(PairCiv2) |
|---|
| 148 | [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds_Civ2]=... |
|---|
| 149 | find_pair_indices(PairCiv2,i1_series{1},j1_series{1},MinIndex_i(1),MaxIndex_i(1),MinIndex_j(1),MaxIndex_j(1)); |
|---|
| 150 | check_bounds=check_bounds | check_bounds_Civ2; |
|---|
| [761] | 151 | end |
|---|
| [1169] | 152 | else% we start from an existing Civ1 file |
|---|
| 153 | i1_series_Civ1=i1_series{1}; |
|---|
| 154 | i2_series_Civ1=i2_series{1}; |
|---|
| 155 | j1_series_Civ1=j1_series{1}; |
|---|
| 156 | j2_series_Civ1=j2_series{1}; |
|---|
| 157 | NomTypeNc=Param.InputTable{1,4}; |
|---|
| 158 | if ~isempty(PairCiv2) |
|---|
| 159 | [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds,NomTypeNc]=... |
|---|
| 160 | find_pair_indices(PairCiv2,i1_series{2},j1_series{2},MinIndex_i(2),MaxIndex_i(2),MinIndex_j(2),MaxIndex_j(2)); |
|---|
| [761] | 161 | end |
|---|
| [1169] | 162 | end |
|---|
| 163 | case 'displacement' |
|---|
| 164 | if isfield(Param.ActionInput,'OriginIndex') |
|---|
| [855] | 165 | i1_series_Civ1=Param.ActionInput.OriginIndex*ones(size(i1_series{1})); |
|---|
| [1169] | 166 | else |
|---|
| 167 | i1_series_Civ1=ones(size(i1_series{1})); |
|---|
| [1020] | 168 | end |
|---|
| [1169] | 169 | i1_series_Civ2=i1_series_Civ1; |
|---|
| 170 | i2_series_Civ1=i1_series{1}; |
|---|
| 171 | i2_series_Civ2=i1_series{1}; |
|---|
| 172 | j1_series_Civ1=[];% no j index variation for the ref image |
|---|
| 173 | j1_series_Civ2=[]; |
|---|
| 174 | if isempty(j1_series{1}) |
|---|
| 175 | j2_series_Civ1=ones(size(i1_series_Civ1)); |
|---|
| [855] | 176 | else |
|---|
| [1169] | 177 | j2_series_Civ1=j1_series{1};% if j index exist |
|---|
| [855] | 178 | end |
|---|
| [1169] | 179 | j2_series_Civ2=j2_series_Civ1; |
|---|
| 180 | NomTypeNc='_1'; |
|---|
| 181 | end |
|---|
| 182 | %determine frame indices for input with movie or other multiframe input file |
|---|
| 183 | if isempty(j1_series_Civ1)% simple movie with index i |
|---|
| 184 | FrameIndex_A_Civ1=i1_series_Civ1; |
|---|
| 185 | FrameIndex_B_Civ1=i2_series_Civ1; |
|---|
| 186 | j1_series_Civ1=ones(size(i1_series_Civ1)); |
|---|
| 187 | if strcmp(Param.ActionInput.ListCompareMode,'PIV') |
|---|
| 188 | j2_series_Civ1=ones(size(i1_series_Civ1)); |
|---|
| [758] | 189 | end |
|---|
| [1169] | 190 | else % movie for each burst or volume (index j) |
|---|
| 191 | FrameIndex_A_Civ1=j1_series_Civ1; |
|---|
| 192 | FrameIndex_B_Civ1=j2_series_Civ1; |
|---|
| [855] | 193 | end |
|---|
| [1169] | 194 | if isempty(PairCiv2) |
|---|
| 195 | FrameIndex_A_Civ2=FrameIndex_A_Civ1; |
|---|
| 196 | FrameIndex_B_Civ2=FrameIndex_B_Civ1; |
|---|
| 197 | else |
|---|
| 198 | if isempty(j1_series_Civ2) |
|---|
| 199 | FrameIndex_A_Civ2=i1_series_Civ2; |
|---|
| 200 | FrameIndex_B_Civ2=i2_series_Civ2; |
|---|
| 201 | j1_series_Civ2=ones(size(i1_series_Civ2)); |
|---|
| 202 | if strcmp(Param.ActionInput.ListCompareMode,'PIV') |
|---|
| 203 | j2_series_Civ2=ones(size(i1_series_Civ2)); |
|---|
| 204 | end |
|---|
| [819] | 205 | else |
|---|
| [1169] | 206 | FrameIndex_A_Civ2=j1_series_Civ2; |
|---|
| 207 | FrameIndex_B_Civ2=j2_series_Civ2; |
|---|
| [781] | 208 | end |
|---|
| [758] | 209 | end |
|---|
| [1169] | 210 | if isempty(i1_series_Civ1)||(~isempty(PairCiv2) && isempty(i1_series_Civ2)) |
|---|
| 211 | disp_uvmat('ERROR','no image pair for civ in the input file index range',checkrun) |
|---|
| 212 | return |
|---|
| 213 | end |
|---|
| [758] | 214 | end |
|---|
| 215 | |
|---|
| [1169] | 216 | %% check the first image pair |
|---|
| 217 | if Param.ActionInput.CheckCiv1% Civ1 is performed |
|---|
| 218 | NbField=numel(i1_series_Civ1); |
|---|
| 219 | elseif Param.ActionInput.CheckCiv2 % Civ2 is performed without Civ1 |
|---|
| 220 | NbField=numel(i1_series_Civ2); |
|---|
| 221 | else |
|---|
| 222 | NbField=numel(i1_series_Civ1);% no image used (only detect_false or patch) TO CHECK |
|---|
| 223 | end |
|---|
| 224 | |
|---|
| [855] | 225 | %% prepare output Data |
|---|
| [1169] | 226 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
|---|
| [886] | 227 | ListGlobalAttribute={'Conventions','Program','CivStage'}; |
|---|
| [605] | 228 | Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes |
|---|
| 229 | Data.Program='civ_series'; |
|---|
| [1154] | 230 | if isfield(Param,'UvmatRevision') |
|---|
| 231 | Data.Program=[Data.Program ', uvmat r' Param.UvmatRevision]; |
|---|
| 232 | end |
|---|
| [605] | 233 | Data.CivStage=0;%default |
|---|
| 234 | |
|---|
| [606] | 235 | %% get timing from the ImaDoc file or input video |
|---|
| [1169] | 236 | % if iview_A~=0 |
|---|
| 237 | XmlFileName=find_imadoc(RootPath_A,SubDir_A); |
|---|
| 238 | Time=[]; |
|---|
| 239 | if ~isempty(XmlFileName) |
|---|
| 240 | XmlData=imadoc2struct(XmlFileName);%read the time from XmlFileName |
|---|
| 241 | if isfield(XmlData,'Time') |
|---|
| 242 | Time=XmlData.Time; |
|---|
| 243 | end |
|---|
| 244 | if isfield(XmlData,'Camera') |
|---|
| 245 | if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice) |
|---|
| 246 | NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform |
|---|
| 247 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
|---|
| 248 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); |
|---|
| [609] | 249 | end |
|---|
| 250 | end |
|---|
| [1169] | 251 | if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit) |
|---|
| 252 | TimeUnit=XmlData.Camera.TimeUnit; |
|---|
| 253 | end |
|---|
| [833] | 254 | end |
|---|
| [610] | 255 | end |
|---|
| [1180] | 256 | |
|---|
| 257 | %% File relabeling documented by the xml file (e.g. PCO) |
|---|
| [1178] | 258 | CheckRelabel=isfield(Param,'FileSeries' );%=true for index relabeling (PCO) |
|---|
| [609] | 259 | |
|---|
| [1181] | 260 | % %% introduce input image transform |
|---|
| 261 | % transform_fct=[];%default, no transform |
|---|
| 262 | % if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
|---|
| 263 | % currentdir=pwd; |
|---|
| 264 | % cd(Param.FieldTransform.TransformPath) |
|---|
| 265 | % transform_fct=str2func(Param.FieldTransform.TransformName); |
|---|
| 266 | % cd (currentdir) |
|---|
| 267 | % end |
|---|
| [1175] | 268 | |
|---|
| [598] | 269 | %%%%% MAIN LOOP %%%%%% |
|---|
| [1010] | 270 | maskoldname='';% initiate the mask name |
|---|
| [1176] | 271 | backgroundoldname=''; |
|---|
| [997] | 272 | FileType_A=''; |
|---|
| 273 | FileType_B=''; |
|---|
| [904] | 274 | CheckOverwrite=1;%default |
|---|
| 275 | if isfield(Param,'CheckOverwrite') |
|---|
| 276 | CheckOverwrite=Param.CheckOverwrite; |
|---|
| 277 | end |
|---|
| [598] | 278 | for ifield=1:NbField |
|---|
| [1131] | 279 | tstart=tic; |
|---|
| 280 | time_civ1=0; |
|---|
| [1164] | 281 | time_patch1=0; |
|---|
| 282 | time_civ2=0; |
|---|
| 283 | time_patch2=0; |
|---|
| [855] | 284 | if ~isempty(RUNHandle)% update the waitbar in interactive mode with GUI series (checkrun=1) |
|---|
| 285 | update_waitbar(WaitbarHandle,ifield/NbField) |
|---|
| [905] | 286 | if checkrun && ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
|---|
| [855] | 287 | disp('program stopped by user') |
|---|
| 288 | break |
|---|
| 289 | end |
|---|
| [624] | 290 | end |
|---|
| [1169] | 291 | OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device); |
|---|
| [1178] | 292 | if CheckRelabel |
|---|
| 293 | RootFileOut=index2filename(Param.FileSeries,1,1,MaxIndex_j); |
|---|
| 294 | else |
|---|
| 295 | RootFileOut=RootFile_A; |
|---|
| 296 | end |
|---|
| [1169] | 297 | if strcmp(Param.ActionInput.ListCompareMode,'PIV') |
|---|
| [1178] | 298 | ncfile=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),... |
|---|
| [1169] | 299 | j1_series_Civ1(ifield),j2_series_Civ1(ifield)); |
|---|
| 300 | else |
|---|
| [1178] | 301 | ncfile=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeNc,i2_series_Civ1(ifield),[],... |
|---|
| [1169] | 302 | j1_series_Civ1(ifield),j2_series_Civ1(ifield)); |
|---|
| 303 | end |
|---|
| 304 | ncfile_out=ncfile;% by default |
|---|
| 305 | |
|---|
| 306 | if isfield (Param.ActionInput,'Civ2') |
|---|
| 307 | i1_civ2=i1_series_Civ2(ifield); |
|---|
| 308 | i2_civ2=i1_civ2; |
|---|
| 309 | if ~isempty(i2_series_Civ2) |
|---|
| 310 | i2_civ2=i2_series_Civ2(ifield); |
|---|
| [822] | 311 | end |
|---|
| [1169] | 312 | j1_civ2=1; |
|---|
| 313 | if ~isempty(j1_series_Civ2) |
|---|
| 314 | j1_civ2=j1_series_Civ2(ifield); |
|---|
| [904] | 315 | end |
|---|
| [1169] | 316 | j2_civ2=i1_civ2; |
|---|
| 317 | if ~isempty(j2_series_Civ2) |
|---|
| 318 | j2_civ2=j2_series_Civ2(ifield); |
|---|
| [912] | 319 | end |
|---|
| [1169] | 320 | if strcmp(Param.ActionInput.ListCompareMode,'PIV') |
|---|
| [1178] | 321 | ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2); |
|---|
| [1169] | 322 | else % displacement |
|---|
| [1178] | 323 | ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeNc,i2_civ2,[],j2_civ2); |
|---|
| [1169] | 324 | end |
|---|
| [761] | 325 | end |
|---|
| [1169] | 326 | if ~CheckOverwrite && exist(ncfile_out,'file') |
|---|
| 327 | disp(['existing output file ' ncfile_out ' already exists, skip to next field']) |
|---|
| 328 | continue% skip iteration if the mode overwrite is desactivated and the result file already exists |
|---|
| 329 | end |
|---|
| 330 | % end |
|---|
| [1122] | 331 | ImageName_A='';ImageName_B='';%default |
|---|
| 332 | VideoObject_A=[];VideoObject_B=[]; |
|---|
| [1143] | 333 | |
|---|
| [598] | 334 | %% Civ1 |
|---|
| [707] | 335 | % if Civ1 computation is requested |
|---|
| [1164] | 336 | if Param.ActionInput.CheckCiv1 |
|---|
| [1169] | 337 | disp('civ1 started') |
|---|
| [1020] | 338 | par_civ1=Param.ActionInput.Civ1;% parameters for civ1 |
|---|
| [1169] | 339 | %if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B) |
|---|
| 340 | try |
|---|
| 341 | if strcmp(Param.ActionInput.ListCompareMode,'displacement') |
|---|
| 342 | ImageName_A=Param.ActionInput.RefFile; |
|---|
| [1178] | 343 | elseif CheckRelabel |
|---|
| [1180] | 344 | [RootFile,FrameIndex_A]=index2filename(Param.FileSeries,i1_series_Civ1(ifield),j1_series_Civ1(ifield),MaxIndex_j); |
|---|
| 345 | ImageName_A=fullfile(RootPath_A,SubDir_A,RootFile); |
|---|
| [1169] | 346 | else |
|---|
| 347 | ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield)); |
|---|
| [1178] | 348 | FrameIndex_A=FrameIndex_A_Civ1(ifield); |
|---|
| [1169] | 349 | end |
|---|
| 350 | if strcmp(FileExt_A,'.nc')% case of input images in format netcdf |
|---|
| 351 | FieldName_A=Param.InputFields.FieldName; |
|---|
| 352 | [DataIn,~,~,errormsg]=nc2struct(ImageName_A,{FieldName_A}); |
|---|
| 353 | par_civ1.ImageA=DataIn.(FieldName_A); |
|---|
| 354 | else % usual image formats for image A |
|---|
| 355 | if isempty(FileType_A)% open the image object if not already done in case of movie input |
|---|
| 356 | [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A); |
|---|
| 357 | FileType_A=FileInfo_A.FileType; |
|---|
| [1170] | 358 | if isempty(Time) && ~isempty(find(strcmp(FileType_A,{'mmreader','video','cine_phantom','telopsIR'}), 1))% case of video input |
|---|
| [1180] | 359 | Time=zeros(FileInfo_A.NumberOfFrames+1,2); |
|---|
| [1169] | 360 | Time(:,2)=(0:1/FileInfo_A.FrameRate:(FileInfo_A.NumberOfFrames)/FileInfo_A.FrameRate)'; |
|---|
| [1180] | 361 | if ~isempty(j1_series_Civ1) && j1_series_Civ1~=1 |
|---|
| 362 | Time=Time'; |
|---|
| 363 | end |
|---|
| [997] | 364 | end |
|---|
| [1169] | 365 | if ~isempty(FileType_A) && isempty(Time)% Time = index i +0.001 index j by default |
|---|
| 366 | MaxIndex_i=max(i2_series_Civ1); |
|---|
| 367 | MaxIndex_j=max(j2_series_Civ1); |
|---|
| 368 | Time=(1:MaxIndex_i)'*ones(1,MaxIndex_j); |
|---|
| 369 | Time=Time+0.001*ones(MaxIndex_i,1)*(1:MaxIndex_j); |
|---|
| 370 | Time=[zeros(1,MaxIndex_j);Time];% insert a first line of zeros |
|---|
| 371 | Time=[zeros(MaxIndex_i+1,1) Time];% insert a first column of zeros |
|---|
| [997] | 372 | end |
|---|
| [855] | 373 | end |
|---|
| [1169] | 374 | if isempty(regexp(ImageName_A,'(^http://)|(^https://)', 'once')) && ~exist(ImageName_A,'file') |
|---|
| 375 | disp([ImageName_A ' missing']) |
|---|
| [1164] | 376 | continue |
|---|
| 377 | end |
|---|
| [1169] | 378 | tsart_input=tic; |
|---|
| [1178] | 379 | [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileType_A,VideoObject_A,FrameIndex_A); |
|---|
| [1169] | 380 | time_input=toc(tsart_input); |
|---|
| [781] | 381 | end |
|---|
| [1180] | 382 | if CheckRelabel |
|---|
| 383 | [RootFile,FrameIndex_B]=index2filename(Param.FileSeries,i2_series_Civ1(ifield),j2_series_Civ1(ifield),MaxIndex_j); |
|---|
| 384 | ImageName_B=fullfile(RootPath_B,SubDir_B,RootFile); |
|---|
| 385 | else |
|---|
| 386 | ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(ifield),[],j2_series_Civ1(ifield)); |
|---|
| 387 | FrameIndex_B=FrameIndex_B_Civ1(ifield); |
|---|
| 388 | end |
|---|
| [1169] | 389 | if isempty(FileType_B)% determine the image type for the first field |
|---|
| 390 | [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B); |
|---|
| 391 | FileType_B=FileInfo_B.FileType; |
|---|
| [781] | 392 | end |
|---|
| [1169] | 393 | if isempty(regexp(ImageName_B,'(^http://)|(^https://)', 'once')) && ~exist(ImageName_B,'file') |
|---|
| 394 | disp([ImageName_B ' missing']) |
|---|
| 395 | continue |
|---|
| [758] | 396 | end |
|---|
| [1178] | 397 | [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B); |
|---|
| [1180] | 398 | |
|---|
| [1169] | 399 | catch ME % display errors in reading input images |
|---|
| 400 | if ~isempty(ME.message) |
|---|
| 401 | disp_uvmat('ERROR', ['error reading input image: ' ME.message],checkrun) |
|---|
| 402 | continue |
|---|
| [855] | 403 | end |
|---|
| [1169] | 404 | end |
|---|
| [1176] | 405 | |
|---|
| 406 | % case of background image to subtract |
|---|
| 407 | if par_civ1.CheckBackground &&~isempty(par_civ1.Background) |
|---|
| 408 | [RootPath_background,SubDir_background,RootFile_background,~,~,~,~,Ext_background]=fileparts_uvmat(Param.ActionInput.Civ1.Background); |
|---|
| 409 | j1=1; |
|---|
| 410 | if ~isempty(j1_series_Civ1) |
|---|
| 411 | j1=j1_series_Civ1(ifield); |
|---|
| 412 | end |
|---|
| 413 | if ~isempty(i2_series_Civ1)% case of volume,backgrounds act on different j levels |
|---|
| 414 | backgroundname=fullfile_uvmat(RootPath_background,SubDir_background,RootFile_background,Ext_background,'_1',j1); |
|---|
| 415 | elseif isfield(par_civ1,'NbSlice') |
|---|
| 416 | i1_background=mod(i1-1,par_civ1.NbSlice)+1; |
|---|
| 417 | backgroundname=fullfile_uvmat(RootPath_background,SubDir_background,RootFile_background,Ext_background,'_1',i1_background); |
|---|
| 418 | if strcmp(Param.ActionInput.PairIndices.ListPairMode,'series(Di)')% case of volume, background index refers to j index |
|---|
| 419 | par_civ1.NbSlice_j=par_civ1.NbSlice; |
|---|
| 420 | end |
|---|
| 421 | else |
|---|
| 422 | backgroundname=Param.ActionInput.Civ1.Background; |
|---|
| 423 | end |
|---|
| 424 | if strcmp(backgroundoldname,backgroundname)% background exist, not already read in civ1 |
|---|
| 425 | par_civ1.Background=background; %use background already opened |
|---|
| 426 | else |
|---|
| 427 | if ~isempty(regexp(backgroundname,'(^http://)|(^https://)', 'once'))|| exist(backgroundname,'file') |
|---|
| 428 | try |
|---|
| 429 | par_civ1.Background=imread(backgroundname);%update the background, an store it for future use |
|---|
| 430 | catch ME |
|---|
| 431 | if ~isempty(ME.message) |
|---|
| 432 | errormsg=['error reading input image: ' ME.message]; |
|---|
| 433 | disp_uvmat('ERROR',errormsg,checkrun) |
|---|
| 434 | return |
|---|
| 435 | end |
|---|
| 436 | end |
|---|
| 437 | else |
|---|
| 438 | par_civ1.Background=[]; |
|---|
| 439 | end |
|---|
| 440 | background=par_civ1.Background; |
|---|
| 441 | backgroundoldname=backgroundname; |
|---|
| 442 | end |
|---|
| 443 | par_civ1.ImageA=par_civ1.ImageA-par_civ1.Background; |
|---|
| 444 | par_civ1.ImageB=par_civ1.ImageB-par_civ1.Background; |
|---|
| 445 | end |
|---|
| 446 | |
|---|
| [1181] | 447 | % case of image luminosity rescaling |
|---|
| 448 | if par_civ1.CheckRescale &&~isempty(par_civ1.Maxtanh) |
|---|
| 449 | par_civ1.ImageA =par_civ1.Maxtanh*tanh(double(par_civ1.ImageA)/par_civ1.Maxtanh); |
|---|
| 450 | par_civ1.ImageB=par_civ1.Maxtanh*tanh(double(par_civ1.ImageB)/par_civ1.Maxtanh); |
|---|
| [1175] | 451 | end |
|---|
| [1169] | 452 | |
|---|
| 453 | % par_civ1.ImageWidth=size(par_civ1.ImageA,2); |
|---|
| 454 | % par_civ1.ImageHeight=size(par_civ1.ImageA,1); |
|---|
| 455 | list_param=(fieldnames(Param.ActionInput.Civ1))'; |
|---|
| 456 | list_param(strcmp('TestCiv1',list_param))=[];% remove the parameter TestCiv1 from the list |
|---|
| 457 | Civ1_param=regexprep(list_param,'^.+','Civ1_$0');% insert 'Civ1_' before each string in list_param |
|---|
| 458 | Civ1_param=[{'Civ1_ImageA','Civ1_ImageB','Civ1_Time','Civ1_Dt'} Civ1_param]; %insert the names of the two input images |
|---|
| 459 | %indicate the values of all the global attributes in the output data |
|---|
| 460 | Data.Civ1_ImageA=ImageName_A; |
|---|
| 461 | Data.Civ1_ImageB=ImageName_B; |
|---|
| 462 | i1=i1_series_Civ1(ifield); |
|---|
| 463 | i2=i1; |
|---|
| 464 | if ~isempty(i2_series_Civ1) |
|---|
| 465 | i2=i2_series_Civ1(ifield); |
|---|
| 466 | end |
|---|
| 467 | j1=1; |
|---|
| 468 | if ~isempty(j1_series_Civ1) |
|---|
| 469 | j1=j1_series_Civ1(ifield); |
|---|
| 470 | end |
|---|
| 471 | j2=j1; |
|---|
| 472 | if ~isempty(j2_series_Civ1) |
|---|
| 473 | j2=j2_series_Civ1(ifield); |
|---|
| 474 | end |
|---|
| 475 | if strcmp(Param.ActionInput.ListCompareMode,'displacement') |
|---|
| 476 | Data.Civ1_Time=Time(i2+1,j2+1);% the Time is the Time of the second image |
|---|
| 477 | Data.Civ1_Dt=1;% Time interval is 1, to yield displacement instead of velocity=displacement/Dt at reading |
|---|
| [1097] | 478 | else |
|---|
| [1169] | 479 | Data.Civ1_Time=(Time(i2+1,j2+1)+Time(i1+1,j1+1))/2;% the Time is the Time at the middle of the image pair |
|---|
| 480 | Data.Civ1_Dt=Time(i2+1,j2+1)-Time(i1+1,j1+1); |
|---|
| [597] | 481 | end |
|---|
| [1169] | 482 | for ilist=1:length(list_param) |
|---|
| 483 | Data.(Civ1_param{4+ilist})=Param.ActionInput.Civ1.(list_param{ilist}); |
|---|
| 484 | end |
|---|
| 485 | Data.ListGlobalAttribute=[ListGlobalAttribute Civ1_param]; |
|---|
| 486 | Data.CivStage=1; |
|---|
| 487 | |
|---|
| [598] | 488 | % set the list of variables |
|---|
| [1144] | 489 | Data.ListVarName={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_FF'};% cell array containing the names of the fields to record |
|---|
| [598] | 490 | Data.VarDimName={'nb_vec_1','nb_vec_1','nb_vec_1','nb_vec_1','nb_vec_1','nb_vec_1'}; |
|---|
| 491 | Data.VarAttribute{1}.Role='coord_x'; |
|---|
| 492 | Data.VarAttribute{2}.Role='coord_y'; |
|---|
| 493 | Data.VarAttribute{3}.Role='vector_x'; |
|---|
| 494 | Data.VarAttribute{4}.Role='vector_y'; |
|---|
| [1144] | 495 | Data.VarAttribute{5}.Role='ancillary'; |
|---|
| 496 | Data.VarAttribute{6}.Role='errorflag'; |
|---|
| [1164] | 497 | |
|---|
| [1010] | 498 | % case of mask |
|---|
| [856] | 499 | if par_civ1.CheckMask&&~isempty(par_civ1.Mask) |
|---|
| [1163] | 500 | [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ1.Mask); |
|---|
| 501 | j1=1; |
|---|
| 502 | if ~isempty(j1_series_Civ1) |
|---|
| 503 | j1=j1_series_Civ1(ifield); |
|---|
| 504 | end |
|---|
| [1183] | 505 | if ~isempty(i2_series_Civ1)&& ~isequal(i1_series_Civ1,i2_series_Civ1)% case of volume,masks act on different j levels |
|---|
| [1163] | 506 | maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',j1); |
|---|
| 507 | elseif isfield(par_civ1,'NbSlice') |
|---|
| [1010] | 508 | i1_mask=mod(i1-1,par_civ1.NbSlice)+1; |
|---|
| 509 | maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',i1_mask); |
|---|
| [1164] | 510 | if strcmp(Param.ActionInput.PairIndices.ListPairMode,'series(Di)')% case of volume, mask index refers to j index |
|---|
| 511 | par_civ1.NbSlice_j=par_civ1.NbSlice; |
|---|
| 512 | end |
|---|
| [1165] | 513 | else |
|---|
| 514 | maskname=Param.ActionInput.Civ1.Mask; |
|---|
| [1010] | 515 | end |
|---|
| [1165] | 516 | if strcmp(maskoldname,maskname)% mask exist, not already read in civ1 |
|---|
| 517 | par_civ1.Mask=mask; %use mask already opened |
|---|
| 518 | else |
|---|
| 519 | if ~isempty(regexp(maskname,'(^http://)|(^https://)', 'once'))|| exist(maskname,'file') |
|---|
| 520 | try |
|---|
| 521 | par_civ1.Mask=imread(maskname);%update the mask, an store it for future use |
|---|
| 522 | catch ME |
|---|
| 523 | if ~isempty(ME.message) |
|---|
| 524 | errormsg=['error reading input image: ' ME.message]; |
|---|
| 525 | disp_uvmat('ERROR',errormsg,checkrun) |
|---|
| 526 | return |
|---|
| 527 | end |
|---|
| [861] | 528 | end |
|---|
| [1165] | 529 | else |
|---|
| 530 | par_civ1.Mask=[]; |
|---|
| [861] | 531 | end |
|---|
| [1165] | 532 | mask=par_civ1.Mask; |
|---|
| 533 | maskoldname=maskname; |
|---|
| [856] | 534 | end |
|---|
| 535 | end |
|---|
| [1176] | 536 | |
|---|
| [1163] | 537 | % case of input grid |
|---|
| 538 | if par_civ1.CheckGrid &&~isempty(par_civ1.Grid) |
|---|
| 539 | GridData=nc2struct(Param.ActionInput.Civ1.Grid); |
|---|
| 540 | par_civ1.Grid=GridData.Grid; |
|---|
| 541 | par_civ1.CorrBoxSize=GridData.CorrBox; |
|---|
| [597] | 542 | end |
|---|
| [1164] | 543 | |
|---|
| 544 | % caluclate velocity data |
|---|
| [1163] | 545 | [Data.Civ1_X,Data.Civ1_Y,Data.Civ1_U,Data.Civ1_V,Data.Civ1_C,Data.Civ1_FF, result_conv, errormsg] = civ (par_civ1); |
|---|
| 546 | if ~isempty(errormsg) |
|---|
| 547 | disp_uvmat('ERROR',errormsg,checkrun) |
|---|
| 548 | return |
|---|
| 549 | end |
|---|
| [597] | 550 | end |
|---|
| 551 | |
|---|
| [1169] | 552 | |
|---|
| [598] | 553 | %% Fix1 |
|---|
| 554 | if isfield (Param.ActionInput,'Fix1') |
|---|
| [1143] | 555 | disp('detect_false1 started') |
|---|
| [822] | 556 | if ~isfield (Param.ActionInput,'Civ1')% if we use existing Civ1, remove previous data beyond Civ1 |
|---|
| 557 | Fix1_attr=find(strcmp('Fix1',Data.ListGlobalAttribute)); |
|---|
| 558 | Data.ListGlobalAttribute(Fix1_attr)=[]; |
|---|
| 559 | for ilist=1:numel(Fix1_attr) |
|---|
| 560 | Data=rmfield(Data,Data.ListGlobalAttribute{Fix1_attr(ilist)}); |
|---|
| 561 | end |
|---|
| [859] | 562 | end |
|---|
| [852] | 563 | list_param=fieldnames(Param.ActionInput.Fix1)'; |
|---|
| 564 | Fix1_param=regexprep(list_param,'^.+','Fix1_$0');% insert 'Fix1_' before each string in ListFixParam |
|---|
| [859] | 565 | %indicate the values of all the global attributes in the output data |
|---|
| [852] | 566 | for ilist=1:length(list_param) |
|---|
| 567 | Data.(Fix1_param{ilist})=Param.ActionInput.Fix1.(list_param{ilist}); |
|---|
| [598] | 568 | end |
|---|
| [852] | 569 | Data.ListGlobalAttribute=[Data.ListGlobalAttribute Fix1_param]; |
|---|
| [1144] | 570 | Data.Civ1_FF=uint8(detect_false(Param.ActionInput.Fix1,Data.Civ1_C,Data.Civ1_U,Data.Civ1_V,Data.Civ1_FF)); |
|---|
| [859] | 571 | Data.CivStage=2; |
|---|
| [597] | 572 | end |
|---|
| [598] | 573 | %% Patch1 |
|---|
| [1169] | 574 | if Param.ActionInput.CheckPatch1 && isfield (Param.ActionInput,'Patch1') |
|---|
| [896] | 575 | disp('patch1 started') |
|---|
| [1169] | 576 | tstart_patch1=tic; |
|---|
| 577 | |
|---|
| [855] | 578 | % record the processing parameters of Patch1 as global attributes in the result nc file |
|---|
| [852] | 579 | list_param=fieldnames(Param.ActionInput.Patch1)'; |
|---|
| [855] | 580 | list_param(strcmp('TestPatch1',list_param))=[];% remove 'TestPatch1' from the list of parameters |
|---|
| 581 | Patch1_param=regexprep(list_param,'^.+','Patch1_$0');% insert 'Patch1_' before each parameter name |
|---|
| [852] | 582 | for ilist=1:length(list_param) |
|---|
| 583 | Data.(Patch1_param{ilist})=Param.ActionInput.Patch1.(list_param{ilist}); |
|---|
| 584 | end |
|---|
| [855] | 585 | Data.CivStage=3;% record the new state of processing |
|---|
| [852] | 586 | Data.ListGlobalAttribute=[Data.ListGlobalAttribute Patch1_param]; |
|---|
| [598] | 587 | |
|---|
| [855] | 588 | % list the variables to record |
|---|
| [598] | 589 | nbvar=length(Data.ListVarName); |
|---|
| 590 | Data.ListVarName=[Data.ListVarName {'Civ1_U_smooth','Civ1_V_smooth','Civ1_SubRange','Civ1_NbCentres','Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps'}]; |
|---|
| 591 | Data.VarDimName=[Data.VarDimName {'nb_vec_1','nb_vec_1',{'nb_coord','nb_bounds','nb_subdomain_1'},'nb_subdomain_1',... |
|---|
| 592 | {'nb_tps_1','nb_coord','nb_subdomain_1'},{'nb_tps_1','nb_subdomain_1'},{'nb_tps_1','nb_subdomain_1'}}]; |
|---|
| 593 | Data.VarAttribute{nbvar+1}.Role='vector_x'; |
|---|
| 594 | Data.VarAttribute{nbvar+2}.Role='vector_y'; |
|---|
| 595 | Data.VarAttribute{nbvar+5}.Role='coord_tps'; |
|---|
| 596 | Data.VarAttribute{nbvar+6}.Role='vector_x'; |
|---|
| 597 | Data.VarAttribute{nbvar+7}.Role='vector_y'; |
|---|
| [855] | 598 | Data.Civ1_U_smooth=Data.Civ1_U; % zeros(size(Data.Civ1_X)); |
|---|
| 599 | Data.Civ1_V_smooth=Data.Civ1_V; %zeros(size(Data.Civ1_X)); |
|---|
| [598] | 600 | if isfield(Data,'Civ1_FF') |
|---|
| 601 | ind_good=find(Data.Civ1_FF==0); |
|---|
| [597] | 602 | else |
|---|
| [598] | 603 | ind_good=1:numel(Data.Civ1_X); |
|---|
| [597] | 604 | end |
|---|
| [1115] | 605 | if isempty(ind_good) |
|---|
| [1169] | 606 | disp_uvmat('ERROR','all vectors of civ1 are bad, check input parameters' ,checkrun) |
|---|
| 607 | return |
|---|
| [1115] | 608 | end |
|---|
| [1169] | 609 | |
|---|
| [859] | 610 | % perform Patch calculation using the UVMAT fct 'filter_tps' |
|---|
| [1163] | 611 | [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,~,Ures, Vres,~,FFres]=... |
|---|
| [598] | 612 | 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); |
|---|
| [949] | 613 | Data.Civ1_U_smooth(ind_good)=Ures;% take the interpolated (smoothed) velocity values for good vectors, keep civ1 data for the other |
|---|
| [598] | 614 | Data.Civ1_V_smooth(ind_good)=Vres; |
|---|
| [1155] | 615 | Data.Civ1_FF(ind_good)=uint8(4*FFres);%set FF to value =4 for vectors eliminated by filter_tps |
|---|
| [1131] | 616 | time_patch1=toc(tstart_patch1); |
|---|
| [896] | 617 | disp('patch1 performed') |
|---|
| [597] | 618 | end |
|---|
| 619 | |
|---|
| [598] | 620 | %% Civ2 |
|---|
| 621 | if isfield (Param.ActionInput,'Civ2') |
|---|
| [896] | 622 | disp('civ2 started') |
|---|
| [1131] | 623 | tstart_civ2=tic; |
|---|
| [598] | 624 | par_civ2=Param.ActionInput.Civ2; |
|---|
| [1169] | 625 | % if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B) |
|---|
| 626 | par_civ2.ImageA=[]; |
|---|
| 627 | par_civ2.ImageB=[]; |
|---|
| 628 | if strcmp(Param.ActionInput.ListCompareMode,'displacement') |
|---|
| 629 | ImageName_A_Civ2=Param.ActionInput.RefFile; |
|---|
| [1178] | 630 | elseif CheckRelabel |
|---|
| [1180] | 631 | [RootFile,FrameIndex_A_2]=index2filename(Param.FileSeries,i1_series_Civ2(ifield),j1_series_Civ2(ifield),MaxIndex_j); |
|---|
| 632 | ImageName_A_Civ2=fullfile(RootPath_A,SubDir_A,RootFile); |
|---|
| 633 | else |
|---|
| [1169] | 634 | ImageName_A_Civ2=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_civ2,[],j1_civ2); |
|---|
| [1178] | 635 | FrameIndex_A_2=FrameIndex_A_Civ2(ifield); |
|---|
| [597] | 636 | end |
|---|
| [1178] | 637 | if strcmp(ImageName_A_Civ2,ImageName_A) && isequal(FrameIndex_A,FrameIndex_A_2) |
|---|
| [1169] | 638 | par_civ2.ImageA=par_civ1.ImageA; |
|---|
| 639 | else |
|---|
| [1178] | 640 | [par_civ2.ImageA,VideoObject_A] = read_image(ImageName_A_Civ2,FileType_A,VideoObject_A,FrameIndex_A_2); |
|---|
| [1169] | 641 | end |
|---|
| [1178] | 642 | if CheckRelabel |
|---|
| [1180] | 643 | [RootFile,FrameIndex_B_2]=index2filename(Param.FileSeries,i2_civ2,j2_civ2,MaxIndex_j); |
|---|
| 644 | ImageName_B_Civ2=fullfile(RootPath_B,SubDir_B,RootFile); |
|---|
| 645 | else |
|---|
| 646 | ImageName_B_Civ2=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_civ2,[],j2_civ2); |
|---|
| 647 | FrameIndex_B_2=FrameIndex_B_Civ2(ifield); |
|---|
| [1178] | 648 | end |
|---|
| 649 | if strcmp(ImageName_B_Civ2,ImageName_B) && isequal(FrameIndex_B_2,FrameIndex_B) |
|---|
| [1169] | 650 | par_civ2.ImageB=par_civ1.ImageB; |
|---|
| 651 | else |
|---|
| [1178] | 652 | [par_civ2.ImageB,VideoObject_B] = read_image(ImageName_B_Civ2,FileType_B,VideoObject_B,FrameIndex_B_2); |
|---|
| [1169] | 653 | end |
|---|
| 654 | % [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A_Civ2); |
|---|
| 655 | npy_ima=size(par_civ2.ImageA,1); |
|---|
| 656 | npx_ima=size(par_civ2.ImageA,2); |
|---|
| 657 | if par_civ2.CheckGrid &&~isempty(par_civ2.Grid) % case of input grid |
|---|
| 658 | GridData=nc2struct(Param.ActionInput.Civ2.Grid); |
|---|
| 659 | par_civ2.Grid=GridData.Grid; |
|---|
| 660 | par_civ2.CorrBoxSize=GridData.CorrBox; |
|---|
| 661 | else% automatic grid |
|---|
| 662 | nbinterv_x=floor((npx_ima-1)/par_civ2.Dx); |
|---|
| 663 | gridlength_x=nbinterv_x*par_civ2.Dx; |
|---|
| 664 | minix=ceil((npx_ima-gridlength_x)/2); |
|---|
| 665 | nbinterv_y=floor((npy_ima-1)/par_civ2.Dy); |
|---|
| 666 | gridlength_y=nbinterv_y*par_civ2.Dy; |
|---|
| 667 | miniy=ceil((npy_ima-gridlength_y)/2); |
|---|
| 668 | [GridX,GridY]=meshgrid(minix:par_civ2.Dx:npx_ima-1,miniy:par_civ2.Dy:npy_ima-1); |
|---|
| 669 | par_civ2.Grid=zeros(numel(GridX),2); |
|---|
| 670 | par_civ2.Grid(:,1)=reshape(GridX,[],1); |
|---|
| 671 | par_civ2.Grid(:,2)=reshape(GridY,[],1);% increases with array index |
|---|
| 672 | end |
|---|
| 673 | |
|---|
| [1181] | 674 | % %% user defined image transform |
|---|
| 675 | % if ~isempty(transform_fct) |
|---|
| 676 | % par_civ2 =transform_fct(par_civ2,Param); |
|---|
| 677 | % end |
|---|
| 678 | %% case of image luminosity rescaling |
|---|
| 679 | if par_civ2.CheckRescale &&~isempty(par_civ2.Maxtanh) |
|---|
| 680 | par_civ2.ImageA =par_civ2.Maxtanh*tanh(double(par_civ2.ImageA)/par_civ2.Maxtanh); |
|---|
| 681 | par_civ2.ImageB=par_civ2.Maxtanh*tanh(double(par_civ2.ImageB)/par_civ2.Maxtanh); |
|---|
| [1175] | 682 | end |
|---|
| 683 | |
|---|
| [856] | 684 | % get the guess from patch1 or patch2 (case 'CheckCiv3') |
|---|
| [1169] | 685 | if iview_A==2 && isfield (par_civ2,'CheckCiv3') && strcmp(par_civ2.CheckCiv3,'iterate(civ3)') %get the guess from patch2% Civ1 data read in a netcdf file |
|---|
| 686 | [DataIn,~,~,errormsg]=nc2struct(filecell{1,ifield}); |
|---|
| 687 | if ~isempty(errormsg) |
|---|
| 688 | disp(errormsg) |
|---|
| 689 | return |
|---|
| 690 | end |
|---|
| 691 | SubRange= DataIn.Civ2_SubRange; |
|---|
| 692 | NbCentres=DataIn.Civ2_NbCentres; |
|---|
| 693 | Coord_tps=DataIn.Civ2_Coord_tps; |
|---|
| 694 | U_tps=DataIn.Civ2_U_tps; |
|---|
| 695 | V_tps=DataIn.Civ2_V_tps; |
|---|
| 696 | %CivStage=DataIn.CivStage;%store the current CivStage |
|---|
| 697 | Civ1_Dt=DataIn.Civ2_Dt; |
|---|
| [1163] | 698 | Data=[];%reinitialise the result structure Data |
|---|
| 699 | Data.ListGlobalAttribute={'Conventions','Program','CivStage'}; |
|---|
| 700 | Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes |
|---|
| 701 | Data.Program='civ_series'; |
|---|
| [1169] | 702 | % Data.CivStage=CivStage+1;%update the current civStage after reinitialisation of Data |
|---|
| [859] | 703 | Data.ListVarName={}; |
|---|
| 704 | Data.VarDimName={}; |
|---|
| [1163] | 705 | else % get the guess from patch1 |
|---|
| 706 | SubRange= Data.Civ1_SubRange; |
|---|
| 707 | NbCentres=Data.Civ1_NbCentres; |
|---|
| 708 | Coord_tps=Data.Civ1_Coord_tps; |
|---|
| 709 | U_tps=Data.Civ1_U_tps; |
|---|
| 710 | V_tps=Data.Civ1_V_tps; |
|---|
| 711 | Civ1_Dt=Data.Civ1_Dt; |
|---|
| [1169] | 712 | % Data.CivStage=4; |
|---|
| [851] | 713 | end |
|---|
| [1169] | 714 | Data.CivStage=4; |
|---|
| 715 | % SubRange= par_civ2.Civ1_SubRange; |
|---|
| 716 | % NbCentres=par_civ2.Civ1_NbCentres; |
|---|
| 717 | % Coord_tps=par_civ2.Civ1_Coord_tps; |
|---|
| 718 | % U_tps=par_civ2.Civ1_U_tps; |
|---|
| 719 | % V_tps=par_civ2.Civ1_V_tps; |
|---|
| 720 | % Civ1_Dt=par_civ2.Civ1_Dt; |
|---|
| 721 | % Civ2_Dt=par_civ2.Civ1_Dt; |
|---|
| 722 | % Data.ListVarName={}; |
|---|
| 723 | % Data.VarDimName={}; |
|---|
| 724 | % end |
|---|
| 725 | Shiftx=zeros(size(par_civ2.Grid,1),1);% initialise the shift expected from civ1 data |
|---|
| [856] | 726 | Shifty=zeros(size(par_civ2.Grid,1),1); |
|---|
| 727 | nbval=zeros(size(par_civ2.Grid,1),1);% nbre of interpolated values at each grid point (from the different patch subdomains) |
|---|
| [862] | 728 | if par_civ2.CheckDeformation |
|---|
| 729 | DUDX=zeros(size(par_civ2.Grid,1),1); |
|---|
| 730 | DUDY=zeros(size(par_civ2.Grid,1),1); |
|---|
| 731 | DVDX=zeros(size(par_civ2.Grid,1),1); |
|---|
| 732 | DVDY=zeros(size(par_civ2.Grid,1),1); |
|---|
| 733 | end |
|---|
| [856] | 734 | NbSubDomain=size(SubRange,3); |
|---|
| [761] | 735 | for isub=1:NbSubDomain% for each sub-domain of Patch1 |
|---|
| [851] | 736 | nbvec_sub=NbCentres(isub);% nbre of Civ vectors in the subdomain |
|---|
| 737 | ind_sel=find(par_civ2.Grid(:,1)>=SubRange(1,1,isub) & par_civ2.Grid(:,1)<=SubRange(1,2,isub) &... |
|---|
| [862] | 738 | par_civ2.Grid(:,2)>=SubRange(2,1,isub) & par_civ2.Grid(:,2)<=SubRange(2,2,isub));% grid points in the subdomain |
|---|
| [859] | 739 | if ~isempty(ind_sel) |
|---|
| [862] | 740 | epoints = par_civ2.Grid(ind_sel,:);% coordinates of interpolation sites (measurement grids) |
|---|
| [859] | 741 | ctrs=Coord_tps(1:nbvec_sub,:,isub) ;%(=initial points) ctrs |
|---|
| [862] | 742 | EM = tps_eval(epoints,ctrs);% thin plate spline (tps) coefficient |
|---|
| [1163] | 743 | CentreX=(SubRange(1,1,isub)+SubRange(1,2,isub))/2; %x posiion of the subdomain center |
|---|
| 744 | CentreY=(SubRange(2,1,isub)+SubRange(2,2,isub))/2; %y posiion of the subdomain center |
|---|
| 745 | xwidth=(SubRange(1,2,isub)-SubRange(1,1,isub))/pi; |
|---|
| 746 | ywidth=(SubRange(2,2,isub)-SubRange(2,1,isub))/pi; |
|---|
| 747 | x_dist=(epoints(:,1)-CentreX)/xwidth; |
|---|
| 748 | y_dist=(epoints(:,2)-CentreY)/ywidth; |
|---|
| 749 | weight=cos(x_dist).*cos(y_dist);%weighting fct =1 at the rectangle center and 0 at edge |
|---|
| 750 | nbval(ind_sel)=nbval(ind_sel)+weight;% records the number of values for each interpolation point (in case of subdomain overlap) |
|---|
| 751 | Shiftx(ind_sel)=Shiftx(ind_sel)+weight.*(EM*U_tps(1:nbvec_sub+3,isub));%velocity shift estimated by tps from civ1 |
|---|
| 752 | Shifty(ind_sel)=Shifty(ind_sel)+weight.*(EM*V_tps(1:nbvec_sub+3,isub)); |
|---|
| [859] | 753 | if par_civ2.CheckDeformation |
|---|
| 754 | [EMDX,EMDY] = tps_eval_dxy(epoints,ctrs);%2D matrix of distances between extrapolation points epoints and spline centres (=site points) ctrs |
|---|
| [1163] | 755 | DUDX(ind_sel)=DUDX(ind_sel)+weight.*(EMDX*U_tps(1:nbvec_sub+3,isub)); |
|---|
| 756 | DUDY(ind_sel)=DUDY(ind_sel)+weight.*(EMDY*U_tps(1:nbvec_sub+3,isub)); |
|---|
| 757 | DVDX(ind_sel)=DVDX(ind_sel)+weight.*(EMDX*V_tps(1:nbvec_sub+3,isub)); |
|---|
| 758 | DVDY(ind_sel)=DVDY(ind_sel)+weight.*(EMDY*V_tps(1:nbvec_sub+3,isub)); |
|---|
| [859] | 759 | end |
|---|
| [597] | 760 | end |
|---|
| 761 | end |
|---|
| [1163] | 762 | Shiftx(nbval>0)=Shiftx(nbval>0)./nbval(nbval>0); |
|---|
| 763 | Shifty(nbval>0)=Shifty(nbval>0)./nbval(nbval>0); |
|---|
| [1169] | 764 | |
|---|
| [1163] | 765 | % introduce mask |
|---|
| 766 | if par_civ2.CheckMask && ~isempty(par_civ2.Mask) |
|---|
| 767 | [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ2.Mask); |
|---|
| [1183] | 768 | if ~isempty(i2_series_Civ2) && ~isequal(i1_series_Civ2,i2_series_Civ2) % we do PIV among indices i, at given indices j (volume scan), mask depends on position j |
|---|
| [1163] | 769 | j1=1; |
|---|
| 770 | if ~isempty(j1_series_Civ2) |
|---|
| 771 | j1=j1_series_Civ1(ifield); |
|---|
| 772 | end |
|---|
| 773 | maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',j1); |
|---|
| 774 | elseif isfield(par_civ2,'NbSlice') |
|---|
| 775 | i1=i1_series_Civ2(ifield); |
|---|
| [1010] | 776 | i1_mask=mod(i1-1,par_civ2.NbSlice)+1; |
|---|
| 777 | maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',i1_mask); |
|---|
| [1164] | 778 | if strcmp(Param.ActionInput.PairIndices.ListPairMode,'series(Di)')% case of volume, mask index refers to j index |
|---|
| 779 | par_civ2.NbSlice_j=par_civ2.NbSlice; |
|---|
| 780 | end |
|---|
| [1010] | 781 | else |
|---|
| 782 | maskname=Param.ActionInput.Civ2.Mask; |
|---|
| 783 | end |
|---|
| 784 | if strcmp(maskoldname,maskname)% mask exist, not already read in civ1 |
|---|
| [856] | 785 | par_civ2.Mask=mask; %use mask already opened |
|---|
| 786 | else |
|---|
| [1062] | 787 | if exist(maskname,'file') |
|---|
| [1163] | 788 | try |
|---|
| 789 | par_civ2.Mask=imread(maskname);%update the mask, an store it for future use |
|---|
| 790 | catch ME |
|---|
| 791 | if ~isempty(ME.message) |
|---|
| 792 | errormsg=['error reading input image: ' ME.message]; |
|---|
| 793 | disp_uvmat('ERROR',errormsg,checkrun) |
|---|
| 794 | return |
|---|
| 795 | end |
|---|
| [1010] | 796 | end |
|---|
| [1062] | 797 | else |
|---|
| 798 | par_civ2.Mask=[]; |
|---|
| 799 | end |
|---|
| [856] | 800 | mask=par_civ2.Mask; |
|---|
| [1010] | 801 | maskoldname=maskname; |
|---|
| [856] | 802 | end |
|---|
| [598] | 803 | end |
|---|
| [1169] | 804 | |
|---|
| [1177] | 805 | % case of background image to subtract |
|---|
| 806 | if par_civ2.CheckBackground &&~isempty(par_civ2.Background) |
|---|
| 807 | [RootPath_background,SubDir_background,RootFile_background,~,~,~,~,Ext_background]=fileparts_uvmat(Param.ActionInput.Civ1.Background); |
|---|
| 808 | j1=1; |
|---|
| 809 | if ~isempty(j1_series_Civ1) |
|---|
| 810 | j1=j1_series_Civ1(ifield); |
|---|
| 811 | end |
|---|
| 812 | if ~isempty(i2_series_Civ1)% case of volume,backgrounds act on different j levels |
|---|
| 813 | backgroundname=fullfile_uvmat(RootPath_background,SubDir_background,RootFile_background,Ext_background,'_1',j1); |
|---|
| 814 | elseif isfield(par_civ2,'NbSlice') |
|---|
| 815 | i1_background=mod(i1-1,par_civ2.NbSlice)+1; |
|---|
| 816 | backgroundname=fullfile_uvmat(RootPath_background,SubDir_background,RootFile_background,Ext_background,'_1',i1_background); |
|---|
| 817 | if strcmp(Param.ActionInput.PairIndices.ListPairMode,'series(Di)')% case of volume, background index refers to j index |
|---|
| 818 | par_civ2.NbSlice_j=par_civ2.NbSlice; |
|---|
| 819 | end |
|---|
| 820 | else |
|---|
| 821 | backgroundname=Param.ActionInput.Civ1.Background; |
|---|
| 822 | end |
|---|
| 823 | if strcmp(backgroundoldname,backgroundname)% background exist, not already read in civ2 |
|---|
| 824 | par_civ2.Background=background; %use background already opened |
|---|
| 825 | else |
|---|
| 826 | if ~isempty(regexp(backgroundname,'(^http://)|(^https://)', 'once'))|| exist(backgroundname,'file') |
|---|
| 827 | try |
|---|
| 828 | par_civ2.Background=imread(backgroundname);%update the background, an store it for future use |
|---|
| 829 | catch ME |
|---|
| 830 | if ~isempty(ME.message) |
|---|
| 831 | errormsg=['error reading input image: ' ME.message]; |
|---|
| 832 | disp_uvmat('ERROR',errormsg,checkrun) |
|---|
| 833 | return |
|---|
| 834 | end |
|---|
| 835 | end |
|---|
| 836 | else |
|---|
| 837 | par_civ2.Background=[]; |
|---|
| 838 | end |
|---|
| 839 | background=par_civ2.Background; |
|---|
| 840 | backgroundoldname=backgroundname; |
|---|
| 841 | end |
|---|
| 842 | par_civ2.ImageA=par_civ2.ImageA-par_civ2.Background; |
|---|
| 843 | par_civ2.ImageB=par_civ2.ImageB-par_civ2.Background; |
|---|
| 844 | end |
|---|
| [1169] | 845 | |
|---|
| 846 | if strcmp(Param.ActionInput.ListCompareMode,'displacement') |
|---|
| 847 | Civ1_Dt=1; |
|---|
| 848 | Civ2_Dt=1; |
|---|
| 849 | else |
|---|
| 850 | Civ2_Dt=Time(i2_civ2+1,j2_civ2+1)-Time(i1_civ2+1,j1_civ2+1); |
|---|
| [856] | 851 | end |
|---|
| [1163] | 852 | par_civ2.SearchBoxShift=zeros(size(par_civ2.Grid)); |
|---|
| [1169] | 853 | par_civ2.SearchBoxShift(:,1)=(Civ2_Dt/Civ1_Dt)*Shiftx;%rescale the shift in case of Dt different for Civ1 and Civ2 |
|---|
| [1163] | 854 | par_civ2.SearchBoxShift(:,2)=(Civ2_Dt/Civ1_Dt)*Shifty; |
|---|
| [1169] | 855 | |
|---|
| [598] | 856 | if par_civ2.CheckDeformation |
|---|
| [1163] | 857 | par_civ2.DUDX(nbval>0)=DUDX(nbval>0)./nbval(nbval>0); |
|---|
| 858 | par_civ2.DUDY(nbval>0)=DUDY(nbval>0)./nbval(nbval>0); |
|---|
| 859 | par_civ2.DVDX(nbval>0)=DVDX(nbval>0)./nbval(nbval>0); |
|---|
| 860 | par_civ2.DVDY(nbval>0)=DVDY(nbval>0)./nbval(nbval>0); |
|---|
| [598] | 861 | end |
|---|
| [1169] | 862 | |
|---|
| [862] | 863 | % calculate velocity data (y and v in image indices, reverse to y component) |
|---|
| [1169] | 864 | |
|---|
| [1163] | 865 | [Data.Civ2_X,Data.Civ2_Y,Data.Civ2_U,Data.Civ2_V,Data.Civ2_C,Data.Civ2_FF,~, errormsg] = civ (par_civ2); |
|---|
| [1169] | 866 | |
|---|
| [598] | 867 | list_param=(fieldnames(Param.ActionInput.Civ2))'; |
|---|
| [859] | 868 | list_param(strcmp('TestCiv2',list_param))=[];% remove the parameter TestCiv2 from the list |
|---|
| [606] | 869 | Civ2_param=regexprep(list_param,'^.+','Civ2_$0');% insert 'Civ2_' before each string in list_param |
|---|
| 870 | Civ2_param=[{'Civ2_ImageA','Civ2_ImageB','Civ2_Time','Civ2_Dt'} Civ2_param]; %insert the names of the two input images |
|---|
| [856] | 871 | %indicate the values of all the global attributes in the output data |
|---|
| 872 | if exist('ImageName_A','var') |
|---|
| [859] | 873 | Data.Civ2_ImageA=ImageName_A; |
|---|
| 874 | Data.Civ2_ImageB=ImageName_B; |
|---|
| [997] | 875 | if strcmp(Param.ActionInput.ListCompareMode,'displacement') |
|---|
| [950] | 876 | Data.Civ2_Time=Time(i2_civ2+1,j2_civ2+1);% the Time is the Time of the secodn image |
|---|
| 877 | Data.Civ2_Dt=1;% Time interval is 1, to yield displacement instead of velocity=displacement/Dt at reading |
|---|
| [997] | 878 | else |
|---|
| 879 | Data.Civ2_Time=(Time(i2_civ2+1,j2_civ2+1)+Time(i1_civ2+1,j1_civ2+1))/2; |
|---|
| 880 | Data.Civ2_Dt=Civ2_Dt; |
|---|
| 881 | end |
|---|
| [856] | 882 | end |
|---|
| [598] | 883 | for ilist=1:length(list_param) |
|---|
| [606] | 884 | Data.(Civ2_param{4+ilist})=Param.ActionInput.Civ2.(list_param{ilist}); |
|---|
| [598] | 885 | end |
|---|
| [606] | 886 | Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ2_param]; |
|---|
| [1169] | 887 | |
|---|
| [598] | 888 | nbvar=numel(Data.ListVarName); |
|---|
| [859] | 889 | % define the Civ2 variable (if Civ2 data are not replaced from previous calculation) |
|---|
| 890 | if isempty(find(strcmp('Civ2_X',Data.ListVarName),1)) |
|---|
| [1144] | 891 | Data.ListVarName=[Data.ListVarName {'Civ2_X','Civ2_Y','Civ2_U','Civ2_V','Civ2_C','Civ2_FF'}];% cell array containing the names of the fields to record |
|---|
| [859] | 892 | Data.VarDimName=[Data.VarDimName {'nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2'}]; |
|---|
| 893 | Data.VarAttribute{nbvar+1}.Role='coord_x'; |
|---|
| 894 | Data.VarAttribute{nbvar+2}.Role='coord_y'; |
|---|
| 895 | Data.VarAttribute{nbvar+3}.Role='vector_x'; |
|---|
| 896 | Data.VarAttribute{nbvar+4}.Role='vector_y'; |
|---|
| [1144] | 897 | Data.VarAttribute{nbvar+5}.Role='ancillary'; |
|---|
| 898 | Data.VarAttribute{nbvar+6}.Role='errorflag'; |
|---|
| [859] | 899 | end |
|---|
| [896] | 900 | disp('civ2 performed') |
|---|
| [1131] | 901 | time_civ2=toc(tstart_civ2); |
|---|
| [860] | 902 | elseif ~isfield(Data,'ListVarName') % we start there, using existing Civ2 data |
|---|
| 903 | if exist('ncfile','var') |
|---|
| 904 | CivFile=ncfile; |
|---|
| [1169] | 905 | [Data,~,~,errormsg]=nc2struct(CivFile);%read civ1 and detect_false1 data in the existing netcdf file |
|---|
| [860] | 906 | if ~isempty(errormsg) |
|---|
| 907 | disp_uvmat('ERROR',errormsg,checkrun) |
|---|
| 908 | return |
|---|
| [997] | 909 | end |
|---|
| [860] | 910 | end |
|---|
| [598] | 911 | end |
|---|
| [1169] | 912 | |
|---|
| [598] | 913 | %% Fix2 |
|---|
| [1169] | 914 | if Param.ActionInput.CheckFix2 && isfield (Param.ActionInput,'Fix2')% if Fix2 computation is requested |
|---|
| [1143] | 915 | disp('detect_false2 started') |
|---|
| [856] | 916 | list_param=fieldnames(Param.ActionInput.Fix2)'; |
|---|
| [852] | 917 | Fix2_param=regexprep(list_param,'^.+','Fix2_$0');% insert 'Fix1_' before each string in ListFixParam |
|---|
| [859] | 918 | %indicate the values of all the global attributes in the output data |
|---|
| [852] | 919 | for ilist=1:length(list_param) |
|---|
| 920 | Data.(Fix2_param{ilist})=Param.ActionInput.Fix2.(list_param{ilist}); |
|---|
| [598] | 921 | end |
|---|
| [1163] | 922 | Data.ListGlobalAttribute=[Data.ListGlobalAttribute Fix2_param]; |
|---|
| [1144] | 923 | Data.Civ2_FF=double(detect_false(Param.ActionInput.Fix2,Data.Civ2_C,Data.Civ2_U,Data.Civ2_V,Data.Civ2_FF)); |
|---|
| 924 | Data.CivStage=Data.CivStage+1; |
|---|
| [598] | 925 | end |
|---|
| 926 | |
|---|
| 927 | %% Patch2 |
|---|
| [1169] | 928 | if Param.ActionInput.CheckPatch2 && isfield (Param.ActionInput,'Patch2')% if Patch2 computation is requested |
|---|
| 929 | |
|---|
| [896] | 930 | disp('patch2 started') |
|---|
| [1131] | 931 | tstart_patch2=tic; |
|---|
| [859] | 932 | list_param=fieldnames(Param.ActionInput.Patch2)'; |
|---|
| 933 | list_param(strcmp('TestPatch2',list_param))=[];% remove the parameter TestCiv1 from the list |
|---|
| [852] | 934 | Patch2_param=regexprep(list_param,'^.+','Patch2_$0');% insert 'Fix1_' before each string in ListFixParam |
|---|
| [859] | 935 | %indicate the values of all the global attributes in the output data |
|---|
| [852] | 936 | for ilist=1:length(list_param) |
|---|
| 937 | Data.(Patch2_param{ilist})=Param.ActionInput.Patch2.(list_param{ilist}); |
|---|
| 938 | end |
|---|
| 939 | Data.ListGlobalAttribute=[Data.ListGlobalAttribute Patch2_param]; |
|---|
| 940 | |
|---|
| [598] | 941 | nbvar=length(Data.ListVarName); |
|---|
| 942 | Data.ListVarName=[Data.ListVarName {'Civ2_U_smooth','Civ2_V_smooth','Civ2_SubRange','Civ2_NbCentres','Civ2_Coord_tps','Civ2_U_tps','Civ2_V_tps'}]; |
|---|
| 943 | Data.VarDimName=[Data.VarDimName {'nb_vec_2','nb_vec_2',{'nb_coord','nb_bounds','nb_subdomain_2'},{'nb_subdomain_2'},... |
|---|
| 944 | {'nb_tps_2','nb_coord','nb_subdomain_2'},{'nb_tps_2','nb_subdomain_2'},{'nb_tps_2','nb_subdomain_2'}}]; |
|---|
| 945 | |
|---|
| 946 | Data.VarAttribute{nbvar+1}.Role='vector_x'; |
|---|
| 947 | Data.VarAttribute{nbvar+2}.Role='vector_y'; |
|---|
| 948 | Data.VarAttribute{nbvar+5}.Role='coord_tps'; |
|---|
| 949 | Data.VarAttribute{nbvar+6}.Role='vector_x'; |
|---|
| 950 | Data.VarAttribute{nbvar+7}.Role='vector_y'; |
|---|
| [997] | 951 | Data.Civ2_U_smooth=Data.Civ2_U; |
|---|
| 952 | Data.Civ2_V_smooth=Data.Civ2_V; |
|---|
| [598] | 953 | if isfield(Data,'Civ2_FF') |
|---|
| 954 | ind_good=find(Data.Civ2_FF==0); |
|---|
| [597] | 955 | else |
|---|
| [598] | 956 | ind_good=1:numel(Data.Civ2_X); |
|---|
| [597] | 957 | end |
|---|
| [1169] | 958 | if isempty(ind_good) |
|---|
| 959 | disp_uvmat('ERROR','all vectors of civ2 are bad, check input parameters' ,checkrun) |
|---|
| 960 | return |
|---|
| 961 | end |
|---|
| 962 | |
|---|
| [949] | 963 | [Data.Civ2_SubRange,Data.Civ2_NbCentres,Data.Civ2_Coord_tps,Data.Civ2_U_tps,Data.Civ2_V_tps,tild,Ures,Vres,tild,FFres]=... |
|---|
| [598] | 964 | filter_tps([Data.Civ2_X(ind_good) Data.Civ2_Y(ind_good)],Data.Civ2_U(ind_good),Data.Civ2_V(ind_good),[],Data.Patch2_SubDomainSize,Data.Patch2_FieldSmooth,Data.Patch2_MaxDiff); |
|---|
| 965 | Data.Civ2_U_smooth(ind_good)=Ures; |
|---|
| 966 | Data.Civ2_V_smooth(ind_good)=Vres; |
|---|
| [1154] | 967 | Data.Civ2_FF(ind_good)=uint8(4*FFres); |
|---|
| [598] | 968 | Data.CivStage=Data.CivStage+1; |
|---|
| [1131] | 969 | time_patch2=toc(tstart_patch2); |
|---|
| [896] | 970 | disp('patch2 performed') |
|---|
| [597] | 971 | end |
|---|
| [598] | 972 | |
|---|
| [1169] | 973 | %% write result in a netcdf file |
|---|
| 974 | errormsg=struct2nc(ncfile_out,Data); |
|---|
| 975 | if isempty(errormsg) |
|---|
| 976 | disp([ncfile_out ' written']) |
|---|
| 977 | else |
|---|
| 978 | disp(errormsg) |
|---|
| [598] | 979 | end |
|---|
| [1169] | 980 | time_total=toc(tstart); |
|---|
| 981 | disp(['ellapsed time ' num2str(time_total/60,2) ' minutes']) |
|---|
| 982 | disp(['time civ1 ' num2str(time_civ1,2) ' s']) |
|---|
| 983 | disp(['time patch1 ' num2str(time_patch1,2) ' s']) |
|---|
| 984 | disp(['time civ2 ' num2str(time_civ2,2) ' s']) |
|---|
| 985 | disp(['time patch2 ' num2str(time_patch2,2) ' s']) |
|---|
| 986 | if exist('time_input','var') |
|---|
| 987 | disp(['time image reading ' num2str(time_input,2) ' s']) |
|---|
| 988 | disp(['time other ' num2str((time_total-time_input-time_civ1-time_patch1-time_civ2-time_patch2),2) ' s']) |
|---|
| 989 | end |
|---|
| [597] | 990 | end |
|---|
| 991 | |
|---|
| [1169] | 992 | |
|---|
| 993 | |
|---|
| [598] | 994 | %------------------------------------------------------------------------ |
|---|
| 995 | % --- determine the list of index pairs of processing file |
|---|
| 996 | function [i1_series,i2_series,j1_series,j2_series,check_bounds,NomTypeNc]=... |
|---|
| [635] | 997 | find_pair_indices(str_civ,i_series,j_series,MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j) |
|---|
| [598] | 998 | %------------------------------------------------------------------------ |
|---|
| [610] | 999 | i1_series=i_series;% set of first image indexes |
|---|
| [598] | 1000 | i2_series=i_series; |
|---|
| [819] | 1001 | j1_series=j_series;%ones(size(i_series));% set of first image numbers |
|---|
| 1002 | j2_series=j_series;%ones(size(i_series)); |
|---|
| [610] | 1003 | r=regexp(str_civ,'^\D(?<ind>[i|j])=( -| )(?<num1>\d+)\|(?<num2>\d+)','names'); |
|---|
| [598] | 1004 | if ~isempty(r) |
|---|
| 1005 | mode=['D' r.ind]; |
|---|
| 1006 | ind1=str2num(r.num1); |
|---|
| 1007 | ind2=str2num(r.num2); |
|---|
| 1008 | else |
|---|
| [668] | 1009 | mode='j1-j2'; |
|---|
| [598] | 1010 | r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names'); |
|---|
| 1011 | if ~isempty(r) |
|---|
| 1012 | NomTypeNc='_1ab'; |
|---|
| 1013 | else |
|---|
| 1014 | r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names'); |
|---|
| 1015 | if ~isempty(r) |
|---|
| 1016 | NomTypeNc='_1AB'; |
|---|
| [597] | 1017 | else |
|---|
| [598] | 1018 | r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names'); |
|---|
| 1019 | if ~isempty(r) |
|---|
| 1020 | NomTypeNc='_1_1-2'; |
|---|
| [859] | 1021 | end |
|---|
| [597] | 1022 | end |
|---|
| 1023 | end |
|---|
| [598] | 1024 | if isempty(r) |
|---|
| 1025 | display('wrong pair mode input option') |
|---|
| 1026 | else |
|---|
| [859] | 1027 | ind1=stra2num(r.num1); |
|---|
| 1028 | ind2=stra2num(r.num2); |
|---|
| [598] | 1029 | end |
|---|
| [597] | 1030 | end |
|---|
| [819] | 1031 | switch mode |
|---|
| 1032 | case 'Di' |
|---|
| 1033 | i1_series=i_series-ind1;% set of first image numbers |
|---|
| 1034 | i2_series=i_series+ind2; |
|---|
| 1035 | check_bounds=i1_series<MinIndex_i | i2_series>MaxIndex_i; |
|---|
| 1036 | if isempty(j_series) |
|---|
| 1037 | NomTypeNc='_1-2'; |
|---|
| 1038 | else |
|---|
| 1039 | j1_series=j_series; |
|---|
| 1040 | j2_series=j_series; |
|---|
| 1041 | NomTypeNc='_1-2_1'; |
|---|
| 1042 | end |
|---|
| 1043 | case 'Dj' |
|---|
| 1044 | j1_series=j_series-ind1; |
|---|
| 1045 | j2_series=j_series+ind2; |
|---|
| 1046 | check_bounds=j1_series<MinIndex_j | j2_series>MaxIndex_j; |
|---|
| 1047 | NomTypeNc='_1_1-2'; |
|---|
| 1048 | otherwise %bursts |
|---|
| 1049 | i1_series=i_series(1,:);% do not sweep the j index |
|---|
| 1050 | i2_series=i_series(1,:); |
|---|
| 1051 | j1_series=ind1*ones(1,size(i_series,2));% j index is fixed by pair choice |
|---|
| 1052 | j2_series=ind2*ones(1,size(i_series,2)); |
|---|
| 1053 | check_bounds=zeros(size(i1_series));% no limitations due to min-max indices |
|---|
| [598] | 1054 | end |
|---|
| [597] | 1055 | |
|---|
| [1169] | 1056 | %------------------------------------------------------------------------ |
|---|
| 1057 | % --- set the flag for false vectors |
|---|
| [1163] | 1058 | function FF=detect_false(Param,C,U,V,FFIn) |
|---|
| 1059 | FF=FFIn;%default, good vectors |
|---|
| 1060 | % FF=1, for correlation max at edge, not set in this function |
|---|
| 1061 | % FF=2, for too small correlation |
|---|
| 1062 | % FF=3, for velocity outside bounds |
|---|
| 1063 | % FF=4 for exclusion by difference with the smoothed field, set by call to function filter_tps |
|---|
| [598] | 1064 | |
|---|
| [1163] | 1065 | if isfield (Param,'MinCorr') |
|---|
| 1066 | FF(C<Param.MinCorr & FFIn==0)=2; |
|---|
| 1067 | end |
|---|
| 1068 | if (isfield(Param,'MinVel')&&~isempty(Param.MinVel))||(isfield (Param,'MaxVel')&&~isempty(Param.MaxVel)) |
|---|
| 1069 | Umod= U.*U+V.*V; |
|---|
| 1070 | if isfield (Param,'MinVel')&&~isempty(Param.MinVel) |
|---|
| 1071 | U2Min=Param.MinVel*Param.MinVel; |
|---|
| 1072 | FF(Umod<U2Min & FFIn==0)=3; |
|---|
| 1073 | end |
|---|
| 1074 | if isfield (Param,'MaxVel')&&~isempty(Param.MaxVel) |
|---|
| 1075 | U2Max=Param.MaxVel*Param.MaxVel; |
|---|
| 1076 | FF(Umod>U2Max & FFIn==0)=3; |
|---|
| 1077 | end |
|---|
| 1078 | end |
|---|
| [598] | 1079 | |
|---|
| 1080 | |
|---|
| [1163] | 1081 | |
|---|