Ignore:
Timestamp:
Jul 22, 2017, 7:20:02 PM (7 years ago)
Author:
sommeria
Message:

various bugs fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/geometry_calib.m

    r1008 r1009  
    220220
    221221%% Apply calibration
    222 [GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
     222[GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
    223223
    224224%% record the coordinate unit
     
    238238answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
    239239    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
    240     ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});
     240    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];
     241    [num2str(numel(ind_removed)) ' points removed']});
    241242if strcmp(answer,'Yes') %store the calibration data
    242243    if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
     
    334335
    335336%% Apply calibration
    336 [GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
     337[GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
    337338
    338339
     
    353354answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
    354355    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
    355     ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});
     356    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];...
     357    [num2str(numel(ind_removed)) ' points removed']});
    356358if strcmp(answer,'Yes') %store the calibration data
    357359    if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
     
    395397%------------------------------------------------------------------------
    396398% --- activate calibration and store parameters in ouputfile .
    397 function [GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic)
     399function [GeometryCalib,ind_max,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic)
    398400%------------------------------------------------------------------------
    399401
    400402index=[];
    401 
     403GeometryCalib=[];
    402404% apply the calibration, whose type is selected in  handles.calib_type
    403405if ~isempty(Coord)
    404406    GeometryCalib=feval(CalibFcn,Coord,Intrinsic);
    405407else
    406     GeometryCalib=[];
    407408    msgbox_uvmat('ERROR','No calibration points, abort')
    408409end
     
    411412end
    412413Z_plane=[];
    413 if ~isempty(Coord)
    414     %check error
     414
     415% estimate calibration error rms and max
     416X=Coord(:,1);
     417Y=Coord(:,2);
     418Z=Coord(:,3);
     419x_ima=Coord(:,4);
     420y_ima=Coord(:,5);
     421[Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z);
     422GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
     423GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
     424[ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima));
     425[ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima));
     426[tild,ind_dim]=max(ErrorMax);
     427ind_max=index(ind_dim); % mark the index with maximum deviation
     428
     429% detect bad calibration points, marked by indices ind_bad, if the
     430% difference of actual image coordinates and those given by calibration is
     431% greater than 2 pixels and greater than 4 rms.
     432check_x=abs(Xpoints-x_ima)>max(2,3*GeometryCalib.ErrorRms(1));
     433check_y=abs(Ypoints-y_ima)>max(2,3*GeometryCalib.ErrorRms(2));
     434ind_removed=find(check_x | check_y)
     435% repeat calibration without the excluded points:
     436if ~isempty(ind_removed)
     437    Coord(ind_removed,:)=[];
     438    GeometryCalib=feval(CalibFcn,Coord,Intrinsic);
    415439    X=Coord(:,1);
    416440    Y=Coord(:,2);
     
    420444    [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z);
    421445    GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
    422     [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima));
    423446    GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
    424     [GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima));
    425     [tild,ind_dim]=max(GeometryCalib.ErrorMax);
    426     index=index(ind_dim);
    427     %set the Z position of the reference plane used for calibration
    428     if isequal(max(Z),min(Z))%Z constant
    429         Z_plane=Z(1);
    430         GeometryCalib.NbSlice=1;
    431         GeometryCalib.SliceCoord=[0 0 Z_plane];
    432     end
     447end
     448GeometryCalib.ErrorMax=ErrorMax;
     449%set the Z position of the reference plane used for calibration
     450if isequal(max(Z),min(Z))%Z constant
     451    Z_plane=Z(1);
     452    GeometryCalib.NbSlice=1;
     453    GeometryCalib.SliceCoord=[0 0 Z_plane];
    433454end
    434455
Note: See TracChangeset for help on using the changeset viewer.