Changeset 1009 for trunk/src/geometry_calib.m
- Timestamp:
- Jul 22, 2017, 7:20:02 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/geometry_calib.m
r1008 r1009 220 220 221 221 %% Apply calibration 222 [GeometryCalib,index, Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration222 [GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration 223 223 224 224 %% record the coordinate unit … … 238 238 answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';... 239 239 ['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']}); 241 242 if strcmp(answer,'Yes') %store the calibration data 242 243 if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration … … 334 335 335 336 %% Apply calibration 336 [GeometryCalib,index, Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration337 [GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration 337 338 338 339 … … 353 354 answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';... 354 355 ['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']}); 356 358 if strcmp(answer,'Yes') %store the calibration data 357 359 if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration … … 395 397 %------------------------------------------------------------------------ 396 398 % --- activate calibration and store parameters in ouputfile . 397 function [GeometryCalib,ind ex,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic)399 function [GeometryCalib,ind_max,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic) 398 400 %------------------------------------------------------------------------ 399 401 400 402 index=[]; 401 403 GeometryCalib=[]; 402 404 % apply the calibration, whose type is selected in handles.calib_type 403 405 if ~isempty(Coord) 404 406 GeometryCalib=feval(CalibFcn,Coord,Intrinsic); 405 407 else 406 GeometryCalib=[];407 408 msgbox_uvmat('ERROR','No calibration points, abort') 408 409 end … … 411 412 end 412 413 Z_plane=[]; 413 if ~isempty(Coord) 414 %check error 414 415 % estimate calibration error rms and max 416 X=Coord(:,1); 417 Y=Coord(:,2); 418 Z=Coord(:,3); 419 x_ima=Coord(:,4); 420 y_ima=Coord(:,5); 421 [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z); 422 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 423 GeometryCalib.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); 427 ind_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. 432 check_x=abs(Xpoints-x_ima)>max(2,3*GeometryCalib.ErrorRms(1)); 433 check_y=abs(Ypoints-y_ima)>max(2,3*GeometryCalib.ErrorRms(2)); 434 ind_removed=find(check_x | check_y) 435 % repeat calibration without the excluded points: 436 if ~isempty(ind_removed) 437 Coord(ind_removed,:)=[]; 438 GeometryCalib=feval(CalibFcn,Coord,Intrinsic); 415 439 X=Coord(:,1); 416 440 Y=Coord(:,2); … … 420 444 [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z); 421 445 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 422 [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima));423 446 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 447 end 448 GeometryCalib.ErrorMax=ErrorMax; 449 %set the Z position of the reference plane used for calibration 450 if isequal(max(Z),min(Z))%Z constant 451 Z_plane=Z(1); 452 GeometryCalib.NbSlice=1; 453 GeometryCalib.SliceCoord=[0 0 Z_plane]; 433 454 end 434 455
Note: See TracChangeset
for help on using the changeset viewer.