Changeset 1001 for trunk/src/geometry_calib.m
- Timestamp:
- Feb 27, 2017, 9:28:27 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/geometry_calib.m
r993 r1001 168 168 % --- Executes on button press APPLY (used to launch the calibration). 169 169 function APPLY_Callback(hObject, eventdata, handles) 170 set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points) 171 170 172 %------------------------------------------------------------------------ 171 173 %% look for the GUI uvmat and check for an image as input … … 173 175 huvmat=findobj(allchild(0),'Name','uvmat');% look for the GUI uvmat 174 176 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat 177 if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on') 178 msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration') 179 return 180 end 175 181 176 182 RootPath=''; … … 186 192 outputfile=answer{1}; 187 193 end 188 [GeometryCalib,index]=calibrate(handles,hhuvmat);% apply calibration 194 195 %% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image 196 Coord=get(handles.ListCoord,'Data'); 197 198 199 %% read the type of calibration 200 calib_cell=get(handles.calib_type,'String'); 201 val=get(handles.calib_type,'Value'); 202 CalibFcn=['calib_' calib_cell{val}]; 203 204 %% read the intrinsic parameters 205 Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String')); 206 Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String')); 207 Intrinsic.coord_files=get(handles.ListCoordFiles,'String'); 208 Intrinsic.f1=str2num(get(handles.fx,'String')); 209 Intrinsic.f2=str2num(get(handles.fy,'String')); 210 Intrinsic.k=str2num(get(handles.kc,'String')); 211 Intrinsic.Cx=str2num(get(handles.Cx,'String')); 212 Intrinsic.Cy=str2num(get(handles.Cy,'String')); 213 if isempty(Intrinsic.k) 214 Intrinsic.k=0; 215 end 216 if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy) 217 Intrinsic.Cx=Intrinsic.Npx/2; 218 Intrinsic.Cy=Intrinsic.Npy/2; 219 end 220 221 %% Apply calibration 222 [GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration 223 224 %% record the coordinate unit 225 unitlist=get(handles.CoordUnit,'String'); 226 unit=unitlist{get(handles.CoordUnit,'value')}; 227 GeometryCalib.CoordUnit=unit; 228 229 %% record the coordinates of the calibration points 230 GeometryCalib.SourceCalib.PointCoord=Coord; 231 232 %% display calibration results on the GUI geometry_calib 233 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters 234 display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters 235 % (rotation and translation of camera with respect to the phys coordinates) 236 237 %% store the calibration data, by default in the xml file of the currently displayed image 238 answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';... 239 ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];... 240 ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']}); 241 if strcmp(answer,'Yes') %store the calibration data 242 if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration 243 msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'}) 244 GeometryCalib.SliceCoord=Z_plane'*[0 0 1]; 245 end 246 else 247 GeometryCalib=[]; 248 index=1; 249 end 189 250 190 251 if isempty(GeometryCalib) % if calibration cancelled … … 228 289 function REPLICATE_Callback(hObject, eventdata, handles) 229 290 %------------------------------------------------------------------------ 291 set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points) 230 292 231 293 %% look for the GUI uvmat and check for an image as input 232 294 huvmat=findobj(allchild(0),'Name','uvmat'); 233 295 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat 234 GeometryCalib=calibrate(handles,hhuvmat);% apply calibration 296 297 %% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image 298 Coord=get(handles.ListCoord,'Data'); 299 300 %% read the type of calibration 301 calib_cell=get(handles.calib_type,'String'); 302 val=get(handles.calib_type,'Value'); 303 CalibFcn=['calib_' calib_cell{val}]; 304 305 %% read the intrinsic parameters 306 Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String')); 307 Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String')); 308 Intrinsic.coord_files=get(handles.ListCoordFiles,'String'); 309 Intrinsic.f1=str2num(get(handles.fx,'String')); 310 Intrinsic.f2=str2num(get(handles.fy,'String')); 311 Intrinsic.k=str2num(get(handles.kc,'String')); 312 Intrinsic.Cx=str2num(get(handles.Cx,'String')); 313 Intrinsic.Cy=str2num(get(handles.Cy,'String')); 314 if isempty(Intrinsic.k) 315 Intrinsic.k=0; 316 end 317 if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy) 318 Intrinsic.Cx=Intrinsic.Npx/2; 319 Intrinsic.Cy=Intrinsic.Npy/2; 320 end 321 322 %% apply to cropped images if requested 323 answer=msgbox_uvmat('INPUT_Y-N','apply to cropped images?'); 324 if strcmp(answer,'Yes') 325 prompt = {'npy_lower'}; 326 dlg_title = 'remove image the npy_lower image lines (removal of the upper linedoes not change calibration)'; 327 num_lines= 1; 328 def = {'0'}; 329 answer = inputdlg(prompt,dlg_title,num_lines,def); 330 npy_crop=str2num(answer{1}); 331 Intrinsic.Npy=Intrinsic.Npy-npy_crop; %size of the filtering window 332 Coord(:,5)=Coord(:,5)-npy_crop;% shift the image ordinates of the calibration points by removing the lower band 333 end 334 335 %% Apply calibration 336 [GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration 337 338 339 %% record the coordinate unit 340 unitlist=get(handles.CoordUnit,'String'); 341 unit=unitlist{get(handles.CoordUnit,'value')}; 342 GeometryCalib.CoordUnit=unit; 343 344 %% record the coordinates of the calibration points 345 GeometryCalib.SourceCalib.PointCoord=Coord; 346 347 %% display calibration results on the GUI geometry_calib 348 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters 349 display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters 350 % (rotation and translation of camera with respect to the phys coordinates) 351 352 %% store the calibration data, by default in the xml file of the currently displayed image 353 answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';... 354 ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];... 355 ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']}); 356 if strcmp(answer,'Yes') %store the calibration data 357 if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration 358 msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'}) 359 GeometryCalib.SliceCoord=Z_plane'*[0 0 1]; 360 end 361 else 362 GeometryCalib=[]; 363 index=1; 364 end 235 365 236 366 %% open the GUI browse_data … … 265 395 %------------------------------------------------------------------------ 266 396 % --- activate calibration and store parameters in ouputfile . 267 function [GeometryCalib,index]=calibrate(handles,hhuvmat) 268 %------------------------------------------------------------------------ 269 set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points) 270 %% read the current calibration points 397 function [GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic) 398 %------------------------------------------------------------------------ 399 271 400 index=[]; 272 Coord=get(handles.ListCoord,'Data'); 273 Coord(:,6)=[]; 401 274 402 % apply the calibration, whose type is selected in handles.calib_type 275 GeometryCalib=[];276 403 if ~isempty(Coord) 277 calib_cell=get(handles.calib_type,'String'); 278 val=get(handles.calib_type,'Value'); 279 GeometryCalib=feval(['calib_' calib_cell{val}],Coord,handles); 404 GeometryCalib=feval(CalibFcn,Coord,Intrinsic); 280 405 else 406 GeometryCalib=[]; 281 407 msgbox_uvmat('ERROR','No calibration points, abort') 282 408 end … … 306 432 end 307 433 end 308 %set the coordinate unit309 unitlist=get(handles.CoordUnit,'String');310 unit=unitlist{get(handles.CoordUnit,'value')};311 GeometryCalib.CoordUnit=unit;312 %record the points313 GeometryCalib.SourceCalib.PointCoord=Coord;314 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters315 316 % Display extrinsinc parameters (rotation and translation of camera with respect to the phys coordiantes)317 set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4))318 set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4))319 set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4))320 set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4))321 set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4))322 set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))323 324 %% store the calibration data, by default in the xml file of the currently displayed image325 answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...326 ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...327 ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});328 if strcmp(answer,'Yes') %store the calibration data329 if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration330 msgbox_uvmat('CONFIRMATION',{['The current image series is assumed by default in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be modified by MenuSetSlice in the upper bar menu of uvmat'})331 GeometryCalib.SliceCoord=Z_plane'*[0 0 1];332 end333 334 else335 GeometryCalib=[];336 index=1;337 end338 434 339 435 340 436 %------------------------------------------------------------------------ 341 437 % --- determine the parameters for a calibration by an affine function (rescaling and offset, no rotation) 342 function GeometryCalib=calib_rescale(Coord, handles)438 function GeometryCalib=calib_rescale(Coord,Intrinsic) 343 439 %------------------------------------------------------------------------ 344 440 X=Coord(:,1); … … 358 454 %------------------------------------------------------------------------ 359 455 % --- determine the parameters for a calibration by a linear transform matrix (rescale and rotation) 360 function GeometryCalib=calib_linear(Coord, handles)456 function GeometryCalib=calib_linear(Coord,Intrinsic) 361 457 %------------------------------------------------------------------------ 362 458 X=Coord(:,1); … … 388 484 % --- determine the tsai parameters for a view normal to the grid plane 389 485 % NOT USED 390 function GeometryCalib=calib_normal(Coord, handles)486 function GeometryCalib=calib_normal(Coord,Intrinsic) 391 487 %------------------------------------------------------------------------ 392 488 Calib.f1=str2num(get(handles.fx,'String')); … … 451 547 452 548 %------------------------------------------------------------------------ 453 function GeometryCalib=calib_3D_linear(Coord,handles) 454 %------------------------------------------------------------------------ 455 path_uvmat=which('uvmat');% check the path detected for source file uvmat 456 path_UVMAT=fileparts(path_uvmat); %path to UVMAT 457 huvmat=findobj(allchild(0),'Tag','uvmat'); 458 hhuvmat=guidata(huvmat); 459 coord_files=get(handles.ListCoordFiles,'String'); 460 if ischar(coord_files) 549 function GeometryCalib=calib_3D_linear(Coord,Intrinsic) 550 %------------------------------------------------------------------------ 551 coord_files=Intrinsic.coord_files; 552 if ischar(Intrinsic.coord_files) 461 553 coord_files={coord_files}; 462 554 end … … 466 558 %retrieve the calibration points stored in the files listed in the popup list ListCoordFiles 467 559 x_1=Coord(:,4:5)';%px coordinates of the ref points 468 if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on') 469 msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration') 470 return 471 end 472 nx=str2num(get(hhuvmat.num_Npx,'String')); 473 ny=str2num(get(hhuvmat.num_Npy,'String')); 560 561 nx=Intrinsic.Npx; 562 ny=Intrinsic.Npy; 474 563 x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates 475 564 X_1=Coord(:,1:3)';%phys coordinates of the ref points … … 1221 1310 set(handles.kc,'String',num2str(kc,'%1.4f')) 1222 1311 1223 1224 % --- Executes when user attempts to close geometry_calib. 1312 %------------------------------------------------------------------------ 1313 % ---display calibration extrinsic parameters 1314 function display_extrinsic(GeometryCalib,handles) 1315 %------------------------------------------------------------------------ 1316 set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) 1317 set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) 1318 set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) 1319 set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) 1320 set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) 1321 set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) 1322 1323 %------------------------------------------------------------------------ 1324 % --- executes when user attempts to close geometry_calib. 1225 1325 function geometry_calib_CloseRequestFcn(hObject, eventdata, handles) 1226 1326 %------------------------------------------------------------------------ 1227 1327 delete(hObject); % closes the figure 1228 1328 1229 1329 %------------------------------------------------------------------------ 1230 % --- Executes on button press in PLOT.1330 % --- executes on button press in PLOT. 1231 1331 %------------------------------------------------------------------------ 1232 1332 function PLOT_Callback(hObject, eventdata, handles)
Note: See TracChangeset
for help on using the changeset viewer.