[695] | 1 | %'phys': transforms image (Unit='pixel') to real world (phys) coordinates using geometric calibration parameters. It acts if the input field contains the tag 'CoordTUnit' with value 'pixel' |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | %%%% Use the general syntax for transform fields %%%% |
---|
| 4 | % OUTPUT: |
---|
| 5 | % DataOut: output field structure |
---|
[810] | 6 | % |
---|
[695] | 7 | %INPUT: |
---|
| 8 | % DataIn: first input field structure |
---|
| 9 | % XmlData: first input parameter structure, |
---|
| 10 | % .GeometryCalib: substructure of the calibration parameters |
---|
| 11 | % DataIn_1: optional second input field structure |
---|
| 12 | % XmlData_1: optional second input parameter structure |
---|
| 13 | % .GeometryCalib: substructure of the calibration parameters |
---|
[810] | 14 | |
---|
| 15 | %======================================================================= |
---|
[1107] | 16 | % Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[810] | 17 | % http://www.legi.grenoble-inp.fr |
---|
| 18 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 19 | % |
---|
| 20 | % This file is part of the toolbox UVMAT. |
---|
| 21 | % |
---|
| 22 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 23 | % it under the terms of the GNU General Public License as published |
---|
| 24 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 25 | % or (at your option) any later version. |
---|
| 26 | % |
---|
| 27 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 28 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 29 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 30 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 31 | %======================================================================= |
---|
| 32 | |
---|
[695] | 33 | function DataOut=phys(DataIn,XmlData,DataIn_1,XmlData_1) |
---|
| 34 | %------------------------------------------------------------------------ |
---|
| 35 | |
---|
| 36 | % A FAIRE: 1- verifier si DataIn est une 'field structure'(.ListVarName'): |
---|
| 37 | % chercher ListVarAttribute, for each field (cell of variables): |
---|
| 38 | % .CoordType: 'phys' or 'px' (default==phys, no transform) |
---|
| 39 | % .scale_factor: =dt (to transform displacement into velocity) default=1 |
---|
| 40 | % .covariance: 'scalar', 'coord', 'D_i': covariant (like velocity), 'D^i': contravariant (like gradient), 'D^jD_i' (like strain tensor) |
---|
| 41 | % (default='coord' if .Role='coord_x,_y..., |
---|
| 42 | % 'D_i' if '.Role='vector_x,...', |
---|
| 43 | % 'scalar', else (thenno change except scale factor) |
---|
| 44 | |
---|
| 45 | DataOut=[]; |
---|
| 46 | DataOut_1=[]; %default second output field |
---|
[753] | 47 | if isfield(DataIn,'Action') && isfield(DataIn.Action,'RUN') && isequal(DataIn.Action.RUN,0) |
---|
[695] | 48 | if isfield(XmlData,'GeometryCalib')&& isfield(XmlData.GeometryCalib,'CoordUnit') |
---|
| 49 | DataOut.CoordUnit=XmlData.GeometryCalib.CoordUnit;% states that the output is in unit defined by GeometryCalib, then erased all projection objects with different units |
---|
| 50 | end |
---|
| 51 | return |
---|
| 52 | end |
---|
| 53 | |
---|
| 54 | %% analyse input and set default output |
---|
| 55 | DataOut=DataIn;%default first output field |
---|
| 56 | if nargin>=2 % nargin =nbre of input variables |
---|
| 57 | if isfield(XmlData,'GeometryCalib') |
---|
| 58 | Calib{1}=XmlData.GeometryCalib; |
---|
| 59 | else |
---|
| 60 | Calib{1}=[]; |
---|
| 61 | end |
---|
| 62 | if nargin>=3 %two input fields |
---|
| 63 | DataOut_1=DataIn_1;%default second output field |
---|
| 64 | if nargin>=4 && isfield(XmlData_1,'GeometryCalib') |
---|
| 65 | Calib{2}=XmlData_1.GeometryCalib; |
---|
| 66 | else |
---|
| 67 | Calib{2}=Calib{1}; |
---|
| 68 | end |
---|
| 69 | end |
---|
| 70 | end |
---|
| 71 | |
---|
| 72 | %% get the z index defining the section plane |
---|
| 73 | if isfield(DataIn,'ZIndex')&&~isempty(DataIn.ZIndex)&&~isnan(DataIn.ZIndex) |
---|
| 74 | ZIndex=DataIn.ZIndex; |
---|
| 75 | else |
---|
| 76 | ZIndex=1; |
---|
| 77 | end |
---|
| 78 | |
---|
| 79 | %% transform first field |
---|
| 80 | iscalar=0;% counter of scalar fields |
---|
[1033] | 81 | checktransform=0; |
---|
[695] | 82 | if ~isempty(Calib{1}) |
---|
[1033] | 83 | if isfield(Calib{1},'CalibrationType')&& isfield(Calib{1},'CoordUnit') && isfield(DataIn,'CoordUnit')&& strcmp(DataIn.CoordUnit,'pixel') |
---|
| 84 | DataOut=phys_1(DataIn,Calib{1},ZIndex);% transform coordinates and velocity components |
---|
| 85 | %case of images or scalar: in case of two input fields, we need to project the transform on the same regular grid |
---|
| 86 | if isfield(DataIn,'A') && isfield(DataIn,'Coord_x') && ~isempty(DataIn.Coord_x) && isfield(DataIn,'Coord_y')&&... |
---|
| 87 | ~isempty(DataIn.Coord_y) && length(DataIn.A)>1 |
---|
| 88 | iscalar=1; |
---|
| 89 | A{1}=DataIn.A; |
---|
| 90 | end |
---|
| 91 | checktransform=1; |
---|
[695] | 92 | end |
---|
| 93 | end |
---|
| 94 | |
---|
| 95 | %% document the selected plane position and angle if relevant |
---|
[1033] | 96 | if checktransform && isfield(Calib{1},'SliceCoord')&&size(Calib{1}.SliceCoord,1)>=ZIndex |
---|
[695] | 97 | DataOut.PlaneCoord=Calib{1}.SliceCoord(ZIndex,:);% transfer the slice position corresponding to index ZIndex |
---|
| 98 | if isfield(Calib{1},'SliceAngle') % transfer the slice rotation angles |
---|
| 99 | if isequal(size(Calib{1}.SliceAngle,1),1)% case of a unique angle |
---|
| 100 | DataOut.PlaneAngle=Calib{1}.SliceAngle; |
---|
| 101 | else % case of multiple planes with different angles: select the plane with index ZIndex |
---|
| 102 | DataOut.PlaneAngle=Calib{1}.SliceAngle(ZIndex,:); |
---|
| 103 | end |
---|
| 104 | end |
---|
| 105 | end |
---|
| 106 | |
---|
| 107 | %% transform second field if relevant |
---|
[1033] | 108 | checktransform_1=0; |
---|
[695] | 109 | if ~isempty(DataOut_1) |
---|
| 110 | if isfield(DataIn_1,'ZIndex') && ~isequal(DataIn_1.ZIndex,ZIndex) |
---|
| 111 | DataOut_1.Txt='different plane indices for the two input fields'; |
---|
| 112 | return |
---|
| 113 | end |
---|
[1033] | 114 | if isfield(Calib{2},'CalibrationType')&&isfield(Calib{2},'CoordUnit') && isfield(DataIn_1,'CoordUnit')&& strcmp(DataIn_1.CoordUnit,'pixel') |
---|
[871] | 115 | DataOut_1=phys_1(DataOut_1,Calib{2},ZIndex); |
---|
[1033] | 116 | if isfield(Calib{1},'SliceCoord') |
---|
| 117 | if ~(isfield(Calib{2},'SliceCoord') && isequal(Calib{2}.SliceCoord,Calib{1}.SliceCoord)) |
---|
| 118 | DataOut_1.Txt='different plane positions for the two input fields'; |
---|
[695] | 119 | return |
---|
| 120 | end |
---|
[1033] | 121 | DataOut_1.PlaneCoord=DataOut.PlaneCoord;% same plane position for the two input fields |
---|
| 122 | if isfield(Calib{1},'SliceAngle') |
---|
| 123 | if ~(isfield(Calib{2},'SliceAngle') && isequal(Calib{2}.SliceAngle,Calib{1}.SliceAngle)) |
---|
| 124 | DataOut_1.Txt='different plane angles for the two input fields'; |
---|
| 125 | return |
---|
| 126 | end |
---|
| 127 | DataOut_1.PlaneAngle=DataOut.PlaneAngle; % same plane angle for the two input fields |
---|
| 128 | end |
---|
[695] | 129 | end |
---|
[1033] | 130 | if isfield(DataIn_1,'A')&&isfield(DataIn_1,'Coord_x')&&~isempty(DataIn_1.Coord_x) && isfield(DataIn_1,'Coord_y')&&... |
---|
| 131 | ~isempty(DataIn_1.Coord_y)&&length(DataIn_1.A)>1 |
---|
| 132 | iscalar=iscalar+1; |
---|
| 133 | Calib{iscalar}=Calib{2}; |
---|
| 134 | A{iscalar}=DataIn_1.A; |
---|
| 135 | end |
---|
| 136 | checktransform_1=1; |
---|
[695] | 137 | end |
---|
| 138 | end |
---|
| 139 | |
---|
| 140 | %% transform the scalar(s) or image(s) |
---|
[1033] | 141 | if checktransform && iscalar~=0 |
---|
[836] | 142 | [A,Coord_x,Coord_y]=phys_ima(A,XmlData,ZIndex);%TODO : introduire interp2_uvmat ds phys_ima |
---|
[695] | 143 | if iscalar==1 && ~isempty(DataOut_1) % case for which only the second field is a scalar |
---|
| 144 | DataOut_1.A=A{1}; |
---|
[782] | 145 | DataOut_1.Coord_x=Coord_x; |
---|
| 146 | DataOut_1.Coord_y=Coord_y; |
---|
[695] | 147 | else |
---|
| 148 | DataOut.A=A{1}; |
---|
[782] | 149 | DataOut.Coord_x=Coord_x; |
---|
| 150 | DataOut.Coord_y=Coord_y; |
---|
[695] | 151 | end |
---|
| 152 | if iscalar==2 |
---|
| 153 | DataOut_1.A=A{2}; |
---|
[782] | 154 | DataOut_1.Coord_x=Coord_x; |
---|
| 155 | DataOut_1.Coord_y=Coord_y; |
---|
[695] | 156 | end |
---|
| 157 | end |
---|
| 158 | |
---|
| 159 | % subtract fields |
---|
| 160 | if ~isempty(DataOut_1) |
---|
[782] | 161 | DataOut=sub_field(DataOut,[],DataOut_1); |
---|
[695] | 162 | end |
---|
| 163 | %------------------------------------------------ |
---|
| 164 | %--- transform a single field |
---|
| 165 | function DataOut=phys_1(Data,Calib,ZIndex) |
---|
| 166 | %------------------------------------------------ |
---|
| 167 | %% set default output |
---|
| 168 | DataOut=Data;%default |
---|
| 169 | DataOut.CoordUnit=Calib.CoordUnit;% the output coord unit is set by the calibration parameters |
---|
| 170 | |
---|
| 171 | %% transform X,Y coordinates for velocity fields (transform of an image or scalar done in phys_ima) |
---|
| 172 | if isfield(Data,'X') &&isfield(Data,'Y')&&~isempty(Data.X) && ~isempty(Data.Y) |
---|
| 173 | [DataOut.X,DataOut.Y]=phys_XYZ(Calib,Data.X,Data.Y,ZIndex); |
---|
| 174 | Dt=1; %default |
---|
| 175 | if isfield(Data,'dt')&&~isempty(Data.dt) |
---|
| 176 | Dt=Data.dt; |
---|
| 177 | end |
---|
| 178 | if isfield(Data,'Dt')&&~isempty(Data.Dt) |
---|
| 179 | Dt=Data.Dt; |
---|
| 180 | end |
---|
| 181 | if isfield(Data,'U')&&isfield(Data,'V')&&~isempty(Data.U) && ~isempty(Data.V) |
---|
| 182 | [XOut_1,YOut_1]=phys_XYZ(Calib,Data.X-Data.U/2,Data.Y-Data.V/2,ZIndex); |
---|
| 183 | [XOut_2,YOut_2]=phys_XYZ(Calib,Data.X+Data.U/2,Data.Y+Data.V/2,ZIndex); |
---|
| 184 | DataOut.U=(XOut_2-XOut_1)/Dt; |
---|
| 185 | DataOut.V=(YOut_2-YOut_1)/Dt; |
---|
| 186 | end |
---|
| 187 | end |
---|
| 188 | |
---|
| 189 | %% suppress tps |
---|
| 190 | list_tps={'Coord_tps' 'U_tps' 'V_tps' 'SubRange' 'NbSites'}; |
---|
| 191 | ind_remove=[]; |
---|
| 192 | for ilist=1:numel(list_tps) |
---|
| 193 | ind_tps=find(strcmp(list_tps{ilist},Data.ListVarName)); |
---|
| 194 | if ~isempty(ind_tps) |
---|
| 195 | ind_remove=[ind_remove ind_tps]; |
---|
| 196 | DataOut=rmfield(DataOut,list_tps{ilist}); |
---|
| 197 | end |
---|
| 198 | end |
---|
| 199 | if isfield(DataOut,'VarAttribute') && numel(DataOut.VarAttribute)>=3 && isfield(DataOut.VarAttribute{3},'VarIndex_tps') |
---|
| 200 | DataOut.VarAttribute{3}=rmfield(DataOut.VarAttribute{3},'VarIndex_tps'); |
---|
| 201 | end |
---|
| 202 | if isfield(DataOut,'VarAttribute')&& numel(DataOut.VarAttribute)>=4 && isfield(DataOut.VarAttribute{4},'VarIndex_tps') |
---|
| 203 | DataOut.VarAttribute{4}=rmfield(DataOut.VarAttribute{4},'VarIndex_tps'); |
---|
| 204 | end |
---|
| 205 | if ~isempty(ind_remove) |
---|
| 206 | DataOut.ListVarName(ind_remove)=[]; |
---|
| 207 | DataOut.VarDimName(ind_remove)=[]; |
---|
| 208 | DataOut.VarAttribute(ind_remove)=[]; |
---|
| 209 | end |
---|
| 210 | |
---|
| 211 | %% transform of spatial derivatives: TODO check the case with plane angles |
---|
| 212 | if isfield(Data,'X') && ~isempty(Data.X) && isfield(Data,'DjUi') && ~isempty(Data.DjUi) |
---|
| 213 | % estimate the Jacobian matrix DXpx/DXphys |
---|
| 214 | for ip=1:length(Data.X) |
---|
| 215 | [Xp1,Yp1]=phys_XYZ(Calib,Data.X(ip)+0.5,Data.Y(ip),ZIndex); |
---|
| 216 | [Xm1,Ym1]=phys_XYZ(Calib,Data.X(ip)-0.5,Data.Y(ip),ZIndex); |
---|
| 217 | [Xp2,Yp2]=phys_XYZ(Calib,Data.X(ip),Data.Y(ip)+0.5,ZIndex); |
---|
| 218 | [Xm2,Ym2]=phys_XYZ(Calib,Data.X(ip),Data.Y(ip)-0.5,ZIndex); |
---|
| 219 | %Jacobian matrix DXpphys/DXpx |
---|
| 220 | DjXi(1,1)=(Xp1-Xm1); |
---|
| 221 | DjXi(2,1)=(Yp1-Ym1); |
---|
| 222 | DjXi(1,2)=(Xp2-Xm2); |
---|
| 223 | DjXi(2,2)=(Yp2-Ym2); |
---|
| 224 | DjUi(:,:)=Data.DjUi(ip,:,:); |
---|
| 225 | DjUi=(DjXi*DjUi')/DjXi;% =J-1*M*J , curvature effects (derivatives of J) neglected |
---|
| 226 | DataOut.DjUi(ip,:,:)=DjUi'; |
---|
| 227 | end |
---|
| 228 | DataOut.DjUi = DataOut.DjUi/Dt; % min(Data.DjUi(:,1,1))=DUDX |
---|
| 229 | end |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | %%%%%%%%%%%%%%%%%%%% |
---|
| 233 | |
---|