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

Last change on this file since 40 was 40, checked in by sommeria, 11 years ago

-relabel_i_j added to the svn (relabel an image series with two indices)
-Menu projection Object added to uvmat, rationalizes the call of projection objects (to improve yet)
-get_plot_handles: modified in relationwith the Menu projection object
-mouse_down: corrected in relation with previous change in field transforms
-transform_field functions added to the svn
-set_object and keyboard_callback: cleaning

File size: 5.3 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 calibration parameters (Tsai) or containing a subtree Calib.GeometryCalib with these 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 exist('Data_1','var')
39    if ~(exist('CalibData_1','var') && isfield(CalibData_1,'GeometryCalib'))
40        DataOut_1=Data_1;
41    else
42        DataOut_1=px_1(Data_1,CalibData_1.GeometryCalib);
43    end
44else
45    DataOut_1=[];
46end
47
48
49%------------------------------------------------
50function DataOut=px_1(Data,Calib)
51DataOut=Data;%default
52
53%Act only if .CoordType=phys, and Calib defined
54if isfield(Data,'CoordType')& isequal(Data.CoordType,'phys')& ~isempty(Calib)
55    DataOut.CoordType='px'; %put flag for pixel coordinates
56    DataOut.CoordUnit='px';
57    %transform of X,Y coordinates
58    if isfield(Data,'Z')&~isempty(Data.Z)
59        Z=Data.Z;
60    else
61        Z=0;
62    end
63    if isfield(Data,'X') & isfield(Data,'Y')
64        [DataOut.X,DataOut.Y]=px_XYZ(Calib,Data.X,Data.Y,Z);
65        if isfield(Data,'U')&isfield(Data,'V')& isfield(Data,'dt')& ~isequal(Data.dt,0)
66            Data.U=Data.U*Data.dt;
67            Data.V=Data.V*Data.dt;
68            if isfield(Data,'W')
69                W=Data.W*Data.dt;
70            else
71                W=0;
72            end
73            [XOut_1,YOut_1]=px_XYZ(Calib,Data.X-Data.U/2,Data.Y-Data.V/2,Z-W/2);
74            [XOut_2,YOut_2]=px_XYZ(Calib,Data.X+Data.U/2,Data.Y+Data.V/2,Z+W/2);
75            DataOut.U=XOut_2-XOut_1;
76            DataOut.V=YOut_2-YOut_1;
77        end
78    end
79    %transform of an image
80    if isfield(Data,'A')&isfield(Data,'AX')&~isempty(Data.AX) & isfield(Data,'AY')&...
81                                   isfield(Data,'AY')&~isempty(Data.AY)&length(Data.A)>1
82%         if isfield(Data,'Field')&isequal(Data.Field,'images')
83          %NO TRANSFORM FROM phys to px for images
84            DataOut.A=[];%
85    end
86end
87
88%'px_XYZ': transform phys coordinates to image coordinates (px)
89%
90% OUPUT:
91% X,Y: array of coordinates in the image cooresponding to the input physical positions
92%                    (origin at lower leftcorner, unit=pixel)
93
94% INPUT:
95% Calib: structure containing the calibration parameters (read from the ImaDoc .xml file)
96% Xphys, Yphys: array of x,y physical coordinates
97% [Zphys]: corresponding array of z physical coordinates (0 by default)
98
99
100function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
101X=[];%default
102Y=[];
103% if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'PlanePos')&length(Calib.PlanePos)>=Z
104%     Zindex=Z;
105%     planepos=Calib.PlanePos{Zindex};
106%     zphys=planepos(3);%A GENERALISER CAS AVEC ANGLE
107% else
108%     zphys=0;
109% end
110if ~exist('Zphys','var')
111    Zphys=0;
112end
113
114%%%%%%%%%%%%%
115if isfield(Calib,'R')
116    R=(Calib.R)';
117    xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx;
118    yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Ty;
119    zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tz;
120%undistorted image coordinates
121    Xu=Calib.f*xc./zc;
122    Yu=Calib.f*yc./zc;
123%distorted image coordinates
124    distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR
125% distortion=1;
126    Xd=Xu./distortion;
127    Yd=Yu./distortion;
128%pixel coordinates
129    X=Xd*Calib.sx/Calib.dpx+Calib.Cx;
130    Y=Yd/Calib.dpy+Calib.Cy;
131
132elseif isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib 
133        X=Xphys*Calib.Pxcmx;
134        Y=Yphys*Calib.Pxcmy;
135end
136
137
Note: See TracBrowser for help on using the repository browser.