[985] | 1 | %'civ2vel_3C': combine velocity fields from two cameras to get three velocity components
|
---|
[839] | 2 | %------------------------------------------------------------------------
|
---|
| 3 | % function ParamOut=civ2vel_3C(Param)
|
---|
| 4 | %
|
---|
| 5 | %OUTPUT
|
---|
| 6 | % ParamOut: sets options in the GUI series.fig needed for the function
|
---|
| 7 | %
|
---|
| 8 | %INPUT:
|
---|
| 9 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
|
---|
| 10 | % In batch mode, Param is the name of the corresponding xml file containing the same information
|
---|
| 11 | % when Param.Action.RUN=0 (as activated when the current Action is selected
|
---|
| 12 | % in series), the function ouput paramOut set the activation of the needed GUI elements
|
---|
| 13 | %
|
---|
| 14 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to
|
---|
| 15 | % see the current structure Param)
|
---|
| 16 | % .InputTable: cell of input file names, (several lines for multiple input)
|
---|
[985] | 17 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
|
---|
[839] | 18 | % .OutputSubDir: name of the subdirectory for data outputs
|
---|
| 19 | % .OutputDirExt: directory extension for data outputs
|
---|
| 20 | % .Action: .ActionName: name of the current activated function
|
---|
| 21 | % .ActionPath: path of the current activated function
|
---|
| 22 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct
|
---|
| 23 | % .RUN =0 for GUI input, =1 for function activation
|
---|
[985] | 24 | % .RunMode='local','background', 'cluster': type of function use
|
---|
| 25 | %
|
---|
[839] | 26 | % .IndexRange: set the file or frame indices on which the action must be performed
|
---|
| 27 | % .InputFields: sub structure describing the input fields withfields
|
---|
| 28 | % .FieldName: name(s) of the field
|
---|
| 29 | % .VelType: velocity type
|
---|
| 30 | % .FieldName_1: name of the second field in case of two input series
|
---|
| 31 | % .VelType_1: velocity type of the second field in case of two input series
|
---|
| 32 | % .Coord_y: name of y coordinate variable
|
---|
| 33 | % .Coord_x: name of x coordinate variable'
|
---|
| 34 |
|
---|
| 35 | %=======================================================================
|
---|
[1107] | 36 | % Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[839] | 37 | % http://www.legi.grenoble-inp.fr
|
---|
| 38 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
| 39 | %
|
---|
| 40 | % This file is part of the toolbox UVMAT.
|
---|
| 41 | %
|
---|
| 42 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 43 | % it under the terms of the GNU General Public License as published
|
---|
| 44 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 45 | % or (at your option) any later version.
|
---|
| 46 | %
|
---|
| 47 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 48 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 49 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 50 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 51 | %=======================================================================
|
---|
| 52 |
|
---|
| 53 | function ParamOut=civ2vel_3C(Param)
|
---|
[985] | 54 | disp('test')
|
---|
[839] | 55 | %% set the input elements needed on the GUI series when the function is selected in the menu ActionName or InputTable refreshed
|
---|
| 56 | if isstruct(Param) && isequal(Param.Action.RUN,0)
|
---|
[863] | 57 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
|
---|
[839] | 58 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
|
---|
| 59 | ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
|
---|
| 60 | ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default)
|
---|
| 61 | ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
|
---|
| 62 | ParamOut.FieldTransform = 'off';%use the phys transform function without choice
|
---|
| 63 | %ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only)
|
---|
[863] | 64 | ParamOut.ProjObject='on';%can use projection object(option 'off'/'on',
|
---|
[839] | 65 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default)
|
---|
| 66 | ParamOut.OutputDirExt='.vel3C';%set the output dir extension
|
---|
[863] | 67 | ParamOut.OutputSubDirMode='two'; % the two first input lines are used to define the output subfolder
|
---|
[839] | 68 | ParamOut.OutputFileMode='NbInput';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
|
---|
[863] | 69 | %check the input files
|
---|
[927] | 70 | ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1)
|
---|
[839] | 71 | first_j=[];
|
---|
[863] | 72 | if size(Param.InputTable,1)<2
|
---|
| 73 | msgbox_uvmat('WARNING',['two or three input file series are needed'])
|
---|
| 74 | end
|
---|
[839] | 75 | if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
|
---|
| 76 | PairString='';
|
---|
| 77 | if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
|
---|
| 78 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
|
---|
| 79 | FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
|
---|
| 80 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
|
---|
| 81 | if ~exist(FirstFileName,'file')
|
---|
| 82 | msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
|
---|
| 83 | elseif isequal(size(Param.InputTable,1),1) && ~isfield(Param,'ProjObject')
|
---|
| 84 | msgbox_uvmat('WARNING','You may need a projection object of type plane for merge_proj')
|
---|
| 85 | end
|
---|
| 86 | return
|
---|
| 87 | end
|
---|
| 88 |
|
---|
| 89 | %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
|
---|
| 90 | ParamOut=[]; %default output
|
---|
| 91 | %% read input parameters from an xml file if input is a file name (batch mode)
|
---|
| 92 | checkrun=1;
|
---|
| 93 | if ischar(Param)
|
---|
| 94 | Param=xml2struct(Param);% read Param as input file (batch case)
|
---|
| 95 | checkrun=0;
|
---|
| 96 | end
|
---|
| 97 | hseries=findobj(allchild(0),'Tag','series');
|
---|
| 98 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
|
---|
| 99 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
|
---|
| 100 |
|
---|
[863] | 101 |
|
---|
| 102 | %% root input file(s) name, type and index series
|
---|
| 103 | RootPath=Param.InputTable(:,1);
|
---|
| 104 | RootFile=Param.InputTable(:,3);
|
---|
| 105 | SubDir=Param.InputTable(:,2);
|
---|
| 106 | NomType=Param.InputTable(:,4);
|
---|
| 107 | FileExt=Param.InputTable(:,5);
|
---|
| 108 | hdisp=disp_uvmat('WAITING...','checking the file series',checkrun);
|
---|
| 109 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
|
---|
| 110 | if ~isempty(hdisp),delete(hdisp),end;
|
---|
| 111 | %%%%%%%%%%%%
|
---|
| 112 | % The cell array filecell is the list of input file names, while
|
---|
| 113 | % filecell{iview,fileindex}:
|
---|
| 114 | % iview: line in the table corresponding to a given file series
|
---|
| 115 | % fileindex: file index within the file series,
|
---|
| 116 | % 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
|
---|
| 117 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
|
---|
| 118 | %%%%%%%%%%%%
|
---|
| 119 | NbView=numel(i1_series);%number of input file series (lines in InputTable)
|
---|
| 120 | NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
|
---|
| 121 | NbField_i=size(i1_series{1},2); %nb of fields for the i index
|
---|
| 122 | NbField=NbField_j*NbField_i; %total number of fields
|
---|
| 123 |
|
---|
[839] | 124 | %% define the directory for result file (with path=RootPath{1})
|
---|
| 125 | OutputDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
|
---|
[985] | 126 | %
|
---|
| 127 | % if ~isfield(Param,'InputFields')
|
---|
| 128 | % Param.InputFields.FieldName='';
|
---|
| 129 | % end
|
---|
[839] | 130 |
|
---|
| 131 | %% calibration data and timing: read the ImaDoc files
|
---|
| 132 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
|
---|
| 133 | if size(time,1)>1
|
---|
| 134 | diff_time=max(max(diff(time)));
|
---|
[863] | 135 | if diff_time>0
|
---|
[839] | 136 | disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time) ': the mean time is chosen in result'],checkrun)
|
---|
[863] | 137 | end
|
---|
[839] | 138 | end
|
---|
| 139 | if ~isempty(errormsg)
|
---|
| 140 | disp_uvmat('WARNING',errormsg,checkrun)
|
---|
| 141 | end
|
---|
[863] | 142 | time=mean(time,1); %averaged time taken for the merged field
|
---|
[839] | 143 | if isfield(XmlData{1},'GeometryCalib')
|
---|
[863] | 144 | tsaiA=XmlData{1}.GeometryCalib;
|
---|
| 145 | else
|
---|
| 146 | disp_uvmat('ERROR','no geometric calibration available for image A',checkrun)
|
---|
| 147 | return
|
---|
| 148 | end
|
---|
| 149 | if isfield(XmlData{2},'GeometryCalib')
|
---|
| 150 | tsaiB=XmlData{2}.GeometryCalib;
|
---|
| 151 | else
|
---|
| 152 | disp_uvmat('ERROR','no geometric calibration available for image B',checkrun)
|
---|
| 153 | return
|
---|
| 154 | end
|
---|
[839] | 155 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
|
---|
| 156 |
|
---|
[862] | 157 | %% grid of physical positions (given by projection plane)
|
---|
| 158 | if ~Param.CheckObject
|
---|
[863] | 159 | disp_uvmat('ERROR','a projection plane with interpolation is needed',checkrun)
|
---|
| 160 | return
|
---|
[862] | 161 | end
|
---|
[985] | 162 | ObjectData=Param.ProjObject;
|
---|
[863] | 163 | xI=ObjectData.RangeX(1):ObjectData.DX:ObjectData.RangeX(2);
|
---|
| 164 | yI=ObjectData.RangeY(1):ObjectData.DY:ObjectData.RangeY(2);
|
---|
| 165 | [XI,YI]=meshgrid(xI,yI);
|
---|
| 166 | U=zeros(size(XI,1),size(XI,2));
|
---|
| 167 | V=zeros(size(XI,1),size(XI,2));
|
---|
| 168 | W=zeros(size(XI,1),size(XI,2));
|
---|
[862] | 169 |
|
---|
[985] | 170 | %% MAIN LOOP ON FIELDS
|
---|
[863] | 171 | warning off
|
---|
[880] | 172 |
|
---|
[927] | 173 | CheckOverwrite=1;%default
|
---|
| 174 | if isfield(Param,'CheckOverwrite')
|
---|
| 175 | CheckOverwrite=Param.CheckOverwrite;
|
---|
| 176 | end
|
---|
[985] | 177 | for index=1:NbField
|
---|
[927] | 178 |
|
---|
[985] | 179 | update_waitbar(WaitbarHandle,index/NbField)
|
---|
[927] | 180 |
|
---|
[985] | 181 |
|
---|
| 182 |
|
---|
| 183 |
|
---|
| 184 | %% generating the name of the merged field
|
---|
| 185 | i1=i1_series{1}(index);
|
---|
[927] | 186 | if ~isempty(i2_series{end})
|
---|
[985] | 187 | i2=i2_series{end}(index);
|
---|
[927] | 188 | else
|
---|
| 189 | i2=i1;
|
---|
| 190 | end
|
---|
| 191 | j1=1;
|
---|
| 192 | j2=1;
|
---|
| 193 | if ~isempty(j1_series{1})
|
---|
[985] | 194 | j1=j1_series{1}(index);
|
---|
[927] | 195 | if ~isempty(j2_series{end})
|
---|
[985] | 196 | j2=j2_series{end}(index);
|
---|
[927] | 197 | else
|
---|
| 198 | j2=j1;
|
---|
| 199 | end
|
---|
| 200 | end
|
---|
| 201 | OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},'.nc','_1-2',i1,i2,j1,j2);
|
---|
| 202 |
|
---|
[985] | 203 | %%
|
---|
| 204 |
|
---|
| 205 |
|
---|
[839] | 206 | if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
|
---|
| 207 | disp('program stopped by user')
|
---|
| 208 | return
|
---|
| 209 | end
|
---|
| 210 |
|
---|
[985] | 211 | if (~CheckOverwrite && exist(OutputFile,'file'))
|
---|
| 212 | disp('existing output file already exists, skip to next field')
|
---|
| 213 | continue% skip iteration if the mode overwrite is desactivated and the result file already exists
|
---|
| 214 | end
|
---|
| 215 |
|
---|
[839] | 216 | %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
|
---|
| 217 | Data=cell(1,NbView);%initiate the set Data
|
---|
[985] | 218 | timeread=zeros(1,NbView);
|
---|
[864] | 219 |
|
---|
| 220 | %get Xphys,Yphys,Zphys from 1 or 2 stereo folders. Positions are taken
|
---|
| 221 | %at the middle between to time step
|
---|
[985] | 222 | clear ZItemp
|
---|
| 223 | ZItemp=zeros(size(XI,1),size(XI,2),2);
|
---|
| 224 |
|
---|
| 225 | if index==1
|
---|
[927] | 226 | first_img=i1_series{1,1}(1,1); %id of the first image of the series
|
---|
[985] | 227 | end
|
---|
| 228 |
|
---|
| 229 | idtemp=0;
|
---|
| 230 | for indextemp=index:index+1;
|
---|
| 231 | idtemp=idtemp+1;
|
---|
| 232 | if NbView==3 % if there is only 1 stereo folder, extract directly Xphys,Yphys and Zphys
|
---|
| 233 |
|
---|
| 234 |
|
---|
| 235 |
|
---|
| 236 | [Data{3},tild,errormsg] = nc2struct([Param.InputTable{3,1},'/',Param.InputTable{3,2},'/',Param.InputTable{3,3},'_',int2str(first_img+indextemp-1),'.nc']);
|
---|
| 237 |
|
---|
| 238 | if exist('Data{3}.Civ3_FF','var') % FF is present, remove wrong vector
|
---|
| 239 | temp=find(Data{3}.Civ3_FF==0);
|
---|
| 240 | Zphys=Data{3}.Zphys(temp);
|
---|
| 241 | Yphys=Data{3}.Yphys(temp);
|
---|
| 242 | Xphys=Data{3}.Xphys(temp);
|
---|
| 243 | else
|
---|
| 244 | Zphys=Data{3}.Zphys;
|
---|
| 245 | Yphys=Data{3}.Yphys;
|
---|
| 246 | Xphys=Data{3}.Xphys;
|
---|
| 247 | end
|
---|
| 248 |
|
---|
| 249 |
|
---|
| 250 |
|
---|
| 251 | elseif NbView==4 % is there is 2 stereo folders, get global U and V and compute Zphys
|
---|
| 252 |
|
---|
| 253 |
|
---|
| 254 | %test if the seconde camera is the same for both folder
|
---|
| 255 | for i=3:4
|
---|
| 256 | indpt(i)=strfind(Param.InputTable{i,2},'.'); % indice of the "." is the folder name 1
|
---|
| 257 | indline(i)=strfind(Param.InputTable{i,2},'-'); % indice of the "-" is the folder name1
|
---|
| 258 | camname{i}=Param.InputTable{i,2}(indline(i)+1:indpt(i)-1);% extract the second camera name
|
---|
| 259 | end
|
---|
| 260 |
|
---|
| 261 | if strcmp(camname{3},camname{4})==0
|
---|
| 262 | disp_uvmat('ERROR','The 2 stereo folders should have the same camera for the second position',checkrun)
|
---|
| 263 | return
|
---|
| 264 | end
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 |
|
---|
| 268 | [Data{3},tild,errormsg] = nc2struct([Param.InputTable{3,1},'/',Param.InputTable{3,2},'/',Param.InputTable{3,3},'_',int2str(first_img+indextemp-1),'.nc']);
|
---|
[927] | 269 |
|
---|
[985] | 270 | if exist('Data{3}.Civ3_FF','var') % if FF is present, remove wrong vector
|
---|
| 271 | temp=find(Data{3}.Civ3_FF==0);
|
---|
| 272 | Xmid3=Data{3}.Xmid(temp);
|
---|
| 273 | Ymid3=Data{3}.Ymid(temp);
|
---|
| 274 | U3=Data{3}.Uphys(temp);
|
---|
| 275 | V3=Data{3}.Vphys(temp);
|
---|
| 276 | else
|
---|
| 277 | Xmid3=Data{3}.Xmid;
|
---|
| 278 | Ymid3=Data{3}.Ymid;
|
---|
| 279 | U3=Data{3}.Uphys;
|
---|
| 280 | V3=Data{3}.Vphys;
|
---|
[864] | 281 | end
|
---|
[985] | 282 | %temporary gridd of merging the 2 stereos datas
|
---|
| 283 | [xq,yq] = meshgrid(min(Xmid3+(U3)/2):(max(Xmid3+(U3)/2)-min(Xmid3+(U3)/2))/128:max(Xmid3+(U3)/2),min(Ymid3+(V3)/2):(max(Ymid3+(V3)/2)-min(Ymid3+(V3)/2))/128:max(Ymid3+(V3)/2));
|
---|
| 284 |
|
---|
| 285 | %1st folder : interpolate the first camera (Dalsa1) points on the second (common) camera
|
---|
| 286 | %(Dalsa 3)
|
---|
| 287 | x3Q=griddata(Xmid3+(U3)/2,Ymid3+(V3)/2,Xmid3-(U3)/2,xq,yq);
|
---|
| 288 | y3Q=griddata(Xmid3+(U3)/2,Ymid3+(V3)/2,Ymid3-(V3)/2,xq,yq);
|
---|
| 289 |
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | [Data{4},tild,errormsg] = nc2struct([Param.InputTable{4,1},'/',Param.InputTable{4,2},'/',Param.InputTable{4,3},'_',int2str(first_img+indextemp-1),'.nc']);
|
---|
| 293 | if exist('Data{4}.Civ3_FF','var') % if FF is present, remove wrong vector
|
---|
| 294 | temp=find(Data{4}.Civ3_FF==0);
|
---|
| 295 | Xmid4=Data{4}.Xmid(temp);
|
---|
| 296 | Ymid4=Data{4}.Ymid(temp);
|
---|
| 297 | U4=Data{4}.Uphys(temp);
|
---|
| 298 | V4=Data{4}.Vphys(temp);
|
---|
| 299 | else
|
---|
| 300 | Xmid4=Data{4}.Xmid;
|
---|
| 301 | Ymid4=Data{4}.Ymid;
|
---|
| 302 | U4=Data{4}.Uphys;
|
---|
| 303 | V4=Data{4}.Vphys;
|
---|
[981] | 304 | end
|
---|
[864] | 305 |
|
---|
[985] | 306 | %2nd folder :interpolate the first camera (Dalsa2) points on the second (common) camera
|
---|
| 307 | %(Dalsa 3)
|
---|
| 308 | x4Q=griddata(Xmid4+(U4)/2,Ymid4+(V4)/2,Xmid4-(U4)/2,xq,yq);
|
---|
| 309 | y4Q=griddata(Xmid4+(U4)/2,Ymid4+(V4)/2,Ymid4-(V4)/2,xq,yq);
|
---|
| 310 |
|
---|
| 311 | xmid=reshape((x4Q+x3Q)/2,length(xq(:,1)).*length(xq(1,:)),1);
|
---|
| 312 | ymid=reshape((y4Q+y3Q)/2,length(yq(:,1)).*length(yq(1,:)),1);
|
---|
| 313 | u=reshape(x4Q-x3Q,length(xq(:,1)).*length(xq(1,:)),1);
|
---|
| 314 | v=reshape(y4Q-y3Q,length(yq(:,1)).*length(yq(1,:)),1);
|
---|
| 315 |
|
---|
| 316 |
|
---|
| 317 | [Zphys,Xphys,Yphys,error]=shift2z(xmid, ymid, u, v,XmlData); %get Xphy,Yphy and Zphys
|
---|
| 318 | %remove NaN
|
---|
| 319 | tempNaN=isnan(Zphys);tempind=find(tempNaN==1);
|
---|
| 320 | Zphys(tempind)=[];
|
---|
| 321 | Xphys(tempind)=[];
|
---|
| 322 | Yphys(tempind)=[];
|
---|
| 323 | error(tempind)=[];
|
---|
| 324 |
|
---|
[864] | 325 | end
|
---|
[985] | 326 |
|
---|
| 327 | if NbView>2
|
---|
| 328 | ZItemp(:,:,idtemp)=griddata(Xphys,Yphys,Zphys,XI,YI); %interpolation on the choosen gridd
|
---|
| 329 | end
|
---|
| 330 |
|
---|
| 331 | end
|
---|
| 332 | ZI=mean(ZItemp,3); %mean between two the two time step
|
---|
[878] | 333 | Vtest=ZItemp(:,:,2)-ZItemp(:,:,1);
|
---|
[864] | 334 |
|
---|
[863] | 335 | [Xa,Ya]=px_XYZ(XmlData{1}.GeometryCalib,XI,YI,ZI);% set of image coordinates on view a
|
---|
| 336 | [Xb,Yb]=px_XYZ(XmlData{2}.GeometryCalib,XI,YI,ZI);% set of image coordinates on view b
|
---|
| 337 |
|
---|
[985] | 338 |
|
---|
[863] | 339 | for iview=1:2
|
---|
[985] | 340 | %% reading input file(s)
|
---|
| 341 | [Data{iview},tild,errormsg]=read_civdata(filecell{iview,index},{'vec(U,V)'},'*');
|
---|
[839] | 342 | if ~isempty(errormsg)
|
---|
| 343 | disp_uvmat('ERROR',['ERROR in civ2vel_3C/read_field/' errormsg],checkrun)
|
---|
| 344 | return
|
---|
| 345 | end
|
---|
| 346 | % get the time defined in the current file if not already defined from the xml file
|
---|
[863] | 347 | if isfield(Data{iview},'Time')&& isequal(Data{iview}.Time,Data{1}.Time)
|
---|
| 348 | Time=Data{iview}.Time;
|
---|
| 349 | else
|
---|
| 350 | disp_uvmat('ERROR','Time undefined or not synchronous',checkrun)
|
---|
| 351 | return
|
---|
[839] | 352 | end
|
---|
[863] | 353 | if isfield(Data{iview},'Dt')&& isequal(Data{iview}.Dt,Data{1}.Dt)
|
---|
| 354 | Dt=Data{iview}.Dt;
|
---|
| 355 | else
|
---|
| 356 | disp_uvmat('ERROR','Dt undefined or not synchronous',checkrun)
|
---|
| 357 | return
|
---|
[839] | 358 | end
|
---|
| 359 | end
|
---|
[993] | 360 | %remove wrong vector
|
---|
| 361 | if isfield(Data{1},'FF')
|
---|
| 362 | temp=find(Data{1}.FF==0);
|
---|
| 363 | X1=Data{1}.X(temp);
|
---|
| 364 | Y1=Data{1}.Y(temp);
|
---|
| 365 | U1=Data{1}.U(temp);
|
---|
| 366 | V1=Data{1}.V(temp);
|
---|
| 367 | else
|
---|
| 368 | X1=Data{1}.X;
|
---|
| 369 | Y1=Data{1}.Y;
|
---|
| 370 | U1=Data{1}.U;
|
---|
| 371 | V1=Data{1}.V;
|
---|
| 372 | end
|
---|
[864] | 373 | Ua=griddata(X1,Y1,U1,Xa,Ya);
|
---|
| 374 | Va=griddata(X1,Y1,V1,Xa,Ya);
|
---|
[993] | 375 | [Ua,Va,Xa,Ya]=Ud2U(XmlData{1}.GeometryCalib,Xa,Ya,Ua,Va); % convert Xd data to X
|
---|
[878] | 376 | [A]=get_coeff(XmlData{1}.GeometryCalib,Xa,Ya,XI,YI,ZI); %get coef A~
|
---|
[864] | 377 |
|
---|
[993] | 378 | %remove wrong vector
|
---|
| 379 | if isfield(Data{1},'FF')
|
---|
| 380 | temp=find(Data{2}.FF==0);
|
---|
| 381 | X2=Data{2}.X(temp);
|
---|
| 382 | Y2=Data{2}.Y(temp);
|
---|
| 383 | U2=Data{2}.U(temp);
|
---|
| 384 | V2=Data{2}.V(temp);
|
---|
| 385 | else
|
---|
| 386 | X2=Data{2}.X;
|
---|
| 387 | Y2=Data{2}.Y;
|
---|
| 388 | U2=Data{2}.U;
|
---|
| 389 | V2=Data{2}.V;
|
---|
| 390 | end
|
---|
[864] | 391 | Ub=griddata(X2,Y2,U2,Xb,Yb);
|
---|
| 392 | Vb=griddata(X2,Y2,V2,Xb,Yb);
|
---|
[993] | 393 | [Ub,Vb,Xb,Yb]=Ud2U(XmlData{2}.GeometryCalib,Xb,Yb,Ub,Vb); % convert Xd data to X
|
---|
| 394 |
|
---|
[878] | 395 | [B]=get_coeff(XmlData{2}.GeometryCalib,Xb,Yb,XI,YI,ZI); %get coef B~
|
---|
| 396 |
|
---|
[993] | 397 |
|
---|
[878] | 398 | % System to solve
|
---|
[863] | 399 | S=ones(size(XI,1),size(XI,2),3);
|
---|
| 400 | D=ones(size(XI,1),size(XI,2),3,3);
|
---|
[985] | 401 |
|
---|
[863] | 402 | S(:,:,1)=A(:,:,1,1).*Ua+A(:,:,2,1).*Va+B(:,:,1,1).*Ub+B(:,:,2,1).*Vb;
|
---|
| 403 | S(:,:,2)=A(:,:,1,2).*Ua+A(:,:,2,2).*Va+B(:,:,1,2).*Ub+B(:,:,2,2).*Vb;
|
---|
| 404 | S(:,:,3)=A(:,:,1,3).*Ua+A(:,:,2,3).*Va+B(:,:,1,3).*Ub+B(:,:,2,3).*Vb;
|
---|
| 405 | D(:,:,1,1)=A(:,:,1,1).*A(:,:,1,1)+A(:,:,2,1).*A(:,:,2,1)+B(:,:,1,1).*B(:,:,1,1)+B(:,:,2,1).*B(:,:,2,1);
|
---|
| 406 | D(:,:,1,2)=A(:,:,1,1).*A(:,:,1,2)+A(:,:,2,1).*A(:,:,2,2)+B(:,:,1,1).*B(:,:,1,2)+B(:,:,2,1).*B(:,:,2,2);
|
---|
| 407 | D(:,:,1,3)=A(:,:,1,1).*A(:,:,1,3)+A(:,:,2,1).*A(:,:,2,3)+B(:,:,1,1).*B(:,:,1,3)+B(:,:,2,1).*B(:,:,2,3);
|
---|
| 408 | D(:,:,2,1)=A(:,:,1,2).*A(:,:,1,1)+A(:,:,2,2).*A(:,:,2,1)+B(:,:,1,2).*B(:,:,1,1)+B(:,:,2,2).*B(:,:,2,1);
|
---|
| 409 | D(:,:,2,2)=A(:,:,1,2).*A(:,:,1,2)+A(:,:,2,2).*A(:,:,2,2)+B(:,:,1,2).*B(:,:,1,2)+B(:,:,2,2).*B(:,:,2,2);
|
---|
| 410 | D(:,:,2,3)=A(:,:,1,2).*A(:,:,1,3)+A(:,:,2,2).*A(:,:,2,3)+B(:,:,1,2).*B(:,:,1,3)+B(:,:,2,2).*B(:,:,2,3);
|
---|
| 411 | D(:,:,3,1)=A(:,:,1,3).*A(:,:,1,1)+A(:,:,2,3).*A(:,:,2,1)+B(:,:,1,3).*B(:,:,1,1)+B(:,:,2,3).*B(:,:,2,1);
|
---|
| 412 | D(:,:,3,2)=A(:,:,1,3).*A(:,:,1,2)+A(:,:,2,3).*A(:,:,2,2)+B(:,:,1,3).*B(:,:,1,2)+B(:,:,2,3).*B(:,:,2,2);
|
---|
| 413 | D(:,:,3,3)=A(:,:,1,3).*A(:,:,1,3)+A(:,:,2,3).*A(:,:,2,3)+B(:,:,1,3).*B(:,:,1,3)+B(:,:,2,3).*B(:,:,2,3);
|
---|
| 414 | for indj=1:size(XI,1)
|
---|
| 415 | for indi=1:size(XI,2)
|
---|
[878] | 416 | dxyz=(squeeze(D(indj,indi,:,:))*1000)\(squeeze(S(indj,indi,:))*1000); % solving...
|
---|
[863] | 417 | U(indj,indi)=dxyz(1);
|
---|
| 418 | V(indj,indi)=dxyz(2);
|
---|
| 419 | W(indj,indi)=dxyz(3);
|
---|
| 420 | end
|
---|
[985] | 421 | end
|
---|
[863] | 422 | Error=zeros(size(XI,1),size(XI,2),4);
|
---|
| 423 | Error(:,:,1)=A(:,:,1,1).*U+A(:,:,1,2).*V+A(:,:,1,3).*W-Ua;
|
---|
| 424 | Error(:,:,2)=A(:,:,2,1).*U+A(:,:,2,2).*V+A(:,:,2,3).*W-Va;
|
---|
| 425 | Error(:,:,3)=B(:,:,1,1).*U+B(:,:,1,2).*V+B(:,:,1,3).*W-Ub;
|
---|
| 426 | Error(:,:,4)=B(:,:,2,1).*U+B(:,:,2,2).*V+B(:,:,2,3).*W-Vb;
|
---|
| 427 |
|
---|
[985] | 428 |
|
---|
| 429 |
|
---|
| 430 |
|
---|
| 431 |
|
---|
| 432 |
|
---|
[839] | 433 | %% recording the merged field
|
---|
[985] | 434 | if index==1% initiate the structure at first index
|
---|
[863] | 435 | MergeData.ListGlobalAttribute={'Conventions','Time','Dt'};
|
---|
[839] | 436 | MergeData.Conventions='uvmat';
|
---|
[863] | 437 | MergeData.Time=Time;
|
---|
| 438 | MergeData.Dt=Dt;
|
---|
| 439 | MergeData.ListVarName={'coord_x','coord_y','Z','U','V','W','Error'};
|
---|
| 440 | MergeData.VarDimName={'coord_x','coord_y',{'coord_y','coord_x'},{'coord_y','coord_x'}...
|
---|
[985] | 441 | {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'}};
|
---|
[863] | 442 | MergeData.coord_x=xI;
|
---|
| 443 | MergeData.coord_y=yI;
|
---|
| 444 | end
|
---|
| 445 | MergeData.U=U/Dt;
|
---|
| 446 | MergeData.V=V/Dt;
|
---|
| 447 | MergeData.W=W/Dt;
|
---|
[927] | 448 | MergeData.Z=ZI;
|
---|
[878] | 449 |
|
---|
[985] | 450 | % mfx=(XmlData{1}.GeometryCalib.fx_fy(1)+XmlData{2}.GeometryCalib.fx_fy(1))/2;
|
---|
| 451 | % mfy=(XmlData{1}.GeometryCalib.fx_fy(2)+XmlData{2}.GeometryCalib.fx_fy(2))/2;
|
---|
[927] | 452 | MergeData.Error=0.5*sqrt(sum(Error.^2,3));
|
---|
[863] | 453 | errormsg=struct2nc(OutputFile,MergeData);%save result file
|
---|
| 454 | if isempty(errormsg)
|
---|
| 455 | disp(['output file ' OutputFile ' written'])
|
---|
| 456 | else
|
---|
| 457 | disp(errormsg)
|
---|
| 458 | end
|
---|
[839] | 459 | end
|
---|
| 460 |
|
---|
| 461 |
|
---|
[878] | 462 | function [A]=get_coeff(Calib,X,Y,x,y,z) % compute A~ coefficients
|
---|
[863] | 463 | R=(Calib.R)';%rotation matrix
|
---|
| 464 | T_z=Calib.Tx_Ty_Tz(3);
|
---|
| 465 | T=R(7)*x+R(8)*y+R(9)*z+T_z;
|
---|
[878] | 466 |
|
---|
[863] | 467 | A(:,:,1,1)=(R(1)-R(7)*X)./T;
|
---|
| 468 | A(:,:,1,2)=(R(2)-R(8)*X)./T;
|
---|
| 469 | A(:,:,1,3)=(R(3)-R(9)*X)./T;
|
---|
| 470 | A(:,:,2,1)=(R(4)-R(7)*Y)./T;
|
---|
| 471 | A(:,:,2,2)=(R(5)-R(8)*Y)./T;
|
---|
| 472 | A(:,:,2,3)=(R(6)-R(9)*Y)./T;
|
---|
[839] | 473 |
|
---|
[985] | 474 | function [U,V,X,Y]=Ud2U(Calib,Xd,Yd,Ud,Vd) % convert Xd to X and Ud to U
|
---|
| 475 |
|
---|
[878] | 476 | X1d=Xd-Ud/2;
|
---|
| 477 | X2d=Xd+Ud/2;
|
---|
| 478 | Y1d=Yd-Vd/2;
|
---|
| 479 | Y2d=Yd+Vd/2;
|
---|
[839] | 480 |
|
---|
[878] | 481 | X1=(X1d-Calib.Cx_Cy(1))./Calib.fx_fy(1).*(1 + Calib.kc.*Calib.fx_fy(1).^(-2).*(X1d-Calib.Cx_Cy(1)).^2 + Calib.kc.*Calib.fx_fy(2).^(-2).*(Y1d-Calib.Cx_Cy(2)).^2 ).^(-1);
|
---|
| 482 | X2=(X2d-Calib.Cx_Cy(1))./Calib.fx_fy(1).*(1 + Calib.kc.*Calib.fx_fy(1).^(-2).*(X2d-Calib.Cx_Cy(1)).^2 + Calib.kc.*Calib.fx_fy(2).^(-2).*(Y2d-Calib.Cx_Cy(2)).^2 ).^(-1);
|
---|
| 483 | Y1=(Y1d-Calib.Cx_Cy(2))./Calib.fx_fy(2).*(1 + Calib.kc.*Calib.fx_fy(1).^(-2).*(X1d-Calib.Cx_Cy(1)).^2 + Calib.kc.*Calib.fx_fy(2).^(-2).*(Y1d-Calib.Cx_Cy(2)).^2 ).^(-1);
|
---|
| 484 | Y2=(Y2d-Calib.Cx_Cy(2))./Calib.fx_fy(2).*(1 + Calib.kc.*Calib.fx_fy(1).^(-2).*(X2d-Calib.Cx_Cy(1)).^2 + Calib.kc.*Calib.fx_fy(2).^(-2).*(Y2d-Calib.Cx_Cy(2)).^2 ).^(-1);
|
---|
[839] | 485 |
|
---|
[878] | 486 | U=X2-X1;
|
---|
| 487 | V=Y2-Y1;
|
---|
| 488 | X=X1+U/2;
|
---|
| 489 | Y=Y1+V/2;
|
---|
| 490 |
|
---|
| 491 |
|
---|
| 492 |
|
---|
| 493 | function [z,Xphy,Yphy,error]=shift2z(xmid, ymid, u, v,XmlData) % get H from stereo data
|
---|
[864] | 494 | z=0;
|
---|
| 495 | error=0;
|
---|
[839] | 496 |
|
---|
[985] | 497 |
|
---|
[864] | 498 | %% first image
|
---|
| 499 | Calib_A=XmlData{1}.GeometryCalib;
|
---|
| 500 | R=(Calib_A.R)';
|
---|
| 501 | x_a=xmid- u/2;
|
---|
[878] | 502 | y_a=ymid- v/2;
|
---|
[864] | 503 | z_a=R(7)*x_a+R(8)*y_a+Calib_A.Tx_Ty_Tz(1,3);
|
---|
| 504 | Xa=(R(1)*x_a+R(2)*y_a+Calib_A.Tx_Ty_Tz(1,1))./z_a;
|
---|
| 505 | Ya=(R(4)*x_a+R(5)*y_a+Calib_A.Tx_Ty_Tz(1,2))./z_a;
|
---|
[839] | 506 |
|
---|
[864] | 507 | A_1_1=R(1)-R(7)*Xa;
|
---|
| 508 | A_1_2=R(2)-R(8)*Xa;
|
---|
| 509 | A_1_3=R(3)-R(9)*Xa;
|
---|
| 510 | A_2_1=R(4)-R(7)*Ya;
|
---|
| 511 | A_2_2=R(5)-R(8)*Ya;
|
---|
| 512 | A_2_3=R(6)-R(9)*Ya;
|
---|
| 513 | Det=A_1_1.*A_2_2-A_1_2.*A_2_1;
|
---|
| 514 | Dxa=(A_1_2.*A_2_3-A_2_2.*A_1_3)./Det;
|
---|
| 515 | Dya=(A_2_1.*A_1_3-A_1_1.*A_2_3)./Det;
|
---|
| 516 |
|
---|
| 517 | %% second image
|
---|
[878] | 518 | %loading shift angle
|
---|
| 519 |
|
---|
[864] | 520 | Calib_B=XmlData{2}.GeometryCalib;
|
---|
| 521 | R=(Calib_B.R)';
|
---|
[878] | 522 |
|
---|
| 523 |
|
---|
[864] | 524 | x_b=xmid+ u/2;
|
---|
| 525 | y_b=ymid+ v/2;
|
---|
| 526 | z_b=R(7)*x_b+R(8)*y_b+Calib_B.Tx_Ty_Tz(1,3);
|
---|
| 527 | Xb=(R(1)*x_b+R(2)*y_b+Calib_B.Tx_Ty_Tz(1,1))./z_b;
|
---|
| 528 | Yb=(R(4)*x_b+R(5)*y_b+Calib_B.Tx_Ty_Tz(1,2))./z_b;
|
---|
| 529 | B_1_1=R(1)-R(7)*Xb;
|
---|
| 530 | B_1_2=R(2)-R(8)*Xb;
|
---|
| 531 | B_1_3=R(3)-R(9)*Xb;
|
---|
| 532 | B_2_1=R(4)-R(7)*Yb;
|
---|
| 533 | B_2_2=R(5)-R(8)*Yb;
|
---|
| 534 | B_2_3=R(6)-R(9)*Yb;
|
---|
| 535 | Det=B_1_1.*B_2_2-B_1_2.*B_2_1;
|
---|
| 536 | Dxb=(B_1_2.*B_2_3-B_2_2.*B_1_3)./Det;
|
---|
| 537 | Dyb=(B_2_1.*B_1_3-B_1_1.*B_2_3)./Det;
|
---|
| 538 |
|
---|
| 539 | %% result
|
---|
| 540 | Den=(Dxb-Dxa).*(Dxb-Dxa)+(Dyb-Dya).*(Dyb-Dya);
|
---|
[927] | 541 | error=abs(((Dyb-Dya).*(-u)-(Dxb-Dxa).*(-v)))./Den;
|
---|
[878] | 542 | % ex=-error.*(Dyb-Dya);
|
---|
| 543 | % ey=-error.*(Dxb-Dxa);
|
---|
[864] | 544 |
|
---|
[878] | 545 | % z1=-u./(Dxb-Dxa);
|
---|
| 546 | % z2=-v./(Dyb-Dya);
|
---|
| 547 | z=((Dxb-Dxa).*(-u)+(Dyb-Dya).*(-v))./Den;
|
---|
| 548 |
|
---|
[864] | 549 | xnew(1,:)=Dxa.*z+x_a;
|
---|
| 550 | xnew(2,:)=Dxb.*z+x_b;
|
---|
| 551 | ynew(1,:)=Dya.*z+y_a;
|
---|
| 552 | ynew(2,:)=Dyb.*z+y_b;
|
---|
[878] | 553 | Xphy=mean(xnew,1);
|
---|
| 554 | Yphy=mean(ynew,1);
|
---|
[864] | 555 |
|
---|
| 556 |
|
---|
| 557 |
|
---|
[878] | 558 |
|
---|