source: trunk/src/transform_field/px.m @ 497

Last change on this file since 497 was 116, checked in by sommeria, 14 years ago

geometry_calib is now updated when a new image is viewed by uvmat
imadoc2struct corrected for time reading

File size: 5.6 KB
Line 
1%'px': transform fields from physical coordinates (phys) to image (px) coordinates
2
3% OUTPUT:
4% DataOut:   structure of modified data (transforms DataIn)
5%       DataOut.CoordType='px': labels image coordinates
6%       DataOut.CoordUnit= 'px' : units of output coordinates
7%       DataOut.X and .Y arrays of image coordinates X, Y
8%       DataOut.U, .V velocity in pixel displacement on the image (unit=px), if velocity exists as input
9%   
10%INPUT:
11% DataIn:  structure of possible input data (like UvData) or cell of structures (several fields):
12%      DataIn.CoordType='phys': allows transform to px, else no transform   (DataOut=DataIn)
13%      DataIn.X and .Y arrays of physical coordinates X, Y
14%      DataIn.Z corresponding array of Z coordinates (=0 by default)
15%      DataIn.U, V corresponding array of velocity components
16%      DataIn.W corresponding array of the third velocity component in 3D case
17%      DataIn.dt: time interval of the image pair used for velocity measurement (NEEDED TO GET OUTPUT RESULT))
18%      DataIn.A, AX, AY : image or scalar input -> EMPTY  CORRESPONDING OUTPUT (A REVOIR)
19%      Other fields in DataIn: copied to DataOut without modification
20% Calib: structure containing the  substructure Calib.GeometryCalib with the calibration parameters
21%
22% call the function  px_XYZ (case of images) for pointwise coordinate transforms
23
24function [DataOut,DataOut_1]=px(Data,CalibData,Data_1,CalibData_1)%DataIn,Calib)
25% A FAIRE: 1- verifier si DataIn est une 'field structure'(.ListVarName'):
26% chercher ListVarAttribute, for each field (cell of variables):
27%   .CoordType: 'phys' or 'px'   (default==px, no transform)
28%   .scale_factor: =dt (to transform displacement into velocity) default=1
29%   .covariance: 'scalar', 'coord', 'D_i': covariant (like velocity), 'D^i': contravariant (like gradient), 'D^jD_i' (like strain tensor)
30%   (default='coord' if .Role='coord_x,_y...,
31%            'D_i' if '.Role='vector_x,...',
32%              'scalar', else (thenno change except scale factor)
33if  ~(exist('CalibData','var') && isfield(CalibData,'GeometryCalib'))
34    DataOut=Data;
35else
36    DataOut=px_1(Data,CalibData.GeometryCalib);
37end
38if isfield(DataOut,'Z')
39    DataOut=rmfield(DataOut,'Z');
40end
41if exist('Data_1','var')% if there is a second input field, it is also transformed
42    if ~(exist('CalibData_1','var') && isfield(CalibData_1,'GeometryCalib'))
43        DataOut_1=Data_1;
44    else
45        DataOut_1=px_1(Data_1,CalibData_1.GeometryCalib);
46    end
47    if isfield(DataOut_1,'Z')
48        DataOut_1=rmfield(DataOut_1,'Z');
49    end
50else % no second input field then empty second output field
51    DataOut_1=[];
52end
53
54
55%------------------------------------------------
56function DataOut=px_1(Data,Calib)
57DataOut=Data;%default
58
59%Act only if .CoordType=phys, and Calib defined
60if isfield(Data,'CoordType')&& isequal(Data.CoordType,'phys')&& ~isempty(Calib)
61    DataOut.CoordType='px'; %put flag for pixel coordinates
62    DataOut.CoordUnit='px';
63    %transform of X,Y coordinates
64    if isfield(Data,'Z')&&~isempty(Data.Z)
65        Z=Data.Z;
66    else
67        Z=0;
68    end
69    if isfield(Data,'X') & isfield(Data,'Y')
70        [DataOut.X,DataOut.Y]=px_XYZ(Calib,Data.X,Data.Y,Z);
71        if isfield(Data,'U')&isfield(Data,'V')& isfield(Data,'dt')& ~isequal(Data.dt,0)
72            Data.U=Data.U*Data.dt;
73            Data.V=Data.V*Data.dt;
74            if isfield(Data,'W')
75                W=Data.W*Data.dt;
76            else
77                W=0;
78            end
79            [XOut_1,YOut_1]=px_XYZ(Calib,Data.X-Data.U/2,Data.Y-Data.V/2,Z-W/2);
80            [XOut_2,YOut_2]=px_XYZ(Calib,Data.X+Data.U/2,Data.Y+Data.V/2,Z+W/2);
81            DataOut.U=XOut_2-XOut_1;
82            DataOut.V=YOut_2-YOut_1;
83        end
84    end
85    %transform of an image
86    if isfield(Data,'A')&isfield(Data,'AX')&~isempty(Data.AX) & isfield(Data,'AY')&...
87                                   isfield(Data,'AY')&~isempty(Data.AY)&length(Data.A)>1
88%         if isfield(Data,'Field')&isequal(Data.Field,'images')
89          %NO TRANSFORM FROM phys to px for images
90            DataOut.A=[];%
91    end
92end
93
94%'px_XYZ': transform phys coordinates to image coordinates (px)
95%
96% OUPUT:
97% X,Y: array of coordinates in the image cooresponding to the input physical positions
98%                    (origin at lower leftcorner, unit=pixel)
99
100% INPUT:
101% Calib: structure containing the calibration parameters (read from the ImaDoc .xml file)
102% Xphys, Yphys: array of x,y physical coordinates
103% [Zphys]: corresponding array of z physical coordinates (0 by default)
104
105%
106% function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
107% X=[];%default
108% Y=[];
109% % if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'PlanePos')&length(Calib.PlanePos)>=Z
110% %     Zindex=Z;
111% %     planepos=Calib.PlanePos{Zindex};
112% %     zphys=planepos(3);%A GENERALISER CAS AVEC ANGLE
113% % else
114% %     zphys=0;
115% % end
116% if ~exist('Zphys','var')
117%     Zphys=0;
118% end
119%
120% %%%%%%%%%%%%%
121% if isfield(Calib,'R')
122%     R=(Calib.R)';
123%     xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx;
124%     yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Ty;
125%     zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tz;
126% %undistorted image coordinates
127%     Xu=Calib.f*xc./zc;
128%     Yu=Calib.f*yc./zc;
129% %distorted image coordinates
130%     distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR
131% % distortion=1;
132%     Xd=Xu./distortion;
133%     Yd=Yu./distortion;
134% %pixel coordinates
135%     X=Xd*Calib.sx/Calib.dpx+Calib.Cx;
136%     Y=Yd/Calib.dpy+Calib.Cy;
137%
138% elseif isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib 
139%         X=Xphys*Calib.Pxcmx;
140%         Y=Yphys*Calib.Pxcmy;
141% end
142
143
Note: See TracBrowser for help on using the repository browser.