source: trunk/src/px_XYZ.m @ 109

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

merge_proj.m, proj_field.m: bugs repaired merging of images
plot_field.m: minor cleaning
imadoc2struct: introduce the possibility of readying the calibration point coordinates
sub_field.m:bugs repaired
geometry_calib, create_grid: introduction of new calibration methods, improvement of detect_grid

File size: 1.8 KB
Line 
1%'px_XYZ': transform physical to image coordinates.
2%------------------------------------------------------------------------
3%[X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
4%------------------------------------------------------------------------           
5% OUTPUT:
6% [X,Y]: image coordinates(in pixels)
7%------------------------------------------------------------------------
8% INPUT:
9% Calib: structure containing calibration parameters
10% Xphys,Yphys,Zphys; vectors of physical coordinates for a set of points
11
12function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
13X=[];%default
14Y=[];
15% if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'PlanePos')&length(Calib.PlanePos)>=Z
16%     Zindex=Z;
17%     planepos=Calib.PlanePos{Zindex};
18%     zphys=planepos(3);%A GENERALISER CAS AVEC ANGLE
19% else
20%     zphys=0;
21% end
22if ~exist('Zphys','var')
23    Zphys=0;
24end
25if ~isfield(Calib,'f')
26    Calib.f=1;
27end
28if ~isfield(Calib,'kappa1')
29    Calib.kappa1=0;
30end
31if ~isfield(Calib,'sx')
32    Calib.sx=1;
33end
34if ~isfield(Calib,'dpx')
35    Calib.dpx=1;
36end
37if ~isfield(Calib,'dpy')
38    Calib.dpy=1;
39end
40if ~isfield(Calib,'Cx')
41    Calib.Cx=0;
42end
43if ~isfield(Calib,'Cy')
44    Calib.Cy=0;
45end
46%%%%%%%%%%%%%
47if isfield(Calib,'R')
48    R=(Calib.R)';
49    xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx;
50    yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Ty;
51    zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tz;
52%undistorted image coordinates
53    Xu=Calib.f*xc./zc;
54    Yu=Calib.f*yc./zc;
55%distorted image coordinates
56    distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR
57% distortion=1;
58    Xd=Xu./distortion;
59    Yd=Yu./distortion;
60%pixel coordinates
61    X=Xd*Calib.sx/Calib.dpx+Calib.Cx;
62    Y=Yd/Calib.dpy+Calib.Cy;
63
64elseif isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib 
65        X=Xphys*Calib.Pxcmx;
66        Y=Yphys*Calib.Pxcmy;
67end
68
69
70
Note: See TracBrowser for help on using the repository browser.