- Timestamp:
- Oct 14, 2010, 6:35:03 PM (14 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/geometry_calib.m
r109 r114 43 43 % Edit the above text to modify the response to help geometry_calib 44 44 45 % Last Modified by GUIDE v2.5 0 3-Oct-2010 09:34:1245 % Last Modified by GUIDE v2.5 05-Oct-2010 13:47:00 46 46 47 47 % Begin initialization code - DO NOT edit … … 93 93 inputxml=''; 94 94 if exist('inputfile','var')& ~isempty(inputfile) 95 struct.XmlInput file=inputfile;95 struct.XmlInputFile=inputfile; 96 96 set(hObject,'UserData',struct) 97 97 [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile); … … 154 154 return 155 155 end 156 157 %check error 158 if isfield(GeometryCalib,'dpx_dpy') 159 Calib.dpx=GeometryCalib.dpx_dpy(1); 160 Calib.dpy=GeometryCalib.dpx_dpy(2); 161 end 162 if isfield(GeometryCalib,'sx') 163 Calib.sx=GeometryCalib.sx; 164 end 165 if isfield(GeometryCalib,'Cx_Cy') 166 Calib.Cx=GeometryCalib.Cx_Cy(1); 167 Calib.Cy=GeometryCalib.Cx_Cy(2); 168 end 169 if isfield(GeometryCalib,'kappa1') 170 Calib.kappa1=GeometryCalib.kappa1; 171 end 172 if isfield(GeometryCalib,'focal') 173 Calib.f=GeometryCalib.focal; 174 end 175 if isfield(GeometryCalib,'Tx_Ty_Tz') 176 Calib.Tx=GeometryCalib.Tx_Ty_Tz(1); 177 Calib.Ty=GeometryCalib.Tx_Ty_Tz(2); 178 Calib.Tz=GeometryCalib.Tx_Ty_Tz(3); 179 end 180 if isfield(GeometryCalib,'R') 181 Calib.R=GeometryCalib.R; 182 end 156 Z_plane=[]; 183 157 if ~isempty(Coord) 158 %check error 184 159 X=Coord(:,1); 185 160 Y=Coord(:,2); … … 187 162 x_ima=Coord(:,4); 188 163 y_ima=Coord(:,5); 189 [Xpoints,Ypoints]=px_XYZ( Calib,X,Y,Z);164 [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z); 190 165 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 191 166 [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima)); … … 194 169 [EM,ind_dim]=max(GeometryCalib.ErrorMax); 195 170 index=index(ind_dim); 171 %set the Z position of the reference plane used for calibration 196 172 if isequal(max(Z),min(Z))%Z constant 173 Z_plane=Z(1); 197 174 GeometryCalib.NbSlice=1; 198 GeometryCalib.SliceCoord=[0 0 Z(1)]; 199 end 200 end 175 GeometryCalib.SliceCoord=[0 0 Z_plane]; 176 end 177 end 178 %set the coordinate unit 201 179 unitlist=get(handles.CoordUnit,'String'); 202 180 unit=unitlist{get(handles.CoordUnit,'value')}; 203 181 GeometryCalib.CoordUnit=unit; 182 %record the points 204 183 GeometryCalib.SourceCalib.PointCoord=Coord; 205 206 %display calibration intrinsic parameters 207 k=0; 208 if isfield(GeometryCalib,'kappa1') 209 k=GeometryCalib.kappa1 * GeometryCalib.focal*GeometryCalib.focal; 210 end 211 sx=1;dpx_dpy=[1 1]; 212 if isfield(GeometryCalib,'sx') 213 sx=GeometryCalib.sx; 214 end 215 if isfield(GeometryCalib,'dpx_dpy') 216 dpx_dpy=GeometryCalib.dpx_dpy; 217 end 218 Cx_Cy=[0 0]; 219 if isfield(GeometryCalib,'Cx_Cy') 220 Cx_Cy=GeometryCalib.Cx_Cy; 221 end 222 f1=GeometryCalib.focal*sx/dpx_dpy(1); 223 f2=GeometryCalib.focal/dpx_dpy(2); 224 Cx=Cx_Cy(1); 225 Cy=Cx_Cy(2); 226 set(handles.fx,'String',num2str(f1,4)) 227 set(handles.fy,'String',num2str(f2,4)) 228 set(handles.k,'String',num2str(k,'%1.4f')) 229 set(handles.Cx,'String',num2str(Cx,'%1.1f')) 230 set(handles.Cy,'String',num2str(Cy,'%1.1f')) 231 % Display extrinsinc parameters 184 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters 185 186 % Display extrinsinc parameters (rotation and translation of camera with respect to the phys coordiantes) 232 187 set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) 233 188 set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) 234 189 set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) 235 236 % indicate the plane of the calibration grid if defined 237 huvmat=findobj(allchild(0),'Name','uvmat'); 238 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat 190 set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) 191 set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) 192 set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) 193 194 % store the calibration data, by default in the xml file of the currently displayed image 195 hhuvmat=guidata(findobj(allchild(0),'Name','uvmat'));%handles of elements in the GUI uvmat 239 196 RootPath=''; 240 197 RootFile=''; … … 244 201 RootFile=get(hhuvmat.RootFile,'String'); 245 202 filebase=fullfile(RootPath,RootFile); 246 outputfile=[filebase '.xml']; 203 outputfile=[filebase '.xml'];%xml file associated with the currently displayed image 247 204 else 248 205 question={'save the calibration data and point coordinates in'}; … … 256 213 ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']}); 257 214 if isequal(answer,'Yes') 258 update_imadoc(GeometryCalib,outputfile) 215 answer_1=msgbox_uvmat('INPUT_TXT',' Z= ',num2str(Z_plane)); 216 Z_plane=str2num(answer_1); 217 GeometryCalib.NbSlice=1; 218 GeometryCalib.SliceCoord=[0 0 Z_plane]; 219 errormsg=update_imadoc(GeometryCalib,outputfile);% introduce the calibration data in the xml file 220 if ~strcmp(errormsg,'') 221 msgbox_uvmat('ERROR',errormsg); 222 end 259 223 %display image with new calibration in the currently opened uvmat interface 260 224 hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');% delete calib points and markers … … 268 232 set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off' 269 233 set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7]) 270 uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat 271 % if ip==0 272 MenuPlot_Callback(hObject, eventdata, handles) 273 set(handles.ListCoord,'Value',index)% indicate in the list the point with max deviation (possible mistake) 274 ListCoord_Callback(hObject, eventdata, handles) 275 % end 234 uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat, show the image in phys coordinates 235 MenuPlot_Callback(hObject, eventdata, handles) 236 set(handles.ListCoord,'Value',index)% indicate in the list the point with max deviation (possible mistake) 237 ListCoord_Callback(hObject, eventdata, handles) 276 238 figure(handles.geometry_calib) 277 239 end … … 286 248 Coord_cell=get(handles.ListCoord,'String'); 287 249 Object=read_geometry_calib(Coord_cell); 288 GeometryCalib=feval(calib_cell{val},Object.Coord); 289 290 % %record image source 291 GeometryCalib.SourceCalib.PointCoord=Object.Coord; 250 GeometryCalib=feval(['calib_' calib_cell{val}],Object.Coord,handles); 251 252 %read the current calibration points 253 Coord_cell=get(handles.ListCoord,'String'); 254 Object=read_geometry_calib(Coord_cell); 255 Coord=Object.Coord; 256 257 % apply the calibration, whose type is selected in handles.calib_type 258 if ~isempty(Coord) 259 calib_cell=get(handles.calib_type,'String'); 260 val=get(handles.calib_type,'Value'); 261 GeometryCalib=feval(['calib_' calib_cell{val}],Coord,handles); 262 else 263 msgbox_uvmat('ERROR','No calibration points, abort') 264 return 265 end 266 267 if ~isempty(Coord) 268 %check error 269 X=Coord(:,1); 270 Y=Coord(:,2); 271 Z=Coord(:,3); 272 x_ima=Coord(:,4); 273 y_ima=Coord(:,5); 274 [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z); 275 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 276 [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima)); 277 GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); 278 [GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima)); 279 [EM,ind_dim]=max(GeometryCalib.ErrorMax); 280 index=index(ind_dim); 281 %set the Z position of the reference plane used for calibration 282 Z_plane=[]; 283 if isequal(max(Z),min(Z)) 284 Z_plane=Z(1); 285 end 286 answer_1=msgbox_uvmat('INPUT_TXT',' Z= ',num2str(Z_plane)); 287 Z_plane=str2num(answer_1); 288 GeometryCalib.NbSlice=1; 289 GeometryCalib.SliceCoord=[0 0 Z_plane]; 290 %set the coordinate unit 291 unitlist=get(handles.CoordUnit,'String'); 292 unit=unitlist{get(handles.CoordUnit,'value')}; 293 GeometryCalib.CoordUnit=unit; 294 %record the points 295 GeometryCalib.SourceCalib.PointCoord=Coord; 296 errormsg=update_imadoc(GeometryCalib,outputfile);% introduce the calibration data in the xml file 297 if ~strcmp(errormsg,'') 298 msgbox_uvmat('ERROR',errormsg); 299 end 300 end 301 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters 302 303 % Display extrinsinc parameters (rotation and translation of camera with respect to the phys coordiantes) 304 set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) 305 set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) 306 set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) 307 set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) 308 set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) 309 set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) 310 311 % indicate the plane of the calibration grid if defined 312 % huvmat=findobj(allchild(0),'Name','uvmat'); 313 % hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat 314 % RootPath=''; 315 % RootFile=''; 316 % if ~isempty(hhuvmat.RootPath)& ~isempty(hhuvmat.RootFile) 317 % testhandle=1; 318 % RootPath=get(hhuvmat.RootPath,'String'); 319 % RootFile=get(hhuvmat.RootFile,'String'); 320 % filebase=fullfile(RootPath,RootFile); 321 % outputfile=[filebase '.xml']; 322 % else 323 % question={'save the calibration data and point coordinates in'}; 324 % def={fullfile(RootPath,['ObjectCalib.xml'])}; 325 % options.Resize='on'; 326 % answer=inputdlg(question,'save average in a new file',1,def,options); 327 % outputfile=answer{1}; 328 % end 292 329 293 330 %open and read the dataview GUI … … 298 335 CalibData=get(handles.geometry_calib,'UserData');%read the calibration image source on the interface userdata 299 336 300 if isfield(CalibData,'XmlInput ')301 XmlInput=fileparts(CalibData.XmlInput );337 if isfield(CalibData,'XmlInputFile') 338 XmlInput=fileparts(CalibData.XmlInputFile); 302 339 [XmlInput,filename,ext]=fileparts(XmlInput); 303 340 end … … 326 363 if ~testinput 327 364 filename='PROJETS';%default 328 if isfield(CalibData,'XmlInput ')329 [pp,filename]=fileparts(CalibData.XmlInput );365 if isfield(CalibData,'XmlInputFile') 366 [pp,filename]=fileparts(CalibData.XmlInputFile); 330 367 end 331 368 while ~isequal(filename,'PROJETS') && numel(filename)>1 … … 354 391 T_y=py(2); 355 392 GeometryCalib.CalibrationType='rescale'; 356 GeometryCalib.focal=1;%default 357 GeometryCalib.sx=px(1)/py(1); 393 GeometryCalib.fx_fy=[px(1) py(1)]; 358 394 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 359 GeometryCalib.Tx_Ty_Tz=[T_x T_y GeometryCalib.focal/py(1)]; 360 GeometryCalib.R=[1,0,0;0,1,0;0,0,0]; 395 GeometryCalib.Tx_Ty_Tz=[px(2)/px(1) py(2)/py(1) 1]; 396 %GeometryCalib.R=[1,0,0;0,1,0;0,0,0]; 397 GeometryCalib.omc=[0 0 0]; 361 398 362 399 %------------------------------------------------------------------------ 363 400 % determine the parameters for a calibration by a linear transform matrix (rescale and rotation) 364 function GeometryCalib=calib_linear(Coord,handles) 401 function GeometryCalib=calib_linear(Coord,handles) %TO UPDATE 365 402 %------------------------------------------------------------------------ 366 403 X=Coord(:,1); … … 385 422 %------------------------------------------------------------------------ 386 423 % determine the tsai parameters for a view normal to the grid plane 424 % NOT USED 387 425 function GeometryCalib=calib_normal(Coord,handles) 388 426 %------------------------------------------------------------------------ 389 427 Calib.f1=str2num(get(handles.fx,'String')); 390 428 Calib.f2=str2num(get(handles.fy,'String')); 391 Calib.k=str2num(get(handles.k ,'String'));429 Calib.k=str2num(get(handles.kc,'String')); 392 430 Calib.Cx=str2num(get(handles.Cx,'String')); 393 431 Calib.Cy=str2num(get(handles.Cy,'String')); … … 449 487 %------------------------------------------------------------------------ 450 488 function GeometryCalib=calib_3D_linear(Coord,handles) 489 %TO UPDATE 451 490 %------------------------------------------------------------------ 452 491 path_uvmat=which('uvmat');% check the path detected for source file uvmat … … 497 536 498 537 %retrieve the calibration points stored in the files listed in the popup list coord_files 499 x_1=Coord(:,4:5)'; 500 X_1=Coord(:,1:3)'; 538 x_1=Coord(:,4:5)';%px coordinates of the ref points 539 nx=str2num(get(hhuvmat.npx,'String')); 540 ny=str2num(get(hhuvmat.npy,'String')); 541 x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates 542 X_1=Coord(:,1:3)';%phys coordinates of the ref points 501 543 n_ima=numel(coord_files)+1; 502 544 if ~isempty(coord_files) … … 516 558 end 517 559 eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']); 560 eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]); 518 561 eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']); 519 562 end … … 525 568 n_ima=numel(coord_files)+1; 526 569 whos 527 nx=str2num(get(hhuvmat.npx,'String'));528 ny=str2num(get(hhuvmat.npy,'String'));529 570 530 571 est_dist=[1;0;0;0;0]; … … 536 577 537 578 GeometryCalib.CalibrationType='3D_quadr'; 538 GeometryCalib.focal=fc(2); 539 GeometryCalib.dpx_dpy=[1 1]; 579 GeometryCalib.fx_fy=fc'; 580 %GeometryCalib.focal=fc(2); 581 %GeometryCalib.dpx_dpy=[1 1]; 540 582 GeometryCalib.Cx_Cy=cc'; 541 GeometryCalib.sx=fc(1)/fc(2); 542 GeometryCalib.kappa1=-kc(1)/fc(2)^2; 583 %GeometryCalib.sx=fc(1)/fc(2); 584 GeometryCalib.kc=kc(1); 585 %GeometryCalib.kappa1=-kc(1)/fc(2)^2; 543 586 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 544 587 GeometryCalib.Tx_Ty_Tz=Tc_1'; 545 588 GeometryCalib.R=Rc_1; 546 GeometryCalib.R(3,1:3)=-GeometryCalib.R(3,1:3);%inversion for z upward 589 GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate 590 GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate 591 GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate 592 GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees 547 593 GeometryCalib.ErrorRMS=[]; 548 594 GeometryCalib.ErrorMax=[]; … … 556 602 x_1=Coord(:,4:5)'; 557 603 X_1=Coord(:,1:3)'; 604 huvmat=findobj(allchild(0),'Tag','uvmat'); 605 hhuvmat=guidata(huvmat); 606 ny=str2num(get(hhuvmat.npy,'String')); 607 x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates 558 608 n_ima=1; 559 Calib.f1=str2num(get(handles.fx,'String'));560 Calib.f2=str2num(get(handles.fy,'String'));561 Calib.k=str2num(get(handles.k,'String'));562 Calib.Cx=str2num(get(handles.Cx,'String'));563 Calib.Cy=str2num(get(handles.Cy,'String'));564 609 GeometryCalib.CalibrationType='3D_extrinsic'; 610 GeometryCalib.fx_fy(1)=str2num(get(handles.fx,'String')); 611 GeometryCalib.fx_fy(2)=str2num(get(handles.fy,'String')); 612 GeometryCalib.Cx_Cy(1)=str2num(get(handles.Cx,'String')); 613 GeometryCalib.Cx_Cy(2)=str2num(get(handles.Cy,'String')); 614 GeometryCalib.kc=str2num(get(handles.kc,'String')); 565 615 fct_path=fullfile(path_UVMAT,'toolbox_calib'); 566 616 addpath(fct_path) 617 Cx_Cy=ny-(GeometryCalib.Cx_Cy)';%reverse Cx_Cy(2) for calibration (inversion of px ordinate) 567 618 % [omc1,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,... 568 619 % [Calib.f Calib.f*Calib.sx]',... 569 620 % [Calib.Cx Calib.Cy]',... 570 621 % [-Calib.kappa1*Calib.f^2 0 0 0 0]); 571 [omc1,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,... 572 [Calib.f1 Calib.f2]',... 573 [Calib.Cx Calib.Cy]',... 574 [-Calib.k 0 0 0 0]); 622 [omc,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,... 623 (GeometryCalib.fx_fy)',... 624 Cx_Cy,[GeometryCalib.kc 0 0 0 0]); 575 625 %get the euler angles ??? 576 626 rmpath(fct_path); 577 627 578 628 std(ex') 579 GeometryCalib.CalibrationType='3D_extrinsic';580 GeometryCalib.focal=Calib.f2;581 GeometryCalib.dpx_dpy=[1 1];582 GeometryCalib.Cx_Cy=[Calib.Cx Calib.Cy];583 GeometryCalib.sx=Calib.f1/Calib.f2;584 GeometryCalib.kappa1=Calib.k/(Calib.f2*Calib.f2);585 629 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 586 630 GeometryCalib.Tx_Ty_Tz=Tc1'; 587 631 %inversion of z axis 588 632 GeometryCalib.R=Rc1; 633 GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate 634 GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate 635 %GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate 636 GeometryCalib.omc=(180/pi)*omc'; 589 637 %GeometryCalib.R(3,1:3)=-GeometryCalib.R(3,1:3);%inversion for z upward 590 638 … … 608 656 %-------------------------------------------------------------------------- 609 657 function GeometryCalib=calib_tsai(Coord,handles)% old version using gauthier's bianry ccal_fo 658 % NOT USED 610 659 %------------------------------------------------------------------------ 611 660 %TSAI … … 728 777 end 729 778 outputfile=[filebase '.xml']; 730 update_imadoc(GeometryCalib,outputfile) 779 errormsg=update_imadoc(GeometryCalib,outputfile); 780 if ~strcmp(errormsg,'') 781 msgbox_uvmat('ERROR',errormsg); 782 end 731 783 listfile=get(handles.coord_files,'string'); 732 784 if isequal(listfile,{''}) … … 739 791 set(handles.ListCoord,'Value',1)% refresh the display of coordinates 740 792 set(handles.ListCoord,'String',{'......'}) 793 794 % -------------------------------------------------------------------- 795 % --- Executes on button press in CLEAR_PTS: clear the list of calibration points 796 function CLEAR_PTS_Callback(hObject, eventdata, handles) 797 % -------------------------------------------------------------------- 798 set(handles.ListCoord,'Value',1)% refresh the display of coordinates 799 set(handles.ListCoord,'String',{'......'}) 800 MenuPlot_Callback(hObject, eventdata, handles) 741 801 742 802 %------------------------------------------------------------------------ … … 892 952 893 953 %------------------------------------------------------------------------ 894 % --- 'key_press_fcn:' function activated when a key is pressed on the keyboard895 function key_press_fcn(hObject,eventdata,handles)896 %------------------------------------------------------------------------897 xx=double(get(handles.geometry_calib,'CurrentCharacter')); %get the keyboard character898 if ismember(xx,[8 127])%backspace or delete899 Coord_cell=get(handles.ListCoord,'String');900 val=get(handles.ListCoord,'Value');901 if max(val)<numel(Coord_cell) % the last element '...' has not been selected902 Coord_cell(val)=[];%remove the selected line903 set(handles.ListCoord,'Value',min(val))904 set(handles.ListCoord,'String',Coord_cell)905 ListCoord_Callback(hObject, eventdata, handles)906 MenuPlot_Callback(hObject,eventdata,handles)907 end908 end909 910 %------------------------------------------------------------------------911 954 function MenuPlot_Callback(hObject, eventdata, handles) 912 955 %------------------------------------------------------------------------ … … 1050 1093 C = [l(7:8)' 1]; 1051 1094 1052 GeometryCalib.CalibrationType='tsai'; 1053 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 1054 GeometryCalib.f=1; 1055 GeometryCalib.dpx=1; 1056 GeometryCalib.dpy=1; 1057 GeometryCalib.sx=1; 1058 GeometryCalib.Cx=0; 1059 GeometryCalib.Cy=0; 1060 GeometryCalib.kappa1=0; 1061 GeometryCalib.Tx=Amat(1,3); 1062 GeometryCalib.Ty=Amat(2,3); 1063 GeometryCalib.Tz=1; 1095 %GeometryCalib.CalibrationType='tsai'; 1096 %GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 1097 % GeometryCalib.f=1; 1098 % GeometryCalib.dpx=1; 1099 % GeometryCalib.dpy=1; 1100 % GeometryCalib.sx=1; 1101 % GeometryCalib.Cx=0; 1102 % GeometryCalib.Cy=0; 1103 % GeometryCalib.kappa1=0; 1104 % GeometryCalib.Tx=Amat(1,3); 1105 % GeometryCalib.Ty=Amat(2,3); 1106 % GeometryCalib.Tz=1; 1107 % GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0]; 1108 % 1109 % [Amod,Rangx,Rangy]=phys_Ima(A-min(min(A)),GeometryCalib,0); 1110 1111 GeometryCalib.fx_fy=[1 1]; 1112 GeometryCalib.Tx_Ty_Tz=[Amat(1,3) Amat(2,3) 1]; 1064 1113 GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0]; 1065 1066 [Amod,Rangx,Rangy]=phys_Ima(A-min(min(A)),GeometryCalib,0); 1114 path_uvmat=which('uvmat');% check the path detected for source file uvmat 1115 path_UVMAT=fileparts(path_uvmat); %path to UVMAT 1116 addpath(fullfile(path_UVMAT,'transform_field')) 1117 Data.ListVarName={'AY','AX','A'}; 1118 Data.VarDimName={'AY','AX',{'AY','AX'}}; 1119 if ndims(A)==3 1120 A=mean(A,3); 1121 end 1122 Data.A=A-min(min(A)); 1123 Data.AY=[npxy(1)-0.5 0.5]; 1124 Data.AX=[0.5 npxy(2)]; 1125 Data.CoordType='px'; 1126 Calib.GeometryCalib=GeometryCalib; 1127 DataOut=phys(Data,Calib) 1128 rmpath(fullfile(path_UVMAT,'transform_field')) 1129 Amod=DataOut.A; 1130 Rangx=DataOut.AX; 1131 Rangy=DataOut.AY; 1132 % GeometryCalib.dpx=1; 1133 % GeometryCalib.dpy=1; 1134 % GeometryCalib.sx=1; 1135 % GeometryCalib.Cx=0; 1136 % GeometryCalib.Cy=0; 1137 % GeometryCalib.kappa1=0; 1138 % GeometryCalib.Tx=Amat(1,3); 1139 % GeometryCalib.Ty=Amat(2,3); 1140 % GeometryCalib.Tz=1; 1141 % GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0]; 1142 % 1143 % [Amod,Rangx,Rangy]=phys_Ima(A-min(min(A)),GeometryCalib,0); 1144 1067 1145 1068 1146 Amod=double(Amod); 1069 % figure(12) display corrected image1147 % figure(12) %display corrected image 1070 1148 % Amax=max(max(Amod)); 1071 1149 % image(Rangx,Rangy,uint8(255*Amod/Amax)) 1150 1072 1151 Dx=(Rangx(2)-Rangx(1))/(npxy(2)-1); %x mesh in real space 1073 1152 Dy=(Rangy(2)-Rangy(1))/(npxy(1)-1); %y mesh in real space 1074 ind_range_x=ceil( GeometryCalib.R(1,1)*CalibData.grid.Dx/3);% range of search of image ma around each point obtained by linear interpolation from the marked points1075 ind_range_y=ceil( GeometryCalib.R(2,2)*CalibData.grid.Dy/3);% range of search of image ma around each point obtained by linear interpolation from the marked points1153 ind_range_x=ceil(abs(GeometryCalib.R(1,1)*CalibData.grid.Dx/3))% range of search of image ma around each point obtained by linear interpolation from the marked points 1154 ind_range_y=ceil(abs(GeometryCalib.R(2,2)*CalibData.grid.Dy/3))% range of search of image ma around each point obtained by linear interpolation from the marked points 1076 1155 nbpoints=size(T,1); 1077 1156 for ipoint=1:nbpoints … … 1095 1174 x_shift=sum(Atop.*[-2 -1 0 1 2])/sum(Atop); 1096 1175 end 1097 if ind_ x_max+2<=numel(y_profile) && ind_y_max-2>=11176 if ind_y_max+2<=numel(y_profile) && ind_y_max-2>=1 1098 1177 Atop=y_profile(ind_y_max-2:ind_y_max+2); 1099 1178 y_shift=sum(Atop.*[-2 -1 0 1 2]')/sum(Atop); … … 1208 1287 %INPUT: 1209 1288 %Zindex: index of plane 1210 function [A_out,Rangx,Rangy]=phys_Ima(A,Calib,ZIndex)1211 % ------------------------------------------------------------------------1212 xcorner=[];1213 ycorner=[];1214 npx=[];1215 npy=[];1216 siz=size(A)1217 npx=[npx siz(2)];1218 npy=[npy siz(1)]1219 xima=[0.5 siz(2)-0.5 0.5 siz(2)-0.5];%image coordinates of corners1220 yima=[0.5 0.5 siz(1)-0.5 siz(1)-0.5];1221 [xcorner,ycorner]=phys_XYZ(Calib,xima,yima,ZIndex);%corresponding physical coordinates1222 Rangx(1)=min(xcorner);1223 Rangx(2)=max(xcorner);1224 Rangy(2)=min(ycorner);1225 Rangy(1)=max(ycorner);1226 test_multi=(max(npx)~=min(npx)) | (max(npy)~=min(npy));1227 npx=max(npx);1228 npy=max(npy);1229 x=linspace(Rangx(1),Rangx(2),npx);1230 y=linspace(Rangy(1),Rangy(2),npy);1231 [X,Y]=meshgrid(x,y);%grid in physical coordiantes1232 vec_B=[];1233 1234 zphys=0; %default1235 if isfield(Calib,'SliceCoord') %.Z= index of plane1236 SliceCoord=Calib.SliceCoord(ZIndex,:);1237 zphys=SliceCoord(3); %to generalize for non-parallel planes1238 end1239 [XIMA,YIMA]=px_XYZ(Calib,X,Y,zphys);%corresponding image indices for each point in the real space grid1240 XIMA=reshape(round(XIMA),1,npx*npy);%indices reorganized in 'line'1241 YIMA=reshape(round(YIMA),1,npx*npy);1242 flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image1243 testuint8=isa(A,'uint8');1244 testuint16=isa(A,'uint16');1245 if numel(siz)==2 %(B/W images)1246 vec_A=reshape(A,1,npx*npy);%put the original image in line1247 ind_in=find(flagin);1248 ind_out=find(~flagin);1249 ICOMB=((XIMA-1)*npy+(npy+1-YIMA));1250 ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A1251 vec_B(ind_in)=vec_A(ICOMB);1252 vec_B(ind_out)=zeros(size(ind_out));1253 A_out=reshape(vec_B,npy,npx);%new image in real coordinates1254 elseif numel(siz)==31255 for icolor=1:siz(3)1256 vec_A=reshape(A{icell}(:,:,icolor),1,npx*npy);%put the original image in line1257 ind_in=find(flagin);1258 ind_out=find(~flagin);1259 ICOMB=((XIMA-1)*npy+(npy+1-YIMA));1260 ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A1261 vec_B(ind_in)=vec_A(ICOMB);1262 vec_B(ind_out)=zeros(size(ind_out));1263 A_out(:,:,icolor)=reshape(vec_B,npy,npx);%new image in real coordinates1264 end1265 end1266 if testuint81267 A_out=uint8(A_out);1268 end1269 if testuint161270 A_out=uint16(A_out);1271 end1289 % function [A_out,Rangx,Rangy]=phys_Ima(A,Calib,ZIndex) 1290 % %------------------------------------------------------------------------ 1291 % xcorner=[]; 1292 % ycorner=[]; 1293 % npx=[]; 1294 % npy=[]; 1295 % siz=size(A) 1296 % npx=[npx siz(2)]; 1297 % npy=[npy siz(1)] 1298 % xima=[0.5 siz(2)-0.5 0.5 siz(2)-0.5];%image coordinates of corners 1299 % yima=[0.5 0.5 siz(1)-0.5 siz(1)-0.5]; 1300 % [xcorner,ycorner]=phys_XYZ(Calib,xima,yima,ZIndex);%corresponding physical coordinates 1301 % Rangx(1)=min(xcorner); 1302 % Rangx(2)=max(xcorner); 1303 % Rangy(2)=min(ycorner); 1304 % Rangy(1)=max(ycorner); 1305 % test_multi=(max(npx)~=min(npx)) | (max(npy)~=min(npy)); 1306 % npx=max(npx); 1307 % npy=max(npy); 1308 % x=linspace(Rangx(1),Rangx(2),npx); 1309 % y=linspace(Rangy(1),Rangy(2),npy); 1310 % [X,Y]=meshgrid(x,y);%grid in physical coordiantes 1311 % vec_B=[]; 1312 % 1313 % zphys=0; %default 1314 % if isfield(Calib,'SliceCoord') %.Z= index of plane 1315 % SliceCoord=Calib.SliceCoord(ZIndex,:); 1316 % zphys=SliceCoord(3); %to generalize for non-parallel planes 1317 % end 1318 % [XIMA,YIMA]=px_XYZ(Calib,X,Y,zphys);%corresponding image indices for each point in the real space grid 1319 % XIMA=reshape(round(XIMA),1,npx*npy);%indices reorganized in 'line' 1320 % YIMA=reshape(round(YIMA),1,npx*npy); 1321 % flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image 1322 % testuint8=isa(A,'uint8'); 1323 % testuint16=isa(A,'uint16'); 1324 % if numel(siz)==2 %(B/W images) 1325 % vec_A=reshape(A,1,npx*npy);%put the original image in line 1326 % ind_in=find(flagin); 1327 % ind_out=find(~flagin); 1328 % ICOMB=((XIMA-1)*npy+(npy+1-YIMA)); 1329 % ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A 1330 % vec_B(ind_in)=vec_A(ICOMB); 1331 % vec_B(ind_out)=zeros(size(ind_out)); 1332 % A_out=reshape(vec_B,npy,npx);%new image in real coordinates 1333 % elseif numel(siz)==3 1334 % for icolor=1:siz(3) 1335 % vec_A=reshape(A{icell}(:,:,icolor),1,npx*npy);%put the original image in line 1336 % ind_in=find(flagin); 1337 % ind_out=find(~flagin); 1338 % ICOMB=((XIMA-1)*npy+(npy+1-YIMA)); 1339 % ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A 1340 % vec_B(ind_in)=vec_A(ICOMB); 1341 % vec_B(ind_out)=zeros(size(ind_out)); 1342 % A_out(:,:,icolor)=reshape(vec_B,npy,npx);%new image in real coordinates 1343 % end 1344 % end 1345 % if testuint8 1346 % A_out=uint8(A_out); 1347 % end 1348 % if testuint16 1349 % A_out=uint16(A_out); 1350 % end 1272 1351 1273 1352 %------------------------------------------------------------------------ … … 1275 1354 %INPUT: 1276 1355 %Z: index of plane 1277 function [Xphys,Yphys,Zphys]=phys_XYZ(Calib,X,Y,Z)1278 % ------------------------------------------------------------------------1279 if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'SliceCoord')&length(Calib.SliceCoord)>=Z1280 Zindex=Z;1281 Zphys=Calib.SliceCoord(Zindex,3);%GENERALISER AUX CAS AVEC ANGLE1282 else1283 Zphys=0;1284 end1285 if ~exist('X','var')||~exist('Y','var')1286 Xphys=[];1287 Yphys=[];%default1288 return1289 end1290 Xphys=X;%default1291 Yphys=Y;1292 % image transform1293 if isfield(Calib,'R')1294 R=(Calib.R)';1295 Dx=R(5)*R(7)-R(4)*R(8);1296 Dy=R(1)*R(8)-R(2)*R(7);1297 D0=Calib.f*(R(2)*R(4)-R(1)*R(5));1298 Z11=R(6)*R(8)-R(5)*R(9);1299 Z12=R(2)*R(9)-R(3)*R(8);1300 Z21=R(4)*R(9)-R(6)*R(7);1301 Z22=R(3)*R(7)-R(1)*R(9);1302 Zx0=R(3)*R(5)-R(2)*R(6);1303 Zy0=R(1)*R(6)-R(3)*R(4);1304 A11=R(8)*Calib.Ty-R(5)*Calib.Tz+Z11*Zphys;1305 A12=R(2)*Calib.Tz-R(8)*Calib.Tx+Z12*Zphys;1306 A21=-R(7)*Calib.Ty+R(4)*Calib.Tz+Z21*Zphys;1307 A22=-R(1)*Calib.Tz+R(7)*Calib.Tx+Z11*Zphys;1308 X0=Calib.f*(R(5)*Calib.Tx-R(2)*Calib.Ty+Zx0*Zphys);1309 Y0=Calib.f*(-R(4)*Calib.Tx+R(1)*Calib.Ty+Zy0*Zphys);1310 %px to camera:1311 Xd=(Calib.dpx/Calib.sx)*(X-Calib.Cx); % sensor coordinates1312 Yd=Calib.dpy*(Y-Calib.Cy);1313 dist_fact=1+Calib.kappa1*(Xd.*Xd+Yd.*Yd); %distortion factor1314 Xu=dist_fact.*Xd;%undistorted sensor coordinates1315 Yu=dist_fact.*Yd;1316 denom=Dx*Xu+Dy*Yu+D0;1317 % denom2=denom.*denom;1318 Xphys=(A11.*Xu+A12.*Yu+X0)./denom;%world coordinates1319 Yphys=(A21.*Xu+A22.*Yu+Y0)./denom;1320 end1356 % function [Xphys,Yphys,Zphys]=phys_XYZ(Calib,X,Y,Z) 1357 % %------------------------------------------------------------------------ 1358 % if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'SliceCoord')&length(Calib.SliceCoord)>=Z 1359 % Zindex=Z; 1360 % Zphys=Calib.SliceCoord(Zindex,3);%GENERALISER AUX CAS AVEC ANGLE 1361 % else 1362 % Zphys=0; 1363 % end 1364 % if ~exist('X','var')||~exist('Y','var') 1365 % Xphys=[]; 1366 % Yphys=[];%default 1367 % return 1368 % end 1369 % Xphys=X;%default 1370 % Yphys=Y; 1371 % %image transform 1372 % if isfield(Calib,'R') 1373 % R=(Calib.R)'; 1374 % Dx=R(5)*R(7)-R(4)*R(8); 1375 % Dy=R(1)*R(8)-R(2)*R(7); 1376 % D0=Calib.f*(R(2)*R(4)-R(1)*R(5)); 1377 % Z11=R(6)*R(8)-R(5)*R(9); 1378 % Z12=R(2)*R(9)-R(3)*R(8); 1379 % Z21=R(4)*R(9)-R(6)*R(7); 1380 % Z22=R(3)*R(7)-R(1)*R(9); 1381 % Zx0=R(3)*R(5)-R(2)*R(6); 1382 % Zy0=R(1)*R(6)-R(3)*R(4); 1383 % A11=R(8)*Calib.Ty-R(5)*Calib.Tz+Z11*Zphys; 1384 % A12=R(2)*Calib.Tz-R(8)*Calib.Tx+Z12*Zphys; 1385 % A21=-R(7)*Calib.Ty+R(4)*Calib.Tz+Z21*Zphys; 1386 % A22=-R(1)*Calib.Tz+R(7)*Calib.Tx+Z11*Zphys; 1387 % X0=Calib.f*(R(5)*Calib.Tx-R(2)*Calib.Ty+Zx0*Zphys); 1388 % Y0=Calib.f*(-R(4)*Calib.Tx+R(1)*Calib.Ty+Zy0*Zphys); 1389 % %px to camera: 1390 % Xd=(Calib.dpx/Calib.sx)*(X-Calib.Cx); % sensor coordinates 1391 % Yd=Calib.dpy*(Y-Calib.Cy); 1392 % dist_fact=1+Calib.kappa1*(Xd.*Xd+Yd.*Yd); %distortion factor 1393 % Xu=dist_fact.*Xd;%undistorted sensor coordinates 1394 % Yu=dist_fact.*Yd; 1395 % denom=Dx*Xu+Dy*Yu+D0; 1396 % % denom2=denom.*denom; 1397 % Xphys=(A11.*Xu+A12.*Yu+X0)./denom;%world coordinates 1398 % Yphys=(A21.*Xu+A22.*Yu+Y0)./denom; 1399 % end 1321 1400 1322 1401 … … 1329 1408 [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); 1330 1409 GeometryCalib=s.GeometryCalib; 1331 GeometryCalib=load_calib(hObject, eventdata, handles)1410 %GeometryCalib=load_calib(hObject, eventdata, handles) 1332 1411 calib=reshape(GeometryCalib.PointCoord',[],1); 1333 1412 for ilist=1:numel(calib) … … 1350 1429 [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); 1351 1430 GeometryCalib=s.GeometryCalib; 1352 k=GeometryCalib.kappa1 * GeometryCalib.f*GeometryCalib.f; 1353 f1=GeometryCalib.f*GeometryCalib.sx/GeometryCalib.dpx; 1354 f2=GeometryCalib.f/GeometryCalib.dpy; 1355 Cx=GeometryCalib.Cx; 1356 Cy=GeometryCalib.Cy; 1357 set(handles.fx,'String',num2str(f1,'%1.1f')) 1358 set(handles.fy,'String',num2str(f2,'%1.1f')) 1359 set(handles.k,'String',num2str(k,'%1.4f')) 1360 set(handles.Cx,'String',num2str(Cx,'%1.1f')) 1361 set(handles.Cy,'String',num2str(Cy,'%1.1f')) 1431 display_intrinsic(GeometryCalib,handles) 1362 1432 1363 1433 % ----------------------------------------------------------------------- … … 1383 1453 1384 1454 %------------------------------------------------------------------------ 1455 % --- 'key_press_fcn:' function activated when a key is pressed on the keyboard 1456 function key_press_fcn(hObject,eventdata,handles) 1457 %------------------------------------------------------------------------ 1458 xx=double(get(handles.geometry_calib,'CurrentCharacter')); %get the keyboard character 1459 if ismember(xx,[8 127])%backspace or delete 1460 Coord_cell=get(handles.ListCoord,'String'); 1461 val=get(handles.ListCoord,'Value'); 1462 if max(val)<numel(Coord_cell) % the last element '...' has not been selected 1463 Coord_cell(val)=[];%remove the selected line 1464 set(handles.ListCoord,'Value',min(val)) 1465 set(handles.ListCoord,'String',Coord_cell) 1466 ListCoord_Callback(hObject, eventdata, handles) 1467 MenuPlot_Callback(hObject,eventdata,handles) 1468 end 1469 end 1470 1471 %------------------------------------------------------------------------ 1385 1472 function fileinput=browse_xml(hObject, eventdata, handles) 1386 1473 %------------------------------------------------------------------------ 1387 1474 fileinput=[];%default 1388 1475 oldfile=''; %default 1389 UserData=get(handles.geometry_calib,'UserData') ;1390 if isfield(UserData,'XmlInput ')1391 oldfile=UserData.XmlInput ;1476 UserData=get(handles.geometry_calib,'UserData') 1477 if isfield(UserData,'XmlInputFile') 1478 oldfile=UserData.XmlInputFile; 1392 1479 end 1393 1480 [FileName, PathName, filterindex] = uigetfile( ... … … 1404 1491 sizf=size(fileinput); 1405 1492 if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end 1406 UserData.XmlInput =fileinput;1493 UserData.XmlInputFile=fileinput; 1407 1494 set(handles.geometry_calib,'UserData',UserData)%record current file foer further use of browser 1408 1495 … … 1411 1498 %------------------------------------------------------------------------ 1412 1499 [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); 1413 GeometryCalib=s.GeometryCalib; 1414 if isempty(GeometryCalib) 1415 Tabchar={}; 1416 CoordCell={}; 1417 k=0;%default 1418 f1=1000; 1419 f2=1000; 1420 hhuvmat=guidata(findobj(allchild(0),'Name','uvmat')); 1421 Cx=str2num(get(hhuvmat.npx,'String'))/2; 1422 Cy=str2num(get(hhuvmat.npy,'String'))/2; 1423 else 1424 k=GeometryCalib.kappa1 * GeometryCalib.f*GeometryCalib.f; 1425 f1=GeometryCalib.f*GeometryCalib.sx/GeometryCalib.dpx; 1426 f2=GeometryCalib.f/GeometryCalib.dpy; 1427 Cx=GeometryCalib.Cx; 1428 Cy=GeometryCalib.Cy; 1429 set(handles.fx,'String',num2str(f1,'%1.1f')) 1430 set(handles.fy,'String',num2str(f2,'%1.1f')) 1431 set(handles.k,'String',num2str(k,'%1.4f')) 1432 set(handles.Cx,'String',num2str(Cx,'%1.1f')) 1433 set(handles.Cy,'String',num2str(Cy,'%1.1f')) 1500 GeometryCalib=s.GeometryCalib 1501 fx=1;fy=1;Cx=0;Cy=0;kc=0; %default 1502 % Tabchar={}; 1503 CoordCell={}; 1504 % kc=0;%default 1505 % f1=1000; 1506 % f2=1000; 1507 % hhuvmat=guidata(findobj(allchild(0),'Name','uvmat')); 1508 % Cx=str2num(get(hhuvmat.npx,'String'))/2; 1509 % Cy=str2num(get(hhuvmat.npy,'String'))/2; 1510 Tabchar={};%default 1511 val_cal=1;%default 1512 if ~isempty(GeometryCalib) 1513 % choose the calibration option 1514 if isfield(GeometryCalib,'CalibrationType') 1515 calib_list=get(handles.calib_type,'String'); 1516 for ilist=1:numel(calib_list) 1517 if strcmp(calib_list{ilist},GeometryCalib.CalibrationType) 1518 val_cal=ilist; 1519 break 1520 end 1521 end 1522 end 1523 display_intrinsic(GeometryCalib,handles)%intrinsic param 1524 %extrinsic param 1525 if isfield(GeometryCalib,'Tx_Ty_Tz') 1526 Tx_Ty_Tz=GeometryCalib.Tx_Ty_Tz; 1527 set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) 1528 set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) 1529 set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) 1530 end 1531 if isfield(GeometryCalib,'omc') 1532 set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) 1533 set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) 1534 set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) 1535 end 1434 1536 calib=reshape(GeometryCalib.PointCoord',[],1); 1435 1537 for ilist=1:numel(calib) … … 1438 1540 CoordCell=reshape(CoordCell,[],5); 1439 1541 Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display 1440 set(handles.ListCoord,'Value',1)1441 set(handles.ListCoord,'String',Tabchar)1442 1542 MenuPlot_Callback(handles.geometry_calib, [], handles) 1443 1543 end 1544 set(handles.calib_type,'Value',val_cal) 1444 1545 Tabchar=[Tabchar;{'......'}]; 1546 set(handles.ListCoord,'Value',1) 1547 set(handles.ListCoord,'String',Tabchar) 1548 1445 1549 if isempty(CoordCell)% allow mouse action by default in the absence of input points 1446 1550 set(handles.edit_append,'Value',1) … … 1451 1555 end 1452 1556 1453 1454 1455 1456 1457 % -------------------------------------------------------------------- 1458 % --- Executes on button press in CLEAR_PTS: clear the list of calibration points 1459 function CLEAR_PTS_Callback(hObject, eventdata, handles) 1460 % -------------------------------------------------------------------- 1461 set(handles.ListCoord,'Value',1)% refresh the display of coordinates 1462 set(handles.ListCoord,'String',{'......'}) 1463 1557 %------------------------------------------------------------------------ 1558 %---display calibration intrinsic parameters 1559 function display_intrinsic(GeometryCalib,handles) 1560 %------------------------------------------------------------------------ 1561 fx=[]; 1562 fy=[]; 1563 if isfield(GeometryCalib,'fx_fy') 1564 fx=GeometryCalib.fx_fy(1); 1565 fy=GeometryCalib.fx_fy(2); 1566 end 1567 Cx_Cy=[0 0];%default 1568 if isfield(GeometryCalib,'Cx_Cy') 1569 Cx_Cy=GeometryCalib.Cx_Cy; 1570 end 1571 kc=0; 1572 if isfield(GeometryCalib,'kc') 1573 kc=GeometryCalib.kc %* GeometryCalib.focal*GeometryCalib.focal; 1574 end 1575 set(handles.fx,'String',num2str(fx,5)) 1576 set(handles.fy,'String',num2str(fy,5)) 1577 set(handles.Cx,'String',num2str(Cx_Cy(1),'%1.1f')) 1578 set(handles.Cy,'String',num2str(Cx_Cy(2),'%1.1f')) 1579 set(handles.kc,'String',num2str(kc,'%1.4f')) 1580 1581 -
trunk/src/imadoc2struct.m
r109 r114 118 118 cont=get(subt,1,'contents'); 119 119 if ~isempty(cont) 120 uid_pixcmx=find(subt,'/GeometryCalib/Pxcmx');121 uid_pixcmy=find(subt,'/GeometryCalib/Pxcmy');122 if ~isempty(uid_pixcmx) && ~isempty(uid_pixcmy)%NON UTILISE123 pixcmx=str2num(get(subt,children(subt,uid_pixcmx),'value'));124 if isempty(pixcmx),pixcmx=1;end; %default125 pixcmy=str2num(get(subt,children(subt,uid_pixcmy),'value'));126 if isempty(pixcmy),pixcmy=1;end; %default127 tsai.Pxcmx=pixcmx;128 tsai.Pxcmy=pixcmy;129 end120 % uid_pixcmx=find(subt,'/GeometryCalib/Pxcmx'); 121 % uid_pixcmy=find(subt,'/GeometryCalib/Pxcmy'); 122 % if ~isempty(uid_pixcmx) && ~isempty(uid_pixcmy)%NON UTILISE 123 % pixcmx=str2num(get(subt,children(subt,uid_pixcmx),'value')); 124 % if isempty(pixcmx),pixcmx=1;end; %default 125 % pixcmy=str2num(get(subt,children(subt,uid_pixcmy),'value')); 126 % if isempty(pixcmy),pixcmy=1;end; %default 127 % tsai.Pxcmx=pixcmx; 128 % tsai.Pxcmy=pixcmy; 129 % end 130 130 %default values: 131 tsai.f=1; 132 tsai.dpx=1; 133 tsai.dpy=1; 134 tsai.sx=1; 135 tsai.Cx=0; 136 tsai.Cy=0; 137 tsai.Tz=1; 138 tsai.Tx=0; 139 tsai.Ty=0; 140 tsai.R=[1 0 0; 0 1 0; 0 0 0]; 141 tsai.kappa1=0; 131 %tsai.dpx_dpy=1; 132 %tsai.dpy=1; 133 %tsai.sx=1; 134 % tsai.Cx_Cy=[0 0]; 135 % tsai.Cy=0; 136 % tsai.Tx_Ty_Tz=[0 0 1]; 137 % tsai.Tx=0; 138 % tsai.Ty=0; 139 % tsai.R=[1 0 0; 0 1 0; 0 0 0]; 140 uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType'); 141 if isequal(length(uid_CalibrationType),1) 142 tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value'); 143 end 142 144 uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit'); 143 if ~isempty(uid_CoordUnit)145 if isequal(length(uid_CoordUnit),1) 144 146 tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value'); 145 147 end 146 uid_focal=find(subt,'/GeometryCalib/focal'); 147 uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy'); 148 uid_sx=find(subt,'/GeometryCalib/sx'); 148 uid_fx_fy=find(subt,'/GeometryCalib/fx_fy'); 149 focal=[];%default fro old convention (Reg Wilson) 150 if isequal(length(uid_fx_fy),1) 151 tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value')); 152 else %old convention (Reg Wilson) 153 uid_focal=find(subt,'/GeometryCalib/focal'); 154 uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy'); 155 uid_sx=find(subt,'/GeometryCalib/sx'); 156 if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx) 157 dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value')); 158 sx=str2num(get(subt,children(subt,uid_sx),'value')); 159 focal=str2num(get(subt,children(subt,uid_focal),'value')); 160 tsai.fx_fy(1)=sx*focal/dpx_dpy(1); 161 tsai.fx_fy(2)=focal/dpx_dpy(2); 162 end 163 end 149 164 uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy'); 150 uid_kappa1=find(subt,'/GeometryCalib/kappa1'); 165 if ~isempty(uid_Cx_Cy) 166 tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value')); 167 end 168 uid_kc=find(subt,'/GeometryCalib/kc'); 169 if ~isempty(uid_kc) 170 tsai.kc=str2num(get(subt,children(subt,uid_kc),'value')); 171 else %old convention (Reg Wilson) 172 uid_kappa1=find(subt,'/GeometryCalib/kappa1'); 173 if ~isempty(uid_kappa1)&& ~isempty(focal) 174 kappa1=str2num(get(subt,children(subt,uid_kappa1),'value')); 175 tsai.kc=-kappa1*focal*focal; 176 end 177 end 151 178 uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz'); 179 if ~isempty(uid_Tx_Ty_Tz) 180 tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value')); 181 end 152 182 uid_R=find(subt,'/GeometryCalib/R'); 153 if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_Cx_Cy)154 tsai.f=str2num(get(subt,children(subt,uid_focal),'value'));155 dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));156 tsai.dpx=dpx_dpy(1);157 tsai.dpy=dpx_dpy(2);158 if ~isempty(uid_sx)159 tsai.sx=str2num(get(subt,children(subt,uid_sx),'value'));160 end161 Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));162 tsai.Cx=Cx_Cy(1);163 tsai.Cy=Cx_Cy(2);164 end165 if ~isempty(uid_Tx_Ty_Tz)166 Tx_Ty_T_char=get(subt,children(subt,uid_Tx_Ty_Tz),'value');167 Tx_Ty_Tz=str2num(Tx_Ty_T_char);168 tsai.Tx=Tx_Ty_Tz(1);169 tsai.Ty=Tx_Ty_Tz(2);170 tsai.Tz=Tx_Ty_Tz(3);171 end172 183 if ~isempty(uid_R) 173 184 RR=get(subt,children(subt,uid_R),'value'); … … 176 187 end 177 188 end 178 if ~isempty(uid_kappa1) 179 tsai.kappa1=str2num(get(subt,children(subt,uid_kappa1),'value')); 180 end 189 181 190 %look for laser plane definitions 182 191 uid_Angle=find(subt,'/GeometryCalib/PlaneAngle'); … … 203 212 tsai.NbSlice=str2double(NbSlice); 204 213 end 205 tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ* [0:NbSlice-1]'*[0 0 1];214 tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1]; 206 215 end 207 216 end -
trunk/src/px_XYZ.m
r109 r114 11 11 12 12 function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys) 13 X=[];%default14 Y=[];15 13 % if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'PlanePos')&length(Calib.PlanePos)>=Z 16 14 % Zindex=Z; … … 23 21 Zphys=0; 24 22 end 25 if ~isfield(Calib,'f ')26 Calib.f=1;23 if ~isfield(Calib,'fx_fy') 24 Calib.fx_fy=[1 1]; 27 25 end 28 if ~isfield(Calib,' kappa1')29 Calib.kappa1=0;26 if ~isfield(Calib,'Tx_Ty_Tz') 27 Calib.Tx_Ty_Tz=[0 0 1]; 30 28 end 31 if ~isfield(Calib,'sx') 32 Calib.sx=1; 33 end 34 if ~isfield(Calib,'dpx') 35 Calib.dpx=1; 36 end 37 if ~isfield(Calib,'dpy') 38 Calib.dpy=1; 39 end 40 if ~isfield(Calib,'Cx') 41 Calib.Cx=0; 42 end 43 if ~isfield(Calib,'Cy') 44 Calib.Cy=0; 45 end 29 % if ~isfield(Calib,'kappa1') 30 % Calib.kappa1=0; 31 % end 32 % if ~isfield(Calib,'sx') 33 % Calib.sx=1; 34 % end 35 % if ~isfield(Calib,'dpx') 36 % Calib.dpx=1; 37 % end 38 % if ~isfield(Calib,'dpy') 39 % Calib.dpy=1; 40 % end 41 46 42 %%%%%%%%%%%%% 47 43 if isfield(Calib,'R') 48 44 R=(Calib.R)'; 49 xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx; 50 yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Ty; 51 zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tz; 45 %camera coordinates 46 xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx_Ty_Tz(1); 47 yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Tx_Ty_Tz(2); 48 zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tx_Ty_Tz(3); 52 49 %undistorted image coordinates 53 Xu=Calib.f*xc./zc; 54 Yu=Calib.f*yc./zc; 55 %distorted image coordinates 56 distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR 57 % distortion=1; 58 Xd=Xu./distortion; 59 Yd=Yu./distortion; 50 Xu=xc./zc; 51 Yu=yc./zc; 52 %radial quadratic correction factor 53 if ~isfield(Calib,'kc') 54 r2=1; %no quadratic distortion 55 else 56 r2=1+Calib.kc*(Xu.*Xu+Yu.*Yu); 57 end 60 58 %pixel coordinates 61 X=Xd*Calib.sx/Calib.dpx+Calib.Cx; 62 Y=Yd/Calib.dpy+Calib.Cy; 63 64 elseif isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib 65 X=Xphys*Calib.Pxcmx; 66 Y=Yphys*Calib.Pxcmy; 59 if ~isfield(Calib,'Cx_Cy') 60 Calib.Cx_Cy=[0 0];%default value 61 end 62 X=Calib.fx_fy(1)*Xu.*r2+Calib.Cx_Cy(1); 63 Y=Calib.fx_fy(2)*Yu.*r2+Calib.Cx_Cy(2); 64 %OLD CONVENTION (Wilson)undistorted image coordinates 65 % Xu=Calib.f*xc./zc; 66 % Yu=Calib.f*yc./zc; 67 % %distorted image coordinates 68 % distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR 69 % % distortion=1; 70 % Xd=Xu./distortion; 71 % Yd=Yu./distortion; 72 % %pixel coordinates 73 % X=Xd*Calib.sx/Calib.dpx+Calib.Cx; 74 % Y=Yd/Calib.dpy+Calib.Cy; 75 else %case 'rescale' 76 X=Calib.fx_fy(1)*(Xphys+Calib.Tx_Ty_Tz(1)); 77 Y=Calib.fx_fy(2)*(Yphys+Calib.Tx_Ty_Tz(2)); 67 78 end 68 79 -
trunk/src/update_imadoc.m
r84 r114 7 7 % outputfile: xml file to modify 8 8 %------------------------------------------------------------- 9 function update_imadoc(GeometryCalib,outputfile) 9 function errormsg=update_imadoc(GeometryCalib,outputfile) 10 errormsg=''; 10 11 testappend=0; 11 12 if exist(outputfile,'file');%=1 if the output file already exists, 0 else … … 19 20 end 20 21 [success,message]=copyfile(outputfile,backupfile);%make backup 22 if success==0 23 errormsg=message 24 end 21 25 uid=find(t,'ImaDoc'); 22 26 if ~isequal(uid,1) 23 27 return 24 end 25 28 end 26 29 %if the xml file is ImaDoc 27 30 uid_calib=find(t,'ImaDoc/GeometryCalib'); -
trunk/src/uvmat.m
r105 r114 815 815 set(handles.pxcm,'String','var') 816 816 set(handles.pycm,'String','var') 817 else 818 pixcmx=GeometryCalib.f *GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);819 pixcmy=GeometryCalib.f *GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);817 elseif isfield(GeometryCalib,'fx_fy') 818 pixcmx=GeometryCalib.fx_fy(1)%*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx); 819 pixcmy=GeometryCalib.fx_fy(2)%*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy); 820 820 set(handles.pxcm,'String',num2str(pixcmx)) 821 821 set(handles.pycm,'String',num2str(pixcmy)) … … 4736 4736 imwrite(imflag,answer,'BitDepth',8); 4737 4737 end 4738 set( list_object_1,'Value',1)4739 set( list_object_1,'Max',1)4738 set(handles.list_object_1,'Value',1) 4739 set(handles.list_object_1,'Max',1) 4740 4740 % end 4741 4741 end
Note: See TracChangeset
for help on using the changeset viewer.