| [1163] | 1 | %'test_civ': test the civ fct on a simple shear produced by defomation of the input image |
|---|
| 2 | %------------------------------------------------------------------------ |
|---|
| 3 | % Method: |
|---|
| 4 | %open a netcdf file with civ results. |
|---|
| 5 | |
|---|
| 6 | % function ParamOut=test_patch_tps (Param) |
|---|
| 7 | % |
|---|
| 8 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 9 | % |
|---|
| 10 | %OUTPUT |
|---|
| 11 | % ParamOut: sets input parameters when the function is selected, not activated(input Param.Action.RUN=0),=[] when the function is running |
|---|
| 12 | % |
|---|
| 13 | %INPUT: |
|---|
| 14 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
|---|
| 15 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
|---|
| 16 | % when Param.Action.RUN=0 (as activated when the current Action is selected |
|---|
| 17 | % in series), the function ouput paramOut set the activation of the needed GUI elements |
|---|
| 18 | % |
|---|
| 19 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
|---|
| 20 | % see the current structure Param) |
|---|
| 21 | % .InputTable: cell of input file names, (several lines for multiple input) |
|---|
| 22 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
|---|
| 23 | % .OutputSubDir: name of the subdirectory for data outputs |
|---|
| 24 | % .OutputDirExt: directory extension for data outputs |
|---|
| 25 | % .Action: .ActionName: name of the current activated function |
|---|
| 26 | % .ActionPath: path of the current activated function |
|---|
| 27 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct |
|---|
| 28 | % .RUN =0 for GUI input, =1 for function activation |
|---|
| 29 | % .RunMode='local','background', 'cluster': type of function use |
|---|
| 30 | % |
|---|
| 31 | % .IndexRange: set the file or frame indices on which the action must be performed |
|---|
| 32 | % .InputFields: sub structure describing the input fields withfields |
|---|
| 33 | % .FieldName: name(s) of the field |
|---|
| 34 | % .VelType: velocity type |
|---|
| 35 | |
|---|
| 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 37 | |
|---|
| 38 | %======================================================================= |
|---|
| 39 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
|---|
| 40 | % http://www.legi.grenoble-inp.fr |
|---|
| 41 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr |
|---|
| 42 | % |
|---|
| 43 | % This file is part of the toolbox UVMAT. |
|---|
| 44 | % |
|---|
| 45 | % UVMAT is free software; you can redistribute it and/or modify |
|---|
| 46 | % it under the terms of the GNU General Public License as published |
|---|
| 47 | % by the Free Software Foundation; either version 2 of the license, |
|---|
| 48 | % or (at your option) any later version. |
|---|
| 49 | % |
|---|
| 50 | % UVMAT is distributed in the hope that it will be useful, |
|---|
| 51 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 52 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 53 | % GNU General Public License (see LICENSE.txt) for more details. |
|---|
| 54 | %======================================================================= |
|---|
| 55 | |
|---|
| 56 | function ParamOut=test_civ (Param) |
|---|
| 57 | |
|---|
| 58 | %%%%%%%%%%%%%%%%% INPUT PREPARATION MODE (no RUN) %%%%%%%%%%%%%%%%% |
|---|
| 59 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
|---|
| 60 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
|---|
| 61 | ParamOut.WholeIndexRange='one';% prescribes the file index ranges from min to max (options 'off'/'on'/'one' (single input index), 'off' by default) |
|---|
| 62 | ParamOut.NbSlice='off'; % edit box nbre of slices made active |
|---|
| 63 | ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
|---|
| 64 | ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
|---|
| 65 | ParamOut.FieldTransform = 'off';%can use a transform function |
|---|
| 66 | ParamOut.ProjObject='off';%cannot use projection object(option 'off'/'on', |
|---|
| 67 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
|---|
| 68 | ParamOut.OutputDirExt='.test_subpixel';%set the output dir extension |
|---|
| 69 | ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice |
|---|
| 70 | |
|---|
| 71 | %% root input file(s) and type |
|---|
| 72 | % check the existence of the first file in the series |
|---|
| 73 | first_j=[];% note that the function will propose to cover the whole range of indices |
|---|
| 74 | if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end |
|---|
| 75 | PairString=''; |
|---|
| 76 | if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end |
|---|
| 77 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString); |
|---|
| 78 | FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},... |
|---|
| 79 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2); |
|---|
| 80 | if ~exist(FirstFileName,'file') |
|---|
| 81 | msgbox_uvmat('ERROR',['the input file ' FirstFileName ' does not exist']) |
|---|
| 82 | return |
|---|
| 83 | end |
|---|
| 84 | |
|---|
| 85 | %% check the validity of input file types |
|---|
| 86 | Data=nc2struct(FirstFileName,[]); |
|---|
| 87 | if isfield(Data,'CivStage') |
|---|
| 88 | switch Data.CivStage |
|---|
| 89 | case {1,2,3} |
|---|
| 90 | CivStage='civ1'; |
|---|
| 91 | |
|---|
| 92 | otherwise |
|---|
| 93 | CivStage='civ2'; |
|---|
| 94 | end |
|---|
| 95 | else |
|---|
| 96 | msgbox_uvmat('ERROR','invalid file type input: test_filter_tps proceeds raw civ data') |
|---|
| 97 | return |
|---|
| 98 | end |
|---|
| 99 | |
|---|
| 100 | %% numbers of fields |
|---|
| 101 | incr_j=1;%default |
|---|
| 102 | if isfield(Param.IndexRange,'incr_j')&&~isempty(Param.IndexRange.incr_j) |
|---|
| 103 | incr_j=Param.IndexRange.incr_j; |
|---|
| 104 | end |
|---|
| 105 | % if isempty(first_j)||isempty(last_j) |
|---|
| 106 | % nbfield_j=1; |
|---|
| 107 | % else |
|---|
| 108 | % nbfield_j=numel(first_j:incr_j:last_j);%nb of fields for the j index (bursts or volume slices) |
|---|
| 109 | % end |
|---|
| 110 | first_i=1;last_i=1;incr_i=1;%default |
|---|
| 111 | if isfield(Param.IndexRange,'MinIndex_i'); first_i=Param.IndexRange.MinIndex_i; end |
|---|
| 112 | if isfield(Param.IndexRange,'MaxIndex_i'); last_i=Param.IndexRange.MaxIndex_i; end |
|---|
| 113 | if isfield(Param.IndexRange,'incr_i')&&~isempty(Param.IndexRange.incr_i) |
|---|
| 114 | incr_i=Param.IndexRange.incr_i; |
|---|
| 115 | end |
|---|
| 116 | nbfield_i=numel(first_i:incr_i:last_i);%nb of fields for the i index (bursts or volume slices) |
|---|
| 117 | % nbfield=nbfield_j*nbfield_i; %total number of fields |
|---|
| 118 | |
|---|
| 119 | %% setting of intput parameters |
|---|
| 120 | ListParam={'CivStage';'CorrSmooth';'Civ1_CorrBoxSize'}; |
|---|
| 121 | DefaultValue={CivStage;1;[31 31]}; |
|---|
| 122 | if isfield(Param,'ActionInput') |
|---|
| 123 | ParamIn=Param.ActionInput; |
|---|
| 124 | else |
|---|
| 125 | ParamIn=[]; |
|---|
| 126 | end |
|---|
| 127 | [ParamOut.ActionInput,errormsg] = set_param_input(ListParam,DefaultValue,ParamIn); |
|---|
| 128 | if ~isempty(errormsg) |
|---|
| 129 | msgbox_uvmat('ERROR',errormsg) |
|---|
| 130 | end |
|---|
| 131 | return |
|---|
| 132 | end |
|---|
| 133 | %%%%%%%%%%%%%%%%% STOP HERE FOR PAMETER INPUT MODE %%%%%%%%%%%%%%%%% |
|---|
| 134 | |
|---|
| 135 | %% read input parameters from an xml file if input is a file name (batch mode) |
|---|
| 136 | checkrun=1; |
|---|
| 137 | RUNHandle=[]; |
|---|
| 138 | WaitbarHandle=[]; |
|---|
| 139 | if ischar(Param) |
|---|
| 140 | Param=xml2struct(Param);% read Param as input file (batch case) |
|---|
| 141 | checkrun=0; |
|---|
| 142 | else |
|---|
| 143 | hseries=findobj(allchild(0),'Tag','series'); |
|---|
| 144 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
|---|
| 145 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
|---|
| 146 | end |
|---|
| 147 | |
|---|
| 148 | %% input preparation |
|---|
| 149 | RootPath=Param.InputTable{:,1}; |
|---|
| 150 | RootFile=Param.InputTable{:,3}; |
|---|
| 151 | NomType=Param.InputTable{:,4}; |
|---|
| 152 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
|---|
| 153 | % if ~isempty(hdisp),delete(hdisp),end; |
|---|
| 154 | %%%%%%%%%%%% |
|---|
| 155 | % The cell array filecell is the list of input file names, while |
|---|
| 156 | % filecell{iview,fileindex}: |
|---|
| 157 | % iview: line in the table corresponding to a given file series |
|---|
| 158 | % fileindex: file index within the file series, |
|---|
| 159 | % i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j |
|---|
| 160 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
|---|
| 161 | %%%%%%%%%%%% |
|---|
| 162 | |
|---|
| 163 | %% output path |
|---|
| 164 | |
|---|
| 165 | OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device); |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | %% Prepare the structure of output netcdf file |
|---|
| 169 | DataOut.ListGlobalAttribute={'Conventions','Program','CivStage'}; |
|---|
| 170 | DataOut.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes |
|---|
| 171 | if isfield(Param,'UvmatRevision') |
|---|
| 172 | DataOut.Program=['test_subpixel, uvmat r' Param.UvmatRevision]; |
|---|
| 173 | else |
|---|
| 174 | DataOut.Program='test_subpixel'; |
|---|
| 175 | end |
|---|
| 176 | DataOut.CivStage=1; |
|---|
| 177 | DataOut.CoordUnit='pixel'; |
|---|
| 178 | DataOut.ListVarName={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_FF'}; |
|---|
| 179 | DataOut.VarDimName={'nb_vec','nb_vec','nb_vec','nb_vec','nb_vec','nb_vec'}; |
|---|
| 180 | DataOut.VarAttribute{1}.Role='coord_x'; |
|---|
| 181 | DataOut.VarAttribute{2}.Role='coord_y'; |
|---|
| 182 | DataOut.VarAttribute{3}.Role='vector_x'; |
|---|
| 183 | DataOut.VarAttribute{4}.Role='vector_y'; |
|---|
| 184 | DataOut.VarAttribute{5}.Role='ancillary'; |
|---|
| 185 | DataOut.VarAttribute{6}.Role='errorflag'; |
|---|
| 186 | |
|---|
| 187 | %% MAIN LOOP |
|---|
| 188 | |
|---|
| 189 | Data=read_field(filecell{1,1},'civdata',Param.InputFields); |
|---|
| 190 | |
|---|
| 191 | %% create shifted input image |
|---|
| 192 | |
|---|
| 193 | A=read_image(Data.Civ1_ImageA); |
|---|
| 194 | [npy,npx]=size(A); |
|---|
| 195 | B=zeros(npy,npx); |
|---|
| 196 | for iline=1:npy |
|---|
| 197 | Ashift=interp(double(A(iline,:)),10); |
|---|
| 198 | Ashift=circshift(Ashift,round(200*(iline-(npy/2))/npy)+10); |
|---|
| 199 | Ashift(1:round(200*(iline-(npy/2))/npy)+10)=0; |
|---|
| 200 | B(iline,:)=decimate(Ashift,10); |
|---|
| 201 | end |
|---|
| 202 | B=B+(rand(npy,npx)-0.5).*B; |
|---|
| 203 | par_civ.ImageA=A; |
|---|
| 204 | if isa(A,'uint8') |
|---|
| 205 | par_civ.ImageB=uint8(B); |
|---|
| 206 | BitDepth=8; |
|---|
| 207 | else |
|---|
| 208 | par_civ.ImageB=uint16(B); |
|---|
| 209 | BitDepth=16; |
|---|
| 210 | end |
|---|
| 211 | y=linspace (0.5,npy-0.5,npy); |
|---|
| 212 | |
|---|
| 213 | %% Run civ_series |
|---|
| 214 | %Param.ActionInput.ListCompareMode='PIV'; |
|---|
| 215 | par_civ.CorrBoxSize=Param.ActionInput.Civ1_CorrBoxSize; |
|---|
| 216 | par_civ.SearchRange=[15 5]; |
|---|
| 217 | par_civ.SearchBoxShift=[0 0]; |
|---|
| 218 | par_civ.Dx=Data.Civ1_Dx; |
|---|
| 219 | par_civ.Dy=Data.Civ1_Dy; |
|---|
| 220 | par_civ.Dy=Data.Civ1_Dy; |
|---|
| 221 | par_civ.CorrSmooth=Param.ActionInput.CorrSmooth; |
|---|
| 222 | % par_civ.MinCorr=0; |
|---|
| 223 | % path_series=fileparts(which('series')); |
|---|
| 224 | % addpath(fullfile(path_series,'series')) |
|---|
| 225 | % [DataOut,errormsg,result_conv]= civ_series(Param) |
|---|
| 226 | |
|---|
| 227 | % par_civ: structure of input parameters, with fields: |
|---|
| 228 | % .ImageA: first image for correlation (matrix) |
|---|
| 229 | % .ImageB: second image for correlation(matrix) |
|---|
| 230 | % .CorrBoxSize: 1,2 vector giving the size of the correlation box in x and y |
|---|
| 231 | % .SearchBoxSize: 1,2 vector giving the size of the search box in x and y |
|---|
| 232 | % .SearchBoxShift: 1,2 vector or 2 column matrix (for civ2) giving the shift of the search box in x and y |
|---|
| 233 | % .CorrSmooth: =1 or 2 determines the choice of the sub-pixel determination of the correlation max |
|---|
| 234 | % .ImageWidth: nb of pixels of the image in x |
|---|
| 235 | % .Dx, Dy: mesh for the PIV calculation |
|---|
| 236 | % .Grid: grid giving the PIV calculation points (alternative to .Dx .Dy): centres of the correlation boxes in Image A |
|---|
| 237 | % .Mask: name of a mask file or mask image matrix itself |
|---|
| 238 | % .MinIma: thresholds for image luminosity |
|---|
| 239 | % .MaxIma |
|---|
| 240 | % .CheckDeformation=1 for subpixel interpolation and image deformation (linear transform) |
|---|
| 241 | % .DUDX: matrix of deformation obtained from patch at each grid point |
|---|
| 242 | % .DUDY |
|---|
| 243 | % .DVDX: |
|---|
| 244 | % .DVDY |
|---|
| 245 | |
|---|
| 246 | [DataOut.Civ1_X,DataOut.Civ1_Y,DataOut.Civ1_U,DataOut.Civ1_V,DataOut.Civ1_C,DataOut.Civ1_FF,result_conv,errormsg] = civ (par_civ); |
|---|
| 247 | |
|---|
| 248 | if ~isempty(errormsg) |
|---|
| 249 | disp_uvmat('ERROR',errormsg,checkrun) |
|---|
| 250 | return |
|---|
| 251 | end |
|---|
| 252 | |
|---|
| 253 | Uref=-10*(2*DataOut.Civ1_Y/npy)+10.1; |
|---|
| 254 | Udiff=DataOut.Civ1_U-Uref; |
|---|
| 255 | figure(1) |
|---|
| 256 | clf |
|---|
| 257 | h=histogram(DataOut.Civ1_U,200,'BinLimits',[-10 10]) |
|---|
| 258 | xlabel('U(pixels)') |
|---|
| 259 | grid on |
|---|
| 260 | figure(2) |
|---|
| 261 | clf |
|---|
| 262 | h=histogram(Udiff,'BinLimits',[-1 1]) |
|---|
| 263 | xlabel('Udiff (pixels)') |
|---|
| 264 | grid on |
|---|
| 265 | figure(3) |
|---|
| 266 | clf |
|---|
| 267 | h=histogram(DataOut.Civ1_V,'BinLimits',[-1 1]) |
|---|
| 268 | xlabel('V (pixels)') |
|---|
| 269 | grid on |
|---|
| 270 | OutputFile=fullfile(OutputPath,[Param.OutputSubDir Param.OutputDirExt],[RootFile '_' num2str(Param.IndexRange.first_i) '.nc']) |
|---|
| 271 | errormsg=struct2nc(OutputFile,DataOut) |
|---|
| 272 | |
|---|
| 273 | OutputImageA=fullfile(OutputPath,[Param.OutputSubDir Param.OutputDirExt],[RootFile '_' num2str(Param.IndexRange.first_i) 'a.png']) |
|---|
| 274 | |
|---|
| 275 | OutputImageB=fullfile(OutputPath,[Param.OutputSubDir Param.OutputDirExt],[RootFile '_' num2str(Param.IndexRange.first_i) 'b.png']) |
|---|
| 276 | imwrite(par_civ.ImageA,OutputImageA,'BitDepth',BitDepth);% save the new image |
|---|
| 277 | imwrite(par_civ.ImageB,OutputImageB,'BitDepth',BitDepth); |
|---|
| 278 | % %plot rms difference and proportion of excluded vectors |
|---|
| 279 | % figure(2) |
|---|
| 280 | % clf |
|---|
| 281 | % if CivStage==3% civ1 |
|---|
| 282 | % ref=0.2; %recommanded value for diff rms |
|---|
| 283 | % txt='civ1'; |
|---|
| 284 | % else |
|---|
| 285 | % ref=0.1; |
|---|
| 286 | % txt='civ2'; |
|---|
| 287 | % end |
|---|
| 288 | % semilogx(FieldSmooth,DataOut.Diff_rms,'b+-',FieldSmooth,DataOut.NbExclude,'m+-',FieldSmooth,ref*ones(size(FieldSmooth)),'b--') |
|---|
| 289 | % grid on |
|---|
| 290 | % title( [filecell{1,1} ':' txt]) |
|---|
| 291 | % legend({'rms vel. diff. ' ;' ratio excluded vectors';['recommended diff for' txt]},'Location','northwest') |
|---|
| 292 | % xlabel('smoothing parameter') |
|---|
| 293 | % ylabel('rms (pixels) and proportion of excluded vectors') |
|---|
| 294 | % OutputFig=fullfile(OutputPath,OutputDir,'plot_rms_diff.png'); |
|---|
| 295 | % saveas(2,OutputFig) |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|