Ignore:
Timestamp:
Feb 27, 2017, 9:28:27 AM (7 years ago)
Author:
sommeria
Message:

tubcorrelation added, compilation improved to accept tranform fct

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/geometry_calib.m

    r993 r1001  
    168168% --- Executes on button press APPLY (used to launch the calibration).
    169169function APPLY_Callback(hObject, eventdata, handles)
     170set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
     171
    170172%------------------------------------------------------------------------
    171173%% look for the GUI uvmat and check for an image as input
     
    173175huvmat=findobj(allchild(0),'Name','uvmat');% look for the GUI uvmat
    174176hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
     177if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
     178    msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
     179  return
     180end
    175181
    176182RootPath='';
     
    186192    outputfile=answer{1};
    187193end
    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
     196Coord=get(handles.ListCoord,'Data');
     197
     198 
     199%% read the type of calibration
     200calib_cell=get(handles.calib_type,'String');
     201val=get(handles.calib_type,'Value');
     202CalibFcn=['calib_' calib_cell{val}];
     203
     204%% read the intrinsic parameters
     205Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String'));
     206Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
     207Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
     208Intrinsic.f1=str2num(get(handles.fx,'String'));
     209Intrinsic.f2=str2num(get(handles.fy,'String'));
     210Intrinsic.k=str2num(get(handles.kc,'String'));
     211Intrinsic.Cx=str2num(get(handles.Cx,'String'));
     212Intrinsic.Cy=str2num(get(handles.Cy,'String'));
     213if isempty(Intrinsic.k)
     214    Intrinsic.k=0;
     215end
     216if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
     217    Intrinsic.Cx=Intrinsic.Npx/2;
     218    Intrinsic.Cy=Intrinsic.Npy/2;
     219end 
     220
     221%% Apply calibration
     222[GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
     223
     224%% record the coordinate unit
     225unitlist=get(handles.CoordUnit,'String');
     226unit=unitlist{get(handles.CoordUnit,'value')};
     227GeometryCalib.CoordUnit=unit;
     228
     229%% record the coordinates of the calibration points
     230GeometryCalib.SourceCalib.PointCoord=Coord;
     231
     232%% display calibration results on the GUI geometry_calib
     233display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
     234display_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
     238answer=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']});
     241if 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   
     246else
     247    GeometryCalib=[];
     248    index=1;
     249end
    189250
    190251if isempty(GeometryCalib) % if calibration cancelled
     
    228289function REPLICATE_Callback(hObject, eventdata, handles)
    229290%------------------------------------------------------------------------
     291set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
    230292
    231293%% look for the GUI uvmat and check for an image as input
    232294huvmat=findobj(allchild(0),'Name','uvmat');
    233295hhuvmat=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
     298Coord=get(handles.ListCoord,'Data');
     299 
     300%% read the type of calibration
     301calib_cell=get(handles.calib_type,'String');
     302val=get(handles.calib_type,'Value');
     303CalibFcn=['calib_' calib_cell{val}];
     304
     305%% read the intrinsic parameters
     306Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String'));
     307Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
     308Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
     309Intrinsic.f1=str2num(get(handles.fx,'String'));
     310Intrinsic.f2=str2num(get(handles.fy,'String'));
     311Intrinsic.k=str2num(get(handles.kc,'String'));
     312Intrinsic.Cx=str2num(get(handles.Cx,'String'));
     313Intrinsic.Cy=str2num(get(handles.Cy,'String'));
     314if isempty(Intrinsic.k)
     315    Intrinsic.k=0;
     316end
     317if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
     318    Intrinsic.Cx=Intrinsic.Npx/2;
     319    Intrinsic.Cy=Intrinsic.Npy/2;
     320end
     321
     322%% apply to cropped images if requested
     323answer=msgbox_uvmat('INPUT_Y-N','apply to cropped images?');
     324if 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
     333end
     334
     335%% Apply calibration
     336[GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
     337
     338
     339%% record the coordinate unit
     340unitlist=get(handles.CoordUnit,'String');
     341unit=unitlist{get(handles.CoordUnit,'value')};
     342GeometryCalib.CoordUnit=unit;
     343
     344%% record the coordinates of the calibration points
     345GeometryCalib.SourceCalib.PointCoord=Coord;
     346
     347%% display calibration results on the GUI geometry_calib
     348display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
     349display_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
     353answer=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']});
     356if 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   
     361else
     362    GeometryCalib=[];
     363    index=1;
     364end
    235365
    236366%% open the GUI browse_data
     
    265395%------------------------------------------------------------------------
    266396% --- 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
     397function [GeometryCalib,index,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic)
     398%------------------------------------------------------------------------
     399
    271400index=[];
    272 Coord=get(handles.ListCoord,'Data');
    273 Coord(:,6)=[];
     401
    274402% apply the calibration, whose type is selected in  handles.calib_type
    275 GeometryCalib=[];
    276403if ~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);
    280405else
     406    GeometryCalib=[];
    281407    msgbox_uvmat('ERROR','No calibration points, abort')
    282408end
     
    306432    end
    307433end
    308 %set the coordinate unit
    309 unitlist=get(handles.CoordUnit,'String');
    310 unit=unitlist{get(handles.CoordUnit,'value')};
    311 GeometryCalib.CoordUnit=unit;
    312 %record the points
    313 GeometryCalib.SourceCalib.PointCoord=Coord;
    314 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
    315 
    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 image
    325 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 data
    329     if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
    330         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     end
    333    
    334 else
    335     GeometryCalib=[];
    336     index=1;
    337 end
    338434
    339435
    340436%------------------------------------------------------------------------
    341437% --- determine the parameters for a calibration by an affine function (rescaling and offset, no rotation)
    342 function GeometryCalib=calib_rescale(Coord,handles)
     438function GeometryCalib=calib_rescale(Coord,Intrinsic)
    343439%------------------------------------------------------------------------
    344440X=Coord(:,1);
     
    358454%------------------------------------------------------------------------
    359455% --- determine the parameters for a calibration by a linear transform matrix (rescale and rotation)
    360 function GeometryCalib=calib_linear(Coord,handles)
     456function GeometryCalib=calib_linear(Coord,Intrinsic)
    361457%------------------------------------------------------------------------
    362458X=Coord(:,1);
     
    388484% --- determine the tsai parameters for a view normal to the grid plane
    389485% NOT USED
    390 function GeometryCalib=calib_normal(Coord,handles)
     486function GeometryCalib=calib_normal(Coord,Intrinsic)
    391487%------------------------------------------------------------------------
    392488Calib.f1=str2num(get(handles.fx,'String'));
     
    451547
    452548%------------------------------------------------------------------------
    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)
     549function GeometryCalib=calib_3D_linear(Coord,Intrinsic)
     550%------------------------------------------------------------------------
     551coord_files=Intrinsic.coord_files;
     552if ischar(Intrinsic.coord_files)
    461553    coord_files={coord_files};
    462554end
     
    466558%retrieve the calibration points stored in the files listed in the popup list ListCoordFiles
    467559x_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
     561nx=Intrinsic.Npx;
     562ny=Intrinsic.Npy;
    474563x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
    475564X_1=Coord(:,1:3)';%phys coordinates of the ref points
     
    12211310set(handles.kc,'String',num2str(kc,'%1.4f'))
    12221311
    1223 
    1224 % --- Executes when user attempts to close geometry_calib.
     1312%------------------------------------------------------------------------
     1313% ---display calibration extrinsic parameters
     1314function display_extrinsic(GeometryCalib,handles)
     1315%------------------------------------------------------------------------
     1316set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4))
     1317set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4))
     1318set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4))
     1319set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4))
     1320set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4))
     1321set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
     1322
     1323%------------------------------------------------------------------------
     1324% --- executes when user attempts to close geometry_calib.
    12251325function geometry_calib_CloseRequestFcn(hObject, eventdata, handles)
    1226 
     1326%------------------------------------------------------------------------
    12271327delete(hObject); % closes the figure
    12281328
    12291329%------------------------------------------------------------------------
    1230 % --- Executes on button press in PLOT.
     1330% --- executes on button press in PLOT.
    12311331%------------------------------------------------------------------------
    12321332function PLOT_Callback(hObject, eventdata, handles)
Note: See TracChangeset for help on using the changeset viewer.