Ignore:
Timestamp:
Jan 31, 2013, 2:24:00 PM (12 years ago)
Author:
sommeria
Message:

LIF calibration improved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/transform_field/phys_polar.m

    r172 r567  
    4040%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    4141origin_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;
     42if isfield(CalibData,'PolarCentre') && isnumeric(CalibData.PolarCentre)
     43    if isequal(length(CalibData.PolarCentre),2);
     44        origin_xy= CalibData.PolarCentre;
    4545    end
    4646end
    4747radius_offset=0;%reference radius used to offset the radial coordinate r
    4848angle_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;
     49if isfield(CalibData,'PolarReferenceRadius') && isnumeric(CalibData.PolarReferenceRadius)
     50    radius_offset=CalibData.PolarReferenceRadius;
    5151end
    5252if radius_offset > 0
     
    5555    angle_scale=180/pi; %polar angle in degrees
    5656end
    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))
     57if 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))
    5959end
    6060% new x coordinate = radius-radius_offset;
     
    8080    end
    8181end
     82
    8283%transform second field (if exists) to cartesian phys coordiantes
    8384if test_1
     
    184185
    185186
    186 %------------------------------------------------------------------------
    187 %'phys_XYZ':transforms image (px) to real world (phys) coordinates using geometric calibration parameters
    188 % function [Xphys,Yphys]=phys_XYZ(Calib,X,Y,Z)
    189 %
    190 %OUTPUT:
    191 %
    192 %INPUT:
    193 %Z: index of plane
    194 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)>=Z
    197     Zindex=Z;
    198     Zphys=Calib.SliceCoord(Zindex,3);%GENERALISER AUX CAS AVEC ANGLE
    199 else
    200     Zphys=0;
    201 end
    202 if ~exist('X','var')||~exist('Y','var')
    203     Xphys=[];
    204     Yphys=[];%default
    205     return
    206 end
    207 %coordinate transform
    208 if ~isfield(Calib,'fx_fy')
    209      Calib.fx_fy=[1 1];
    210 end
    211 if ~isfield(Calib,'Tx_Ty_Tz')
    212      Calib.Tx_Ty_Tz=[0 0 1];
    213 end
    214 if ~isfield(Calib,'Cx_Cy')
    215      Calib.Cx_Cy=[0 0];
    216 end
    217 if ~isfield(Calib,'kc')
    218      Calib.kc=0;
    219 end
    220 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=1
    226     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 coordinates
    244     Yd=(Y-Calib.Cx_Cy(2));
    245     dist_fact=1+Calib.kc*(Xd.*Xd+Yd.*Yd)/(f*f); %distortion factor
    246     Xu=Xd./dist_fact;%undistorted sensor coordinates
    247     Yu=Yd./dist_fact;
    248     denom=Dx*Xu+Dy*Yu+D0;
    249     Xphys=(A11.*Xu+A12.*Yu+X0)./denom;%world coordinates
    250     Yphys=(A21.*Xu+A22.*Yu+Y0)./denom;
    251 else
    252     Xphys=-Calib.Tx_Ty_Tz(1)+X/Calib.fx_fy(1);
    253     Yphys=-Calib.Tx_Ty_Tz(2)+Y/Calib.fx_fy(2);
    254 end
    255 
    256187%%%%%%%%%%%%%%%%%%%%
    257188function [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.