Changeset 1108 for trunk/src/phys_XYZ.m
- Timestamp:
- Jan 7, 2022, 10:55:01 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/phys_XYZ.m
r1107 r1108 4 4 % 5 5 %OUTPUT: 6 % 6 % Xphys,Yphys,Zphys: vector of phys coordinates corresponding to the input vector of image coordinates 7 7 %INPUT: 8 %Z: index of plane 8 % Calib: Matlab structure containing the calibration parameters (pinhole camera model, see 9 % http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#GeometryCalib) and the 10 % parameters describing the illumination plane(s) 11 % .Tx_Ty_Tz: translation (3 phys coordinates) defining the origine of the camera frame 12 % .R : rotation matrix from phys to camera frame 13 % .fx_fy: focal length along each direction of the image 14 % X, Y: vectors of X and Y image coordinates 15 % ZIndex: index defining the current illumination plane in a volume scan 9 16 10 17 %======================================================================= … … 28 35 function [Xphys,Yphys,Zphys]=phys_XYZ(Calib,X,Y,Zindex) 29 36 %------------------------------------------------------------------------ 30 testangle=0; 31 test_refraction=0; 37 testangle=0;% =1 if the illumination plane is tilted with respect to the horizontal plane Xphys Yphys 38 test_refraction=0;% =1 if the considered points are viewed through an horizontal interface (located at z=Calib.InterfaceCoord(3)') 32 39 Zphys=0; %default output 33 40 if exist('Zindex','var')&& isequal(Zindex,round(Zindex))&& Zindex>0 && isfield(Calib,'SliceCoord')&&size(Calib.SliceCoord,1)>=Zindex 34 41 if isfield(Calib, 'SliceAngle') && size(Calib.SliceAngle,1)>=Zindex && ~isequal(Calib.SliceAngle(Zindex,:),[0 0 0]) 35 42 testangle=1; 36 norm_plane=angle2normal(Calib.SliceAngle(Zindex,:)); 43 norm_plane=angle2normal(Calib.SliceAngle(Zindex,:));% coordinates of the unit vector normal to the current illumination plane 37 44 end 38 45 Z0=Calib.SliceCoord(Zindex,3);%horizontal plane z=cte 39 46 Z0virt=Z0; 40 47 if isfield(Calib,'InterfaceCoord') && isfield(Calib,'RefractionIndex') 41 H=Calib.InterfaceCoord(3); 48 H=Calib.InterfaceCoord(3);% z position of the water surface 42 49 if H>Z0 43 50 Z0virt=H-(H-Z0)/Calib.RefractionIndex; %corrected z (virtual object) … … 69 76 if isfield(Calib,'R') 70 77 R=(Calib.R)'; 78 c=Z0virt; 71 79 if testangle 80 % equation of the illumination plane: z=ax+by+c 72 81 a=-norm_plane(1)/norm_plane(3); 73 82 b=-norm_plane(2)/norm_plane(3); 74 83 if test_refraction 75 a =a/Calib.RefractionIndex;76 b =b/Calib.RefractionIndex;84 avirt=a/Calib.RefractionIndex; 85 bvirt=b/Calib.RefractionIndex; 77 86 end 78 R(1)=R(1)+a*R(3); 79 R(2)=R(2)+b*R(3); 80 R(4)=R(4)+a*R(6); 81 R(5)=R(5)+b*R(6); 82 R(7)=R(7)+a*R(9); 83 R(8)=R(8)+b*R(9); 87 c=Z0virt-avirt*Calib.SliceCoord(Zindex,1)-bvirt*Calib.SliceCoord(Zindex,2);% Z0 = (virtual) z coordinate on the rotation axis (assumed horizontal) 88 % c=z coordinate at (x,y)=(0,0) 89 R(1)=R(1)+avirt*R(3); 90 R(2)=R(2)+bvirt*R(3); 91 R(4)=R(4)+avirt*R(6); 92 R(5)=R(5)+bvirt*R(6); 93 R(7)=R(7)+avirt*R(9); 94 R(8)=R(8)+bvirt*R(9); 84 95 end 85 96 Tx=Calib.Tx_Ty_Tz(1); … … 93 104 Z21=R(4)*R(9)-R(6)*R(7); 94 105 Z22=R(3)*R(7)-R(1)*R(9); 95 Zx0=R(3)*R(5)-R(2)*R(6);96 Zy0=R(1)*R(6)-R(3)*R(4);97 A11=R(8)*Ty-R(5)*Tz+Z11*Z0virt;98 A12=R(2)*Tz-R(8)*Tx+Z12*Z0virt;99 A21=-R(7)*Ty+R(4)*Tz+Z21*Z0virt;100 A22=-R(1)*Tz+R(7)*Tx+Z22*Z0virt;101 X0=(R(5)*Tx-R(2)*Ty+Zx0* Z0virt);102 Y0=(-R(4)*Tx+R(1)*Ty+Zy0* Z0virt);106 Zx0=R(3)*R(5)-R(2)*R(6); 107 Zy0=R(1)*R(6)-R(3)*R(4); 108 B11=R(8)*Ty-R(5)*Tz+Z11*c; 109 B12=R(2)*Tz-R(8)*Tx+Z12*c; 110 B21=-R(7)*Ty+R(4)*Tz+Z21*c; 111 B22=-R(1)*Tz+R(7)*Tx+Z22*c; 112 X0=(R(5)*Tx-R(2)*Ty+Zx0*c); 113 Y0=(-R(4)*Tx+R(1)*Ty+Zy0*c); 103 114 %px to camera: 104 115 Xd=(X-Calib.Cx_Cy(1))/Calib.fx_fy(1); % sensor coordinates … … 116 127 end 117 128 denom=Dx*Xu+Dy*Yu+D0; 118 Xphys=( A11.*Xu+A12.*Yu+X0)./denom;%world coordinates119 Yphys=( A21.*Xu+A22.*Yu+Y0)./denom;129 Xphys=(B11.*Xu+B12.*Yu+X0)./denom;%world coordinates 130 Yphys=(B21.*Xu+B22.*Yu+Y0)./denom; 120 131 if testangle 121 132 Zphys=Z0+a*Xphys+b*Yphys;
Note: See TracChangeset
for help on using the changeset viewer.