source: trunk/src/private/px_XYZ.m @ 8

Last change on this file since 8 was 8, checked in by gostiaux, 11 years ago
File size: 1.5 KB
Line 
1%'px_XYZ': transform phys coordinates to image coordinates (px)
2%
3% OUPUT:
4% X,Y: array of coordinates in the image cooresponding to the input physical positions
5%                    (origin at lower leftcorner, unit=pixel)
6
7% INPUT:
8% Calib: structure containing the calibration parameters (read from the ImaDoc .xml file)
9% Xphys, Yphys: array of x,y physical coordinates
10% [Zphys]: corresponding array of z physical coordinates (0 by default)
11
12
13function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
14X=[];%default
15Y=[];
16% if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'PlanePos')&length(Calib.PlanePos)>=Z
17%     Zindex=Z;
18%     planepos=Calib.PlanePos{Zindex};
19%     zphys=planepos(3);%A GENERALISER CAS AVEC ANGLE
20% else
21%     zphys=0;
22% end
23if ~exist('Zphys','var')
24    Zphys=0;
25end
26
27%%%%%%%%%%%%%
28if isfield(Calib,'R')
29    R=(Calib.R)';
30    xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx;
31    yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Ty;
32    zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tz;
33%undistorted image coordinates
34    Xu=Calib.f*xc./zc;
35    Yu=Calib.f*yc./zc;
36%distorted image coordinates
37    distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR
38% distortion=1;
39    Xd=Xu./distortion;
40    Yd=Yu./distortion;
41%pixel coordinates
42    X=Xd*Calib.sx/Calib.dpx+Calib.Cx;
43    Y=Yd/Calib.dpy+Calib.Cy;
44
45elseif isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib 
46        X=Xphys*Calib.Pxcmx;
47        Y=Yphys*Calib.Pxcmy;
48end
49
50
Note: See TracBrowser for help on using the repository browser.