Changeset 567 for trunk/src/transform_field
- Timestamp:
- Jan 31, 2013, 2:24:00 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/transform_field/phys_polar.m
r172 r567 40 40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 41 41 origin_xy=[0 0];%center for the polar coordinates in the original x,y coordinates 42 if isfield(Calib {1},'PolarCentre') && isnumeric(Calib{1}.PolarCentre)43 if isequal(length(Calib {1}.PolarCentre),2);44 origin_xy= Calib {1}.PolarCentre;42 if isfield(CalibData,'PolarCentre') && isnumeric(CalibData.PolarCentre) 43 if isequal(length(CalibData.PolarCentre),2); 44 origin_xy= CalibData.PolarCentre; 45 45 end 46 46 end 47 47 radius_offset=0;%reference radius used to offset the radial coordinate r 48 48 angle_offset=0; %reference angle used as new origin of the polar angle (= axis Ox by default) 49 if isfield(Calib {1},'PolarReferenceRadius') && isnumeric(Calib{1}.PolarReferenceRadius)50 radius_offset=Calib {1}.PolarReferenceRadius;49 if isfield(CalibData,'PolarReferenceRadius') && isnumeric(CalibData.PolarReferenceRadius) 50 radius_offset=CalibData.PolarReferenceRadius; 51 51 end 52 52 if radius_offset > 0 … … 55 55 angle_scale=180/pi; %polar angle in degrees 56 56 end 57 if isfield(Calib {1},'PolarReferenceAngle') && isnumeric(Calib{1}.PolarReferenceAngle)58 angle_offset=Calib {1}.PolarReferenceAngle; %offset angle (in unit of the final angle, degrees or arc length along the reference radius))57 if isfield(CalibData,'PolarReferenceAngle') && isnumeric(CalibData.PolarReferenceAngle) 58 angle_offset=CalibData.PolarReferenceAngle; %offset angle (in unit of the final angle, degrees or arc length along the reference radius)) 59 59 end 60 60 % new x coordinate = radius-radius_offset; … … 80 80 end 81 81 end 82 82 83 %transform second field (if exists) to cartesian phys coordiantes 83 84 if test_1 … … 184 185 185 186 186 %------------------------------------------------------------------------187 %'phys_XYZ':transforms image (px) to real world (phys) coordinates using geometric calibration parameters188 % function [Xphys,Yphys]=phys_XYZ(Calib,X,Y,Z)189 %190 %OUTPUT:191 %192 %INPUT:193 %Z: index of plane194 function [Xphys,Yphys,Zphys]=phys_XYZ(Calib,X,Y,Z)195 %------------------------------------------------------------------------196 if exist('Z','var')&& isequal(Z,round(Z))&& Z>0 && isfield(Calib,'SliceCoord')&&length(Calib.SliceCoord)>=Z197 Zindex=Z;198 Zphys=Calib.SliceCoord(Zindex,3);%GENERALISER AUX CAS AVEC ANGLE199 else200 Zphys=0;201 end202 if ~exist('X','var')||~exist('Y','var')203 Xphys=[];204 Yphys=[];%default205 return206 end207 %coordinate transform208 if ~isfield(Calib,'fx_fy')209 Calib.fx_fy=[1 1];210 end211 if ~isfield(Calib,'Tx_Ty_Tz')212 Calib.Tx_Ty_Tz=[0 0 1];213 end214 if ~isfield(Calib,'Cx_Cy')215 Calib.Cx_Cy=[0 0];216 end217 if ~isfield(Calib,'kc')218 Calib.kc=0;219 end220 if isfield(Calib,'R')221 R=(Calib.R)';222 Tx=Calib.Tx_Ty_Tz(1);223 Ty=Calib.Tx_Ty_Tz(2);224 Tz=Calib.Tx_Ty_Tz(3);225 f=Calib.fx_fy(1);%dpy=1; sx=1226 dpx=Calib.fx_fy(2)/Calib.fx_fy(1);227 Dx=R(5)*R(7)-R(4)*R(8);228 Dy=R(1)*R(8)-R(2)*R(7);229 D0=f*(R(2)*R(4)-R(1)*R(5));230 Z11=R(6)*R(8)-R(5)*R(9);231 Z12=R(2)*R(9)-R(3)*R(8);232 Z21=R(4)*R(9)-R(6)*R(7);233 Z22=R(3)*R(7)-R(1)*R(9);234 Zx0=R(3)*R(5)-R(2)*R(6);235 Zy0=R(1)*R(6)-R(3)*R(4);236 A11=R(8)*Ty-R(5)*Tz+Z11*Zphys;237 A12=R(2)*Tz-R(8)*Tx+Z12*Zphys;238 A21=-R(7)*Ty+R(4)*Tz+Z21*Zphys;239 A22=-R(1)*Tz+R(7)*Tx+Z22*Zphys;240 X0=f*(R(5)*Tx-R(2)*Ty+Zx0*Zphys);241 Y0=f*(-R(4)*Tx+R(1)*Ty+Zy0*Zphys);242 %px to camera:243 Xd=dpx*(X-Calib.Cx_Cy(1)); % sensor coordinates244 Yd=(Y-Calib.Cx_Cy(2));245 dist_fact=1+Calib.kc*(Xd.*Xd+Yd.*Yd)/(f*f); %distortion factor246 Xu=Xd./dist_fact;%undistorted sensor coordinates247 Yu=Yd./dist_fact;248 denom=Dx*Xu+Dy*Yu+D0;249 Xphys=(A11.*Xu+A12.*Yu+X0)./denom;%world coordinates250 Yphys=(A21.*Xu+A22.*Yu+Y0)./denom;251 else252 Xphys=-Calib.Tx_Ty_Tz(1)+X/Calib.fx_fy(1);253 Yphys=-Calib.Tx_Ty_Tz(2)+Y/Calib.fx_fy(2);254 end255 256 187 %%%%%%%%%%%%%%%%%%%% 257 188 function [A_out,Rangx,Rangy]=phys_Ima_polar(A,CalibIn,ZIndex,origin_xy,radius_offset,angle_offset,angle_scale)
Note: See TracChangeset
for help on using the changeset viewer.