[847] | 1 | %'geometry_calib': associated to the GUI geometry_calib to perform geometric calibration from a set of reference points
|
---|
| 2 | %------------------------------------------------------------------------
|
---|
| 3 | % function hgeometry_calib = geometry_calib(inputfile,pos)
|
---|
| 4 | %
|
---|
[1062] | 5 | %OUTPUT:
|
---|
[847] | 6 | % hgeometry_calib=current handles of the GUI geometry_calib.fig
|
---|
| 7 | %
|
---|
| 8 | %INPUT:
|
---|
| 9 | % inputfile: (optional) name of an xml file containing coordinates of reference points
|
---|
[1062] | 10 | % pos: (optional) 4 element vector setting the 'Position' of the GUI
|
---|
[847] | 11 |
|
---|
| 12 | %=======================================================================
|
---|
[1061] | 13 | % Copyright 2008-2019, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[847] | 14 | % http://www.legi.grenoble-inp.fr
|
---|
| 15 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
| 16 | %
|
---|
| 17 | % This file is part of the toolbox UVMAT.
|
---|
| 18 | %
|
---|
| 19 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 20 | % it under the terms of the GNU General Public License as published
|
---|
| 21 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 22 | % or (at your option) any later version.
|
---|
| 23 | %
|
---|
| 24 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 27 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 28 | %=======================================================================
|
---|
| 29 |
|
---|
| 30 | function varargout = geometry_calib(varargin)
|
---|
| 31 | % GEOMETRY_CALIB M-file for geometry_calib.fig
|
---|
| 32 | % GEOMETRY_CALIB, by itself, creates a MenuCoord GEOMETRY_CALIB or raises the existing
|
---|
| 33 | % singleton*.
|
---|
| 34 | %
|
---|
| 35 | % H = GEOMETRY_CALIB returns the handle to a MenuCoord GEOMETRY_CALIB or the handle to
|
---|
| 36 | % the existing singleton*.
|
---|
| 37 | %
|
---|
| 38 | % GEOMETRY_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local
|
---|
| 39 | % function named CALLBACK in GEOMETRY_CALIB.M with the given input arguments.
|
---|
| 40 | %
|
---|
| 41 | % GEOMETRY_CALIB('Property','Value',...) creates a MenuCoord GEOMETRY_CALIB or raises the
|
---|
| 42 | % existing singleton*. Starting from the left, property value pairs are
|
---|
| 43 | % applied to the GUI before geometry_calib_OpeningFunction gets called. An
|
---|
| 44 | % unrecognized property name or invalid value makes property application
|
---|
| 45 | % stop. All inputs are passed to geometry_calib_OpeningFcn via varargin.
|
---|
| 46 | %
|
---|
| 47 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
|
---|
| 48 | % instance to run (singleton)".
|
---|
| 49 | %
|
---|
| 50 | % See also: GUIDE, GUIDATA, GUIHANDLES
|
---|
| 51 |
|
---|
| 52 | % Edit the above text to modify the response to help geometry_calib
|
---|
| 53 |
|
---|
[1059] | 54 | % Last Modified by GUIDE v2.5 20-Sep-2018 19:04:30
|
---|
[847] | 55 |
|
---|
| 56 | % Begin initialization code - DO NOT edit
|
---|
| 57 | gui_Singleton = 1;
|
---|
| 58 | gui_State = struct('gui_Name', mfilename, ...
|
---|
[1062] | 59 | 'gui_Singleton', gui_Singleton, ...
|
---|
| 60 | 'gui_OpeningFcn', @geometry_calib_OpeningFcn, ...
|
---|
| 61 | 'gui_OutputFcn', @geometry_calib_OutputFcn, ...
|
---|
| 62 | 'gui_LayoutFcn', [] , ...
|
---|
| 63 | 'gui_Callback', []);
|
---|
[847] | 64 | if nargin
|
---|
[1062] | 65 | [pp,ff]=fileparts(which(varargin{1})); % name of the input file
|
---|
| 66 | if strcmp(ff,mfilename)% if we are activating a sub-function of geometry_calib
|
---|
| 67 | % ~isempty(regexp(varargin{1},'_Callback','once'))
|
---|
| 68 | gui_State.gui_Callback = str2func(varargin{1});
|
---|
| 69 | end
|
---|
[847] | 70 | end
|
---|
| 71 |
|
---|
| 72 | if nargout
|
---|
| 73 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
|
---|
| 74 | else
|
---|
| 75 | gui_mainfcn(gui_State, varargin{:});
|
---|
| 76 | end
|
---|
| 77 | % End initialization code - DO NOT edit
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | % --- Executes just before geometry_calib is made visible.
|
---|
[1062] | 81 | %INPUT:
|
---|
[847] | 82 | %handles: handles of the geometry_calib interface elements
|
---|
| 83 | % PlotHandles: set of handles of the elements contolling the plotting
|
---|
| 84 | % parameters on the uvmat interface (obtained by 'get_plot_handle.m')
|
---|
| 85 | %------------------------------------------------------------------------
|
---|
| 86 | function geometry_calib_OpeningFcn(hObject, eventdata, handles,inputfile)
|
---|
| 87 | %------------------------------------------------------------------------
|
---|
| 88 |
|
---|
| 89 | handles.output = hObject;
|
---|
| 90 | % Update handles structure
|
---|
| 91 | guidata(hObject, handles);
|
---|
| 92 | set(hObject,'DeleteFcn',{@closefcn})%
|
---|
| 93 |
|
---|
| 94 | %% position
|
---|
| 95 | set(0,'Unit','pixels')
|
---|
| 96 | ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
|
---|
| 97 | Left=ScreenSize(3)- 460; %right edge close to the right, with margin=40 (GUI width=420 px)
|
---|
| 98 | if ScreenSize(4)>920
|
---|
| 99 | Height=840;%default height of the GUI
|
---|
| 100 | Bottom=ScreenSize(4)-Height-40; %put fig at top right
|
---|
| 101 | else
|
---|
| 102 | Height=ScreenSize(4)-80;
|
---|
| 103 | Bottom=40; % GUI lies o the screen bottom (with margin =40)
|
---|
| 104 | end
|
---|
| 105 | set(handles.calib_type,'Position',[1 Height-40 194 30])% rank 1
|
---|
| 106 | set(handles.APPLY,'Position',[197 Height-40 110 30])% rank 1
|
---|
[1059] | 107 | set(handles.Replicate,'Position',[309 Height-40 110 30])% rank 1
|
---|
[847] | 108 | set(handles.Intrinsic,'Position',[1 Height-40-2-92 418 92])% rank 2
|
---|
| 109 | set(handles.Extrinsic,'Position',[1 Height-40-4-92-75 418 75])% rank 3
|
---|
| 110 | set(handles.PointLists,'Position',[1 Height-40-6-92-75-117 418 117]) % rank 4
|
---|
| 111 | set(handles.CheckEnableMouse,'Position',[3 Height-362 208 30])% rank 5
|
---|
| 112 | set(handles.PLOT,'Position',[3 Height-394 120 30])% rank 6
|
---|
| 113 | set(handles.Copy,'Position',[151 Height-394 120 30])% rank 6
|
---|
| 114 | set(handles.ClearAll,'Position',[297 Height-394 120 30])% rank 6
|
---|
| 115 | set(handles.ClearPoint,'Position',[297 Height-362 120 30])% rank 6
|
---|
| 116 | set(handles.CoordLine,'Position',[211 Height-362 86 30])% rank 6
|
---|
| 117 | set(handles.phys_title,'Position',[38 Height-426 125 20])% rank 7
|
---|
| 118 | set(handles.CoordUnit,'Position',[151 Height-426 120 30])% rank 7
|
---|
| 119 | set(handles.px_title,'Position',[272 Height-426 125 20])% rank 7
|
---|
| 120 | set(handles.ListCoord,'Position',[1 20 418 Height-446])% rank 8
|
---|
| 121 | set(handles.geometry_calib,'Position',[Left Bottom 420 Height])
|
---|
| 122 |
|
---|
[1062] | 123 | %% set menu of calibration options
|
---|
[847] | 124 | set(handles.calib_type,'String',{'rescale';'linear';'3D_linear';'3D_quadr';'3D_extrinsic'})
|
---|
| 125 | if exist('inputfile','var')&& ~isempty(inputfile)
|
---|
| 126 | [RootPath,SubDir,RootFile,tild,tild,tild,tild,FileExt]=fileparts_uvmat(inputfile);
|
---|
| 127 | struct.XmlInputFile=find_imadoc(RootPath,SubDir,RootFile,FileExt);
|
---|
| 128 | set(handles.ListCoord,'Data',[])
|
---|
| 129 | if exist(struct.XmlInputFile,'file')
|
---|
| 130 | Heading=loadfile(handles,struct.XmlInputFile);% load data from the xml file and fill the GUI
|
---|
| 131 | if isfield(Heading,'Campaign')&& ischar(Heading.Campaign)
|
---|
| 132 | struct.Campaign=Heading.Campaign;
|
---|
| 133 | end
|
---|
[1062] | 134 | end
|
---|
[847] | 135 | set(hObject,'UserData',struct)
|
---|
| 136 | end
|
---|
| 137 |
|
---|
| 138 | %------------------------------------------------------------------------
|
---|
| 139 | % --- Outputs from this function are returned to the command line.
|
---|
| 140 | function varargout = geometry_calib_OutputFcn(~, eventdata, handles)
|
---|
| 141 | %------------------------------------------------------------------------
|
---|
| 142 | % Get default command line output from handles structure
|
---|
| 143 | varargout{1} = handles.output;
|
---|
| 144 | varargout{2}=handles;
|
---|
[1062] | 145 |
|
---|
[847] | 146 | %------------------------------------------------------------------------
|
---|
| 147 | % executed when closing: set the parent interface button to value 0
|
---|
| 148 | function closefcn(gcbo,eventdata)
|
---|
| 149 | %------------------------------------------------------------------------
|
---|
| 150 | huvmat=findobj(allchild(0),'Name','uvmat');
|
---|
| 151 | if ~isempty(huvmat)
|
---|
| 152 | handles=guidata(huvmat);
|
---|
| 153 | set(handles.MenuCalib,'Checked','off')
|
---|
| 154 | hobject=findobj(handles.PlotAxes,'tag','calib_points');
|
---|
| 155 | if ~isempty(hobject)
|
---|
| 156 | delete(hobject)
|
---|
| 157 | end
|
---|
| 158 | hobject=findobj(handles.PlotAxes,'tag','calib_marker');
|
---|
| 159 | if ~isempty(hobject)
|
---|
| 160 | delete(hobject)
|
---|
[1062] | 161 | end
|
---|
[847] | 162 | end
|
---|
[1062] | 163 |
|
---|
| 164 | %------------------------------------------------------------------------
|
---|
| 165 | % --- Executes on button press APPLY (used to launch the calibration).
|
---|
| 166 | function APPLY_Callback(hObject, eventdata, handles)
|
---|
| 167 | set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
|
---|
[847] | 168 |
|
---|
| 169 | %------------------------------------------------------------------------
|
---|
[1062] | 170 | %% look for the GUI uvmat and check for an image as input
|
---|
| 171 | set(handles.APPLY,'BackgroundColor',[1 1 0])% paint APPLY button in yellow to show activation
|
---|
| 172 | huvmat=findobj(allchild(0),'Name','uvmat');% look for the GUI uvmat
|
---|
| 173 | hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
|
---|
| 174 | if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
|
---|
| 175 | msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
|
---|
| 176 | return
|
---|
| 177 | end
|
---|
| 178 |
|
---|
| 179 | RootPath='';
|
---|
| 180 | if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
|
---|
| 181 | RootPath=get(hhuvmat.RootPath,'String');% path to the currently displayed image
|
---|
| 182 | SubDirBase=regexprep(get(hhuvmat.SubDir,'String'),'\..+$','');
|
---|
| 183 | outputfile=[fullfile(RootPath,SubDirBase) '.xml'];%xml file associated with the currently displayed image
|
---|
| 184 | else
|
---|
| 185 | question={'save the calibration data and point coordinates in'};
|
---|
| 186 | def={fullfile(RootPath,'ObjectCalib.xml')};
|
---|
| 187 | options.Resize='on';
|
---|
| 188 | answer=inputdlg(question,'',1,def,options);
|
---|
| 189 | outputfile=answer{1};
|
---|
| 190 | end
|
---|
| 191 |
|
---|
| 192 | %% read coordinates of the calibration poinnts: Coord(:,1-3) in phys, Coord(:,4-5) image
|
---|
| 193 | Coord=get(handles.ListCoord,'Data');
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | %% read the type of calibration
|
---|
| 197 | calib_cell=get(handles.calib_type,'String');
|
---|
| 198 | val=get(handles.calib_type,'Value');
|
---|
| 199 | CalibFcn=['calib_' calib_cell{val}];
|
---|
| 200 |
|
---|
| 201 | %% read the intrinsic parameters
|
---|
| 202 | Intrinsic.Npx=str2num(get(hhuvmat.num_Npx,'String'));
|
---|
| 203 | Intrinsic.Npy=str2num(get(hhuvmat.num_Npy,'String'));
|
---|
| 204 | Intrinsic.coord_files=get(handles.ListCoordFiles,'String');
|
---|
| 205 | Intrinsic.fx=str2num(get(handles.fx,'String'));
|
---|
| 206 | Intrinsic.fy=str2num(get(handles.fy,'String'));
|
---|
| 207 | Intrinsic.kc=str2num(get(handles.kc,'String'));
|
---|
| 208 | Intrinsic.Cx=str2num(get(handles.Cx,'String'));
|
---|
| 209 | Intrinsic.Cy=str2num(get(handles.Cy,'String'));
|
---|
| 210 | if isempty(Intrinsic.kc)
|
---|
| 211 | Intrinsic.kc=0;
|
---|
| 212 | end
|
---|
| 213 | if isempty(Intrinsic.Cx)||isempty(Intrinsic.Cy)
|
---|
| 214 | Intrinsic.Cx=Intrinsic.Npx/2;
|
---|
| 215 | Intrinsic.Cy=Intrinsic.Npy/2;
|
---|
| 216 | end
|
---|
| 217 |
|
---|
| 218 | %% apply to cropped images if requested
|
---|
| 219 | if get(handles.Replicate,'Value')
|
---|
| 220 | answer=msgbox_uvmat('INPUT_Y-N','apply to full images (not cropped)?');
|
---|
| 221 | if strcmp(answer,'No')
|
---|
| 222 | prompt = {'npy_lower'};
|
---|
| 223 | dlg_title = 'remove image the npy_lower image lines (removal of the upper line does not change calibration)';
|
---|
| 224 | num_lines= 1;
|
---|
| 225 | def = {'0'};
|
---|
| 226 | answer = inputdlg(prompt,dlg_title,num_lines,def);
|
---|
| 227 | npy_crop=str2num(answer{1});
|
---|
| 228 | Intrinsic.Npy=Intrinsic.Npy-npy_crop; %size of the filtering window
|
---|
| 229 | Coord(:,5)=Coord(:,5)-npy_crop;% shift the image ordinates of the calibration points by removing the lower band
|
---|
| 230 | end
|
---|
| 231 | end
|
---|
| 232 |
|
---|
| 233 | %% Apply calibration
|
---|
| 234 | [GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
|
---|
| 235 | if isempty(GeometryCalib)
|
---|
| 236 | return
|
---|
| 237 | end
|
---|
| 238 |
|
---|
| 239 | %% record the coordinate unit
|
---|
| 240 | unitlist=get(handles.CoordUnit,'String');
|
---|
| 241 | unit=unitlist{get(handles.CoordUnit,'value')};
|
---|
| 242 | GeometryCalib.CoordUnit=unit;
|
---|
| 243 |
|
---|
| 244 | %% record the coordinates of the calibration points
|
---|
| 245 | GeometryCalib.SourceCalib.PointCoord=Coord;
|
---|
| 246 |
|
---|
| 247 | %% display calibration results on the GUI geometry_calib
|
---|
| 248 | display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
|
---|
| 249 | display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
|
---|
| 250 | % (rotation and translation of camera with respect to the phys coordinates)
|
---|
| 251 |
|
---|
| 252 | %% set the default plane and display the calibration data errors for validation
|
---|
| 253 | answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
|
---|
| 254 | ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
|
---|
| 255 | ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];
|
---|
| 256 | [num2str(numel(ind_removed)) ' points removed']});
|
---|
[1063] | 257 | SliceCoord_ref=[0 0 0]; %default reference plane
|
---|
[1062] | 258 | if strcmp(answer,'Yes') %store the calibration data
|
---|
| 259 | if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
|
---|
| 260 | answer=msgbox_uvmat('INPUT_Y-N',{['Assume that the current image is in the plane of the calib points z=' num2str(Z_plane) ] ; 'can be later modified by MenuSetSlice in the upper bar menu of uvmat'});
|
---|
| 261 | SliceCoord_ref=Z_plane'*[0 0 1];
|
---|
| 262 | end
|
---|
| 263 | else
|
---|
| 264 | GeometryCalib=[];
|
---|
| 265 | index=1;
|
---|
| 266 | end
|
---|
| 267 |
|
---|
| 268 | if ~isempty(GeometryCalib) % if calibration is not cancelled
|
---|
| 269 | %%%%% use of the option 'replicate'
|
---|
| 270 | if get(handles.Replicate,'Value')% if the option replicate is activated
|
---|
[1063] | 271 | nbcalib=0;
|
---|
[1062] | 272 | %% open the GUI browse_data
|
---|
| 273 | hbrowse=findobj(allchild(0),'Tag','browse_data');
|
---|
| 274 | if ~isempty(hbrowse)% look for the GUI 'replicate'
|
---|
[1068] | 275 | BrowseData=guidata(hbrowse);
|
---|
| 276 | SourceDir=get(BrowseData.SourceDir,'String');
|
---|
| 277 | ListExp=get(BrowseData.ListExperiments,'String');
|
---|
| 278 | ExpIndices=get(BrowseData.ListExperiments,'Value');
|
---|
| 279 | ListExp=ListExp(ExpIndices);
|
---|
| 280 | ListDevices=get(BrowseData.ListDevices,'String');
|
---|
| 281 | DeviceIndices=get(BrowseData.ListDevices,'Value');
|
---|
| 282 | ListDevices=ListDevices(DeviceIndices);
|
---|
| 283 | ListDataSeries=get(BrowseData.DataSeries,'String');
|
---|
| 284 | DataSeriesIndices=get(BrowseData.DataSeries,'Value');
|
---|
| 285 | ListDataSeries=ListDataSeries(DataSeriesIndices);
|
---|
| 286 | NbExp=0; % counter of the number of experiments set by the GUI browse_data
|
---|
| 287 | for iexp=1:numel(ListExp)
|
---|
| 288 | if ~isempty(regexp(ListExp{iexp},'^\+/'))% if it is a folder
|
---|
| 289 | for idevice=1:numel(ListDevices)
|
---|
| 290 | if ~isempty(regexp(ListDevices{idevice},'^\+/'))% if it is a folder
|
---|
| 291 | for isubdir=1:numel(ListDataSeries)
|
---|
| 292 | if ~isempty(regexp(ListDataSeries{isubdir},'^\+/'))% if it is a folder
|
---|
| 293 | lpath= fullfile(SourceDir,regexprep(ListExp{iexp},'^\+/',''),...
|
---|
| 294 | regexprep(ListDevices{idevice},'^\+/',''));
|
---|
| 295 | ldir= regexprep(ListDataSeries{isubdir},'^\+/','');
|
---|
| 296 | if exist(fullfile(lpath,ldir),'dir')
|
---|
| 297 | NbExp=NbExp+1;
|
---|
| 298 | ListPath{NbExp}=lpath;
|
---|
| 299 | ListSubdir{NbExp}=ldir;
|
---|
| 300 | ExpIndex{NbExp}=iexp;
|
---|
| 301 | end
|
---|
| 302 | end
|
---|
| 303 | end
|
---|
| 304 | end
|
---|
| 305 | end
|
---|
| 306 | end
|
---|
| 307 | end
|
---|
| 308 | for iexp=1:NbExp
|
---|
| 309 | XmlName=fullfile(ListPath{iexp},[ListSubdir{iexp} '.xml']);
|
---|
| 310 | if exist(XmlName,'file')
|
---|
| 311 | check_update=1;
|
---|
| 312 | else
|
---|
| 313 | check_update=0;
|
---|
| 314 | end
|
---|
[1063] | 315 | errormsg=update_imadoc(GeometryCalib,XmlName,'GeometryCalib');% introduce the calibration data in the xml file
|
---|
| 316 | if ~strcmp(errormsg,'')
|
---|
| 317 | msgbox_uvmat('ERROR',errormsg);
|
---|
[1062] | 318 | else
|
---|
[1068] | 319 | if check_update
|
---|
| 320 | display([XmlName ' updated with calibration parameters'])
|
---|
| 321 | else
|
---|
| 322 | display([XmlName ' created with calibration parameters'])
|
---|
| 323 | end
|
---|
[1063] | 324 | nbcalib=nbcalib+1;
|
---|
[1062] | 325 | end
|
---|
[1059] | 326 | end
|
---|
[1062] | 327 | end
|
---|
[1068] | 328 | msgbox_uvmat('CONFIMATION',['calibration replicated for ' num2str(NbExp) ' experiments']);
|
---|
[1063] | 329 | else
|
---|
| 330 | %% copy the xml file from the old location if appropriate, then update with the calibration parameters
|
---|
| 331 | if ~exist(outputfile,'file') && ~isempty(SubDirBase)
|
---|
| 332 | oldxml=[fullfile(RootPath,SubDirBase,get(hhuvmat.RootFile,'String')) '.xml'];
|
---|
| 333 | if exist(oldxml,'file')
|
---|
| 334 | [success,message]=copyfile(oldxml,outputfile);%copy the old xml file to a new one with the new convention
|
---|
| 335 | end
|
---|
| 336 | end
|
---|
| 337 | errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');% introduce the calibration data in the xml file
|
---|
[1062] | 338 | if ~strcmp(errormsg,'')
|
---|
| 339 | msgbox_uvmat('ERROR',errormsg);
|
---|
[1063] | 340 | end
|
---|
| 341 |
|
---|
| 342 | %% display image with new calibration in the currently opened uvmat interface
|
---|
| 343 | FieldList=get(hhuvmat.FieldName,'String');
|
---|
| 344 | val=get(hhuvmat.FieldName,'Value');
|
---|
| 345 | if strcmp(FieldList{val},'image')
|
---|
| 346 | set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' to plot the whole image
|
---|
| 347 | UserData=get(handles.geometry_calib,'UserData');
|
---|
| 348 | UserData.XmlInputFile=outputfile;%save the current xml file name
|
---|
| 349 | set(handles.geometry_calib,'UserData',UserData)
|
---|
| 350 | uvmat('InputFileREFRESH_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat, show the image in phys coordinates
|
---|
| 351 | PLOT_Callback(hObject, eventdata, handles)
|
---|
| 352 | set(handles.CoordLine,'string',num2str(index))
|
---|
| 353 | Coord=get(handles.ListCoord,'Data');
|
---|
| 354 | update_calib_marker(Coord(index,:)); %indicate the point with max deviations from phys coord to calibration
|
---|
| 355 | figure(handles.geometry_calib)% put the GUI geometry_calib in front
|
---|
[1059] | 356 | else
|
---|
[1063] | 357 | msgbox_uvmat('WARNING','open the image to see the effect of the new calibration')
|
---|
[1059] | 358 | end
|
---|
[847] | 359 | end
|
---|
[1062] | 360 | end
|
---|
[847] | 361 |
|
---|
[1063] | 362 | set(handles.APPLY,'BackgroundColor',[1 0 0]) % set APPLY button to red color
|
---|
[1062] | 363 |
|
---|
[847] | 364 | %------------------------------------------------------------------------
|
---|
[1059] | 365 | % --- Executes on button press in Replicate
|
---|
[1063] | 366 | function Replicate_Callback(hObject, eventdata, handles)
|
---|
| 367 | % %------------------------------------------------------------------------
|
---|
| 368 | set(handles.CheckEnableMouse,'Value',0)% desactivate mouse (to avoid spurious creation of new points)
|
---|
| 369 |
|
---|
| 370 | if get(handles.Replicate,'Value') %open the GUI browse_data
|
---|
| 371 | % look for the GUI uvmat and check for an image as input
|
---|
| 372 | huvmat=findobj(allchild(0),'Name','uvmat');
|
---|
| 373 | hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
|
---|
| 374 | RootPath=get(hhuvmat.RootPath,'String');
|
---|
| 375 | SubDir=get(hhuvmat.SubDir,'String');
|
---|
| 376 | browse_data(fullfile(RootPath,SubDir))
|
---|
| 377 | else
|
---|
| 378 | hbrowse=findobj(allchild(0),'Tag','browse_data');
|
---|
| 379 | if ~isempty(hbrowse)
|
---|
| 380 | delete(hbrowse)
|
---|
| 381 | end
|
---|
| 382 | end
|
---|
[847] | 383 | %------------------------------------------------------------------------
|
---|
| 384 | % --- activate calibration and store parameters in ouputfile .
|
---|
[1009] | 385 | function [GeometryCalib,ind_max,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic)
|
---|
[847] | 386 | %------------------------------------------------------------------------
|
---|
[1001] | 387 |
|
---|
[847] | 388 | index=[];
|
---|
[1009] | 389 | GeometryCalib=[];
|
---|
[1062] | 390 | ind_max=[];ind_removed=[];Z_plane=[];
|
---|
[847] | 391 | % apply the calibration, whose type is selected in handles.calib_type
|
---|
| 392 | if ~isempty(Coord)
|
---|
[1001] | 393 | GeometryCalib=feval(CalibFcn,Coord,Intrinsic);
|
---|
[847] | 394 | else
|
---|
| 395 | msgbox_uvmat('ERROR','No calibration points, abort')
|
---|
[1062] | 396 | end
|
---|
[847] | 397 | if isempty(GeometryCalib)
|
---|
| 398 | return
|
---|
| 399 | end
|
---|
| 400 | Z_plane=[];
|
---|
[1009] | 401 |
|
---|
| 402 | % estimate calibration error rms and max
|
---|
| 403 | X=Coord(:,1);
|
---|
| 404 | Y=Coord(:,2);
|
---|
| 405 | Z=Coord(:,3);
|
---|
| 406 | x_ima=Coord(:,4);
|
---|
| 407 | y_ima=Coord(:,5);
|
---|
| 408 | [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z);
|
---|
| 409 | GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
|
---|
| 410 | GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
|
---|
| 411 | [ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima));
|
---|
| 412 | [ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima));
|
---|
| 413 | [tild,ind_dim]=max(ErrorMax);
|
---|
| 414 | ind_max=index(ind_dim); % mark the index with maximum deviation
|
---|
| 415 |
|
---|
| 416 | % detect bad calibration points, marked by indices ind_bad, if the
|
---|
| 417 | % difference of actual image coordinates and those given by calibration is
|
---|
| 418 | % greater than 2 pixels and greater than 4 rms.
|
---|
| 419 | check_x=abs(Xpoints-x_ima)>max(2,3*GeometryCalib.ErrorRms(1));
|
---|
| 420 | check_y=abs(Ypoints-y_ima)>max(2,3*GeometryCalib.ErrorRms(2));
|
---|
| 421 | ind_removed=find(check_x | check_y)
|
---|
| 422 | % repeat calibration without the excluded points:
|
---|
[1062] | 423 | if ~isempty(ind_removed)
|
---|
[1009] | 424 | Coord(ind_removed,:)=[];
|
---|
| 425 | GeometryCalib=feval(CalibFcn,Coord,Intrinsic);
|
---|
[847] | 426 | X=Coord(:,1);
|
---|
| 427 | Y=Coord(:,2);
|
---|
| 428 | Z=Coord(:,3);
|
---|
| 429 | x_ima=Coord(:,4);
|
---|
| 430 | y_ima=Coord(:,5);
|
---|
| 431 | [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z);
|
---|
| 432 | GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
|
---|
| 433 | GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
|
---|
| 434 | end
|
---|
[1009] | 435 | GeometryCalib.ErrorMax=ErrorMax;
|
---|
| 436 | %set the Z position of the reference plane used for calibration
|
---|
| 437 | if isequal(max(Z),min(Z))%Z constant
|
---|
| 438 | Z_plane=Z(1);
|
---|
| 439 | GeometryCalib.NbSlice=1;
|
---|
| 440 | GeometryCalib.SliceCoord=[0 0 Z_plane];
|
---|
| 441 | end
|
---|
[847] | 442 |
|
---|
| 443 |
|
---|
| 444 | %------------------------------------------------------------------------
|
---|
| 445 | % --- determine the parameters for a calibration by an affine function (rescaling and offset, no rotation)
|
---|
[1001] | 446 | function GeometryCalib=calib_rescale(Coord,Intrinsic)
|
---|
[847] | 447 | %------------------------------------------------------------------------
|
---|
| 448 | X=Coord(:,1);
|
---|
| 449 | Y=Coord(:,2);% Z not used
|
---|
| 450 | x_ima=Coord(:,4);
|
---|
| 451 | y_ima=Coord(:,5);
|
---|
| 452 | [px]=polyfit(X,x_ima,1);
|
---|
| 453 | [py]=polyfit(Y,y_ima,1);
|
---|
| 454 | % T_x=px(2);
|
---|
| 455 | % T_y=py(2);
|
---|
| 456 | GeometryCalib.CalibrationType='rescale';
|
---|
| 457 | GeometryCalib.fx_fy=[px(1) py(1)];%.fx_fy corresponds to pxcm along x and y
|
---|
| 458 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
|
---|
| 459 | GeometryCalib.Tx_Ty_Tz=[px(2)/px(1) py(2)/py(1) 1];
|
---|
| 460 | GeometryCalib.omc=[0 0 0];
|
---|
| 461 |
|
---|
| 462 | %------------------------------------------------------------------------
|
---|
| 463 | % --- determine the parameters for a calibration by a linear transform matrix (rescale and rotation)
|
---|
[1062] | 464 | function GeometryCalib=calib_linear(Coord,Intrinsic)
|
---|
[847] | 465 | %------------------------------------------------------------------------
|
---|
| 466 | X=Coord(:,1);
|
---|
| 467 | Y=Coord(:,2);% Z not used
|
---|
| 468 | x_ima=Coord(:,4);
|
---|
| 469 | y_ima=Coord(:,5);
|
---|
| 470 | XY_mat=[ones(size(X)) X Y];
|
---|
| 471 | a_X1=XY_mat\x_ima; %transformation matrix for X
|
---|
| 472 | a_Y1=XY_mat\y_ima;%transformation matrix for X
|
---|
| 473 | R=[a_X1(2),a_X1(3);a_Y1(2),a_Y1(3)];
|
---|
| 474 | epsilon=sign(det(R));
|
---|
| 475 | norm=abs(det(R));
|
---|
| 476 | GeometryCalib.CalibrationType='linear';
|
---|
| 477 | if (a_X1(2)/a_Y1(3))>0
|
---|
| 478 | GeometryCalib.fx_fy(1)=sqrt((a_X1(2)/a_Y1(3))*norm);
|
---|
| 479 | else
|
---|
| 480 | GeometryCalib.fx_fy(1)=-sqrt(-(a_X1(2)/a_Y1(3))*norm);
|
---|
| 481 | end
|
---|
| 482 | GeometryCalib.fx_fy(2)=(a_Y1(3)/a_X1(2))*GeometryCalib.fx_fy(1);
|
---|
| 483 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
|
---|
| 484 | GeometryCalib.Tx_Ty_Tz=[a_X1(1)/GeometryCalib.fx_fy(1) a_Y1(1)/GeometryCalib.fx_fy(2) 1];
|
---|
| 485 | R(1,:)=R(1,:)/GeometryCalib.fx_fy(1);
|
---|
| 486 | R(2,:)=R(2,:)/GeometryCalib.fx_fy(2);
|
---|
| 487 | R=[R;[0 0]];
|
---|
| 488 | GeometryCalib.R=[R [0;0;-epsilon]];
|
---|
| 489 | GeometryCalib.omc=(180/pi)*[acos(GeometryCalib.R(1,1)) 0 0];
|
---|
| 490 |
|
---|
| 491 | %------------------------------------------------------------------------
|
---|
| 492 | % --- determine the tsai parameters for a view normal to the grid plane
|
---|
| 493 | % NOT USED
|
---|
[1001] | 494 | function GeometryCalib=calib_normal(Coord,Intrinsic)
|
---|
[847] | 495 | %------------------------------------------------------------------------
|
---|
[1008] | 496 | Calib.fx=str2num(get(handles.fx,'String'));
|
---|
| 497 | Calib.fy=str2num(get(handles.fy,'String'));
|
---|
| 498 | Calib.kc=str2num(get(handles.kc,'String'));
|
---|
[847] | 499 | Calib.Cx=str2num(get(handles.Cx,'String'));
|
---|
| 500 | Calib.Cy=str2num(get(handles.Cy,'String'));
|
---|
| 501 | %default
|
---|
[1008] | 502 | if isempty(Calib.fx)
|
---|
| 503 | Calib.fx=25/0.012;
|
---|
[847] | 504 | end
|
---|
[1008] | 505 | if isempty(Calib.fy)
|
---|
| 506 | Calib.fy=25/0.012;
|
---|
[847] | 507 | end
|
---|
[1008] | 508 | if isempty(Calib.kc)
|
---|
| 509 | Calib.kc=0;
|
---|
[847] | 510 | end
|
---|
| 511 | if isempty(Calib.Cx)||isempty(Calib.Cy)
|
---|
| 512 | huvmat=findobj(allchild(0),'Tag','uvmat');
|
---|
| 513 | hhuvmat=guidata(huvmat);
|
---|
| 514 | Calib.Cx=str2num(get(hhuvmat.num_Npx,'String'))/2;
|
---|
| 515 | Calib.Cx=str2num(get(hhuvmat.num_Npy,'String'))/2;
|
---|
[1062] | 516 | end
|
---|
[847] | 517 | %tsai parameters
|
---|
| 518 | Calib.dpx=0.012;%arbitrary
|
---|
| 519 | Calib.dpy=0.012;
|
---|
[1008] | 520 | Calib.sx=Calib.fx*Calib.dpx/(Calib.fy*Calib.dpy);
|
---|
| 521 | Calib.f=Calib.fy*Calib.dpy;
|
---|
| 522 | Calib.kappa1=Calib.kc/(Calib.f*Calib.f);
|
---|
[847] | 523 |
|
---|
| 524 | %initial guess
|
---|
| 525 | X=Coord(:,1);
|
---|
| 526 | Y=Coord(:,2);
|
---|
| 527 | Zmean=mean(Coord(:,3));
|
---|
| 528 | x_ima=Coord(:,4)-Calib.Cx;
|
---|
| 529 | y_ima=Coord(:,5)-Calib.Cy;
|
---|
| 530 | XY_mat=[ones(size(X)) X Y];
|
---|
| 531 | a_X1=XY_mat\x_ima; %transformation matrix for X
|
---|
| 532 | a_Y1=XY_mat\y_ima;%transformation matrix for Y
|
---|
| 533 | R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,-1];% rotation+ z axis reversal (upward)
|
---|
| 534 | norm=sqrt(det(-R));
|
---|
| 535 | calib_param(1)=0;% quadratic distortion
|
---|
| 536 | calib_param(2)=a_X1(1);
|
---|
| 537 | calib_param(3)=a_Y1(1);
|
---|
| 538 | calib_param(4)=Calib.f/(norm*Calib.dpx)-R(3,3)*Zmean;
|
---|
| 539 | calib_param(5)=angle(a_X1(2)+1i*a_X1(3));
|
---|
| 540 | display(['initial guess=' num2str(calib_param)])
|
---|
| 541 |
|
---|
| 542 | %optimise the parameters: minimisation of error
|
---|
| 543 | calib_param = fminsearch(@(calib_param) error_calib(calib_param,Calib,Coord),calib_param);
|
---|
| 544 |
|
---|
| 545 | GeometryCalib.CalibrationType='tsai_normal';
|
---|
| 546 | GeometryCalib.focal=Calib.f;
|
---|
| 547 | GeometryCalib.dpx_dpy=[Calib.dpx Calib.dpy];
|
---|
| 548 | GeometryCalib.Cx_Cy=[Calib.Cx Calib.Cy];
|
---|
| 549 | GeometryCalib.sx=Calib.sx;
|
---|
| 550 | GeometryCalib.kappa1=calib_param(1);
|
---|
| 551 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
|
---|
[1062] | 552 | GeometryCalib.Tx_Ty_Tz=[calib_param(2) calib_param(3) calib_param(4)];
|
---|
[847] | 553 | alpha=calib_param(5);
|
---|
| 554 | GeometryCalib.R=[cos(alpha) sin(alpha) 0;-sin(alpha) cos(alpha) 0;0 0 -1];
|
---|
| 555 |
|
---|
| 556 | %------------------------------------------------------------------------
|
---|
[1001] | 557 | function GeometryCalib=calib_3D_linear(Coord,Intrinsic)
|
---|
[847] | 558 | %------------------------------------------------------------------------
|
---|
[1001] | 559 | coord_files=Intrinsic.coord_files;
|
---|
| 560 | if ischar(Intrinsic.coord_files)
|
---|
[847] | 561 | coord_files={coord_files};
|
---|
| 562 | end
|
---|
| 563 | if isempty(coord_files{1}) || isequal(coord_files,{''})
|
---|
| 564 | coord_files={};
|
---|
| 565 | end
|
---|
| 566 | %retrieve the calibration points stored in the files listed in the popup list ListCoordFiles
|
---|
| 567 | x_1=Coord(:,4:5)';%px coordinates of the ref points
|
---|
[1001] | 568 |
|
---|
| 569 | nx=Intrinsic.Npx;
|
---|
| 570 | ny=Intrinsic.Npy;
|
---|
[847] | 571 | x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
|
---|
| 572 | X_1=Coord(:,1:3)';%phys coordinates of the ref points
|
---|
| 573 | n_ima=numel(coord_files)+1;
|
---|
[1062] | 574 | if ~isempty(coord_files)
|
---|
[847] | 575 | msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used'])
|
---|
| 576 | for ifile=1:numel(coord_files)
|
---|
[1062] | 577 | t=xmltree(coord_files{ifile});
|
---|
| 578 | s=convert(t);%convert to matlab structure
|
---|
[847] | 579 | if isfield(s,'GeometryCalib')
|
---|
| 580 | if isfield(s.GeometryCalib,'SourceCalib')
|
---|
| 581 | if isfield(s.GeometryCalib.SourceCalib,'PointCoord')
|
---|
[1062] | 582 | PointCoord=s.GeometryCalib.SourceCalib.PointCoord;
|
---|
| 583 | Coord_file=zeros(length(PointCoord),5);%default
|
---|
| 584 | for i=1:length(PointCoord)
|
---|
| 585 | line=str2num(PointCoord{i});
|
---|
| 586 | Coord_file(i,4:5)=line(4:5);%px x
|
---|
| 587 | Coord_file(i,1:3)=line(1:3);%phys x
|
---|
| 588 | end
|
---|
| 589 | eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']);
|
---|
| 590 | eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]);
|
---|
| 591 | eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']);
|
---|
[847] | 592 | end
|
---|
| 593 | end
|
---|
| 594 | end
|
---|
| 595 | end
|
---|
| 596 | end
|
---|
| 597 | n_ima=numel(coord_files)+1;
|
---|
| 598 | est_dist=[0;0;0;0;0];
|
---|
| 599 | est_aspect_ratio=0;
|
---|
| 600 | est_fc=[1;1];
|
---|
| 601 | center_optim=0;
|
---|
[1006] | 602 | path_uvmat=which('uvmat');% check the path detected for source file uvmat
|
---|
| 603 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT
|
---|
[847] | 604 | run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim'));% apply fct 'toolbox_calib/go_calib_optim'
|
---|
| 605 | if exist('Rc_1','var')
|
---|
| 606 | GeometryCalib.CalibrationType='3D_linear';
|
---|
| 607 | GeometryCalib.fx_fy=fc';
|
---|
| 608 | GeometryCalib.Cx_Cy=cc';
|
---|
| 609 | GeometryCalib.kc=kc(1);
|
---|
| 610 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
|
---|
| 611 | GeometryCalib.Tx_Ty_Tz=Tc_1';
|
---|
| 612 | GeometryCalib.R=Rc_1;
|
---|
| 613 | GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate
|
---|
| 614 | GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate
|
---|
| 615 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate
|
---|
| 616 | GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees
|
---|
| 617 | GeometryCalib.ErrorRMS=[];
|
---|
| 618 | GeometryCalib.ErrorMax=[];
|
---|
| 619 | else
|
---|
| 620 | msgbox_uvmat('ERROR',['calibration function ' fullfile('toolbox_calib','go_calib_optim') ' did not converge: use multiple views or option 3D_extrinsic'])
|
---|
| 621 | GeometryCalib=[];
|
---|
| 622 | end
|
---|
| 623 |
|
---|
| 624 | %------------------------------------------------------------------------
|
---|
[1006] | 625 | function GeometryCalib=calib_3D_quadr(Coord,Intrinsic)
|
---|
[847] | 626 | %------------------------------------------------------------------
|
---|
| 627 |
|
---|
| 628 | path_uvmat=which('uvmat');% check the path detected for source file uvmat
|
---|
| 629 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT
|
---|
| 630 | huvmat=findobj(allchild(0),'Tag','uvmat');
|
---|
| 631 | hhuvmat=guidata(huvmat);
|
---|
| 632 | if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
|
---|
| 633 | msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
|
---|
[1062] | 634 | return
|
---|
[847] | 635 | end
|
---|
| 636 | % check_cond=0;
|
---|
[1006] | 637 |
|
---|
| 638 | coord_files=Intrinsic.coord_files;
|
---|
| 639 |
|
---|
[847] | 640 | if ischar(coord_files)
|
---|
| 641 | coord_files={coord_files};
|
---|
| 642 | end
|
---|
| 643 | if isempty(coord_files{1}) || isequal(coord_files,{''})
|
---|
| 644 | coord_files={};
|
---|
| 645 | end
|
---|
| 646 |
|
---|
| 647 | %retrieve the calibration points stored in the files listed in the popup list ListCoordFiles
|
---|
| 648 | x_1=Coord(:,4:5)';%px coordinates of the ref points
|
---|
| 649 | nx=str2num(get(hhuvmat.num_Npx,'String'));
|
---|
| 650 | ny=str2num(get(hhuvmat.num_Npy,'String'));
|
---|
| 651 | x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
|
---|
| 652 | X_1=Coord(:,1:3)';%phys coordinates of the ref points
|
---|
| 653 | n_ima=numel(coord_files)+1;
|
---|
[1062] | 654 | if ~isempty(coord_files)
|
---|
[847] | 655 | msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used'])
|
---|
| 656 | for ifile=1:numel(coord_files)
|
---|
[1062] | 657 | t=xmltree(coord_files{ifile});
|
---|
| 658 | s=convert(t);%convert to matlab structure
|
---|
[847] | 659 | if isfield(s,'GeometryCalib')
|
---|
| 660 | if isfield(s.GeometryCalib,'SourceCalib')
|
---|
| 661 | if isfield(s.GeometryCalib.SourceCalib,'PointCoord')
|
---|
[1062] | 662 | PointCoord=s.GeometryCalib.SourceCalib.PointCoord;
|
---|
| 663 | Coord_file=zeros(length(PointCoord),5);%default
|
---|
| 664 | for i=1:length(PointCoord)
|
---|
| 665 | line=str2num(PointCoord{i});
|
---|
| 666 | Coord_file(i,4:5)=line(4:5);%px x
|
---|
| 667 | Coord_file(i,1:3)=line(1:3);%phys x
|
---|
| 668 | end
|
---|
| 669 | eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']);
|
---|
| 670 | eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]);
|
---|
| 671 | eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']);
|
---|
[847] | 672 | end
|
---|
| 673 | end
|
---|
| 674 | end
|
---|
| 675 | end
|
---|
| 676 | end
|
---|
| 677 | n_ima=numel(coord_files)+1;
|
---|
| 678 | est_dist=[1;0;0;0;0];
|
---|
| 679 | est_aspect_ratio=1;
|
---|
| 680 | center_optim=0;
|
---|
| 681 | run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim'));% apply fct 'toolbox_calib/go_calib_optim'
|
---|
| 682 |
|
---|
| 683 | if exist('Rc_1','var')
|
---|
| 684 | GeometryCalib.CalibrationType='3D_quadr';
|
---|
| 685 | GeometryCalib.fx_fy=fc';
|
---|
| 686 | GeometryCalib.Cx_Cy=cc';
|
---|
| 687 | GeometryCalib.kc=kc(1);
|
---|
| 688 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
|
---|
| 689 | GeometryCalib.Tx_Ty_Tz=Tc_1';
|
---|
| 690 | GeometryCalib.R=Rc_1;
|
---|
| 691 | GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate
|
---|
| 692 | GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate
|
---|
| 693 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate
|
---|
| 694 | GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees
|
---|
| 695 | GeometryCalib.ErrorRMS=[];
|
---|
| 696 | GeometryCalib.ErrorMax=[];
|
---|
| 697 | else
|
---|
| 698 | msgbox_uvmat('ERROR',['calibration function ' fullfile('toolbox_calib','go_calib_optim') ' did not converge: use multiple views or option 3D_extrinsic'])
|
---|
| 699 | GeometryCalib=[];
|
---|
| 700 | end
|
---|
| 701 |
|
---|
| 702 | %------------------------------------------------------------------------
|
---|
[1008] | 703 | function GeometryCalib=calib_3D_extrinsic(Coord, Intrinsic)
|
---|
[847] | 704 | %------------------------------------------------------------------
|
---|
| 705 | path_uvmat=which('geometry_calib');% check the path detected for source file uvmat
|
---|
| 706 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT
|
---|
| 707 | x_1=double(Coord(:,4:5)');%image coordinates
|
---|
| 708 | X_1=double(Coord(:,1:3)');% phys coordinates
|
---|
| 709 | huvmat=findobj(allchild(0),'Tag','uvmat');
|
---|
| 710 | hhuvmat=guidata(huvmat);
|
---|
| 711 | if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
|
---|
| 712 | msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
|
---|
[1062] | 713 | return
|
---|
[847] | 714 | end
|
---|
| 715 | ny=str2double(get(hhuvmat.num_Npy,'String'));
|
---|
| 716 | x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
|
---|
| 717 | n_ima=1;
|
---|
| 718 | GeometryCalib.CalibrationType='3D_extrinsic';
|
---|
[1008] | 719 | fx=Intrinsic.fx;
|
---|
| 720 | fy=Intrinsic.fy;
|
---|
| 721 | Cx=Intrinsic.Cx;
|
---|
| 722 | Cy=Intrinsic.Cy;
|
---|
| 723 | kc=Intrinsic.kc;
|
---|
[847] | 724 | errormsg='';
|
---|
| 725 | if isempty(fx)
|
---|
| 726 | errormsg='focal length fx needs to be introduced';
|
---|
| 727 | elseif isempty(fy)
|
---|
| 728 | errormsg='focal length fy needs to be introduced';
|
---|
| 729 | elseif isempty(Cx)
|
---|
| 730 | errormsg='shift Cx to image centre needs to be introduced';
|
---|
| 731 | elseif isempty(Cy)
|
---|
| 732 | errormsg='shift Cy to image centre needs to be introduced';
|
---|
| 733 | end
|
---|
| 734 | if ~isempty(errormsg)
|
---|
| 735 | GeometryCalib=[];
|
---|
| 736 | msgbox_uvmat('ERROR',errormsg)
|
---|
| 737 | return
|
---|
| 738 | end
|
---|
[1008] | 739 | GeometryCalib.fx_fy(1)=fx;
|
---|
| 740 | GeometryCalib.fx_fy(2)=fy;
|
---|
| 741 | GeometryCalib.Cx_Cy(1)=Cx;
|
---|
| 742 | GeometryCalib.Cx_Cy(2)=Cy;
|
---|
| 743 | GeometryCalib.kc=kc;
|
---|
[847] | 744 | fct_path=fullfile(path_UVMAT,'toolbox_calib');
|
---|
| 745 | addpath(fct_path)
|
---|
| 746 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%reverse Cx_Cy(2) for calibration (inversion of px ordinate)
|
---|
| 747 | [omc,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,...
|
---|
[1062] | 748 | (GeometryCalib.fx_fy)',GeometryCalib.Cx_Cy',[GeometryCalib.kc 0 0 0 0]);
|
---|
[847] | 749 | rmpath(fct_path);
|
---|
| 750 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
|
---|
| 751 | GeometryCalib.Tx_Ty_Tz=Tc1';
|
---|
[1062] | 752 | %inversion of z axis
|
---|
[847] | 753 | GeometryCalib.R=Rc1;
|
---|
| 754 | GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate
|
---|
| 755 | GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate
|
---|
| 756 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate
|
---|
| 757 | GeometryCalib.omc=(180/pi)*omc';
|
---|
| 758 |
|
---|
| 759 | %------------------------------------------------------------------------
|
---|
| 760 | %function GeometryCalib=calib_tsai_heikkila(Coord)
|
---|
| 761 | % TEST: NOT IMPLEMENTED
|
---|
| 762 | %------------------------------------------------------------------
|
---|
| 763 | % path_uvmat=which('uvmat');% check the path detected for source file uvmat
|
---|
| 764 | % path_UVMAT=fileparts(path_uvmat); %path to UVMAT
|
---|
| 765 | % path_calib=fullfile(path_UVMAT,'toolbox_calib_heikkila');
|
---|
| 766 | % addpath(path_calib)
|
---|
| 767 | % npoints=size(Coord,1);
|
---|
| 768 | % Coord(:,1:3)=10*Coord(:,1:3);
|
---|
| 769 | % Coord=[Coord zeros(npoints,2) -ones(npoints,1)];
|
---|
| 770 | % [par,pos,iter,res,er,C]=cacal('dalsa',Coord);
|
---|
| 771 | % GeometryCalib.CalibrationType='tsai';
|
---|
| 772 | % GeometryCalib.focal=par(2);
|
---|
| 773 |
|
---|
| 774 |
|
---|
| 775 | %------------------------------------------------------------------------
|
---|
| 776 | % --- determine the rms of calibration error
|
---|
| 777 | function ErrorRms=error_calib(calib_param,Calib,Coord)
|
---|
| 778 | %------------------------------------------------------------------------
|
---|
| 779 | %calib_param: vector of free calibration parameters (to optimise)
|
---|
| 780 | %Calib: structure of the given calibration parameters
|
---|
| 781 | %Coord: list of phys coordinates (columns 1-3, and pixel coordinates (columns 4-5)
|
---|
| 782 | Calib.f=25;
|
---|
| 783 | Calib.dpx=0.012;
|
---|
| 784 | Calib.dpy=0.012;
|
---|
| 785 | Calib.sx=1;
|
---|
| 786 | Calib.Cx=512;
|
---|
| 787 | Calib.Cy=512;
|
---|
| 788 | Calib.kappa1=calib_param(1);
|
---|
| 789 | Calib.Tx=calib_param(2);
|
---|
| 790 | Calib.Ty=calib_param(3);
|
---|
| 791 | Calib.Tz=calib_param(4);
|
---|
| 792 | alpha=calib_param(5);
|
---|
| 793 | Calib.R=[cos(alpha) sin(alpha) 0;-sin(alpha) cos(alpha) 0;0 0 -1];
|
---|
| 794 |
|
---|
| 795 | X=Coord(:,1);
|
---|
| 796 | Y=Coord(:,2);
|
---|
| 797 | Z=Coord(:,3);
|
---|
| 798 | x_ima=Coord(:,4);
|
---|
[1062] | 799 | y_ima=Coord(:,5);
|
---|
[847] | 800 | [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z);
|
---|
| 801 | ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
|
---|
| 802 | ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
|
---|
| 803 | ErrorRms=mean(ErrorRms);
|
---|
| 804 |
|
---|
| 805 |
|
---|
| 806 | %------------------------------------------------------------------------
|
---|
| 807 | % --- Executes on button press in STORE.
|
---|
| 808 | function STORE_Callback(hObject, eventdata, handles)
|
---|
| 809 | %------------------------------------------------------------------------
|
---|
| 810 | Coord=get(handles.ListCoord,'Data');
|
---|
| 811 | %Object=read_geometry_calib(Coord_cell);
|
---|
| 812 | unitlist=get(handles.CoordUnit,'String');
|
---|
| 813 | unit=unitlist{get(handles.CoordUnit,'value')};
|
---|
| 814 | GeometryCalib.CoordUnit=unit;
|
---|
| 815 | GeometryCalib.SourceCalib.PointCoord=Coord(:,1:5);
|
---|
| 816 | huvmat=findobj(allchild(0),'Name','uvmat');
|
---|
| 817 | hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
|
---|
| 818 | % RootPath='';
|
---|
| 819 | % RootFile='';
|
---|
| 820 | if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
|
---|
[1062] | 821 | % testhandle=1;
|
---|
[847] | 822 | RootPath=get(hhuvmat.RootPath,'String');
|
---|
| 823 | RootFile=get(hhuvmat.RootFile,'String');
|
---|
| 824 | filebase=[fullfile(RootPath,RootFile) '~'];
|
---|
| 825 | while exist([filebase '.xml'],'file')
|
---|
| 826 | filebase=[filebase '~'];
|
---|
| 827 | end
|
---|
| 828 | outputfile=[filebase '.xml'];
|
---|
| 829 | errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');
|
---|
| 830 | if ~strcmp(errormsg,'')
|
---|
| 831 | msgbox_uvmat('ERROR',errormsg);
|
---|
| 832 | end
|
---|
| 833 | listfile=get(handles.ListCoordFiles,'string');
|
---|
| 834 | if isequal(listfile,{''})
|
---|
| 835 | listfile={outputfile};
|
---|
| 836 | else
|
---|
| 837 | listfile=[listfile;{outputfile}];%update the list of coord files
|
---|
| 838 | end
|
---|
| 839 | set(handles.ListCoordFiles,'string',listfile);
|
---|
| 840 | end
|
---|
| 841 | ClearAll_Callback(hObject, eventdata, handles)% clear the current list and point plots
|
---|
| 842 |
|
---|
| 843 | % --------------------------------------------------------------------
|
---|
| 844 | % --- Executes on button press in ClearAll: clear the list of calibration points
|
---|
| 845 | function ClearAll_Callback(hObject, eventdata, handles)
|
---|
| 846 | % --------------------------------------------------------------------
|
---|
| 847 | set(handles.ListCoord,'Data',[])
|
---|
| 848 | PLOT_Callback(hObject, eventdata, handles)
|
---|
| 849 | update_calib_marker([]);%remove circle marker
|
---|
| 850 | set(handles.APPLY,'backgroundColor',[1 0 0])% set APPLY button to red color: no calibration wanted without points
|
---|
| 851 | set(handles.CheckEnableMouse,'value',1); %activate mouse to pick new points
|
---|
| 852 |
|
---|
| 853 | %------------------------------------------------------------------------
|
---|
| 854 | % --- Executes on button press in CLEAR LIST
|
---|
| 855 | function CLEAR_Callback(hObject, eventdata, handles)
|
---|
| 856 | %------------------------------------------------------------------------
|
---|
| 857 | set(handles.ListCoordFiles,'Value',1)
|
---|
| 858 | set(handles.ListCoordFiles,'String',{''})
|
---|
| 859 |
|
---|
| 860 | %------------------------------------------------------------------------
|
---|
| 861 | % --- Executes on selection change in CheckEnableMouse.
|
---|
| 862 | function CheckEnableMouse_Callback(hObject, eventdata, handles)
|
---|
| 863 | %------------------------------------------------------------------------
|
---|
| 864 | choice=get(handles.CheckEnableMouse,'Value');
|
---|
| 865 | if choice
|
---|
| 866 | huvmat=findobj(allchild(0),'tag','uvmat');
|
---|
| 867 | if ishandle(huvmat)
|
---|
| 868 | hhuvmat=guidata(huvmat);
|
---|
| 869 | set(hhuvmat.MenuRuler,'checked','off')%desactivate ruler
|
---|
| 870 | if get(hhuvmat.CheckEditObject,'Value')
|
---|
| 871 | set(hhuvmat.CheckEditObject,'Value',0)
|
---|
| 872 | uvmat('CheckEditObject_Callback',hhuvmat.CheckEditObject,[],hhuvmat)
|
---|
| 873 | end
|
---|
| 874 | set(hhuvmat.MenuRuler,'checked','off')%desactivate ruler
|
---|
| 875 | end
|
---|
| 876 | end
|
---|
| 877 |
|
---|
| 878 | % --------------------------------------------------------------------
|
---|
| 879 |
|
---|
[1062] | 880 | % function MenuHelp_Callback(hObject, eventdata, handles)
|
---|
| 881 | % web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#GeometryCalib')
|
---|
[847] | 882 |
|
---|
[1062] | 883 | %
|
---|
| 884 | function MenuSetScale_Callback(hObject,eventdata,handles)
|
---|
| 885 |
|
---|
[847] | 886 | answer=msgbox_uvmat('INPUT_TXT','scale pixel/cm?','');
|
---|
| 887 | %create test points
|
---|
| 888 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
|
---|
| 889 | hhuvmat=guidata(huvmat);
|
---|
| 890 | if ~strcmp(get(hhuvmat.Scalar,'Visible'),'on')
|
---|
| 891 | msgbox_uvmat('ERROR','An image needs to be opened in uvmat for calibration')
|
---|
| 892 | return
|
---|
| 893 | end
|
---|
| 894 | set(handles.calib_type,'Value',1)% set calib option to 'rescale'
|
---|
| 895 | npx=str2num(get(hhuvmat.num_Npx,'String'))/2;
|
---|
| 896 | npy=str2num(get(hhuvmat.num_Npy,'String'))/2;
|
---|
| 897 | Xima=[0.25*npx 0.75*npx 0.75*npx 0.25*npx]';
|
---|
| 898 | Yima=[0.25*npy 0.25*npy 0.75*npy 0.75*npy]';
|
---|
| 899 | x=Xima/str2num(answer);
|
---|
| 900 | y=Yima/str2num(answer);
|
---|
| 901 | Coord=[x y zeros(4,1) Xima Yima zeros(4,1)];
|
---|
| 902 | set(handles.ListCoord,'Data',Coord)
|
---|
| 903 | set(handles.APPLY,'BackgroundColor',[1 0 1])
|
---|
| 904 | set(handles.CheckEnableMouse,'value',0); %desactivate mouse to avoid spurious points
|
---|
| 905 |
|
---|
| 906 | %------------------------------------------------------------------------
|
---|
| 907 | function MenuCreateGrid_Callback(hObject, eventdata, handles)
|
---|
| 908 | %------------------------------------------------------------------------
|
---|
| 909 | CalibData=get(handles.geometry_calib,'UserData');
|
---|
| 910 | Tinput=[];%default
|
---|
| 911 | if isfield(CalibData,'grid')
|
---|
| 912 | Tinput=CalibData.grid;
|
---|
| 913 | end
|
---|
| 914 | [T,CalibData.grid]=create_grid(Tinput);%display the GUI create_grid
|
---|
| 915 | set(handles.geometry_calib,'UserData',CalibData)
|
---|
| 916 |
|
---|
| 917 | %grid in phys space
|
---|
| 918 | Coord=get(handles.ListCoord,'Data');
|
---|
| 919 | Coord(1:size(T,1),1:3)=T;%update the existing list of phys coordinates from the GUI create_grid
|
---|
| 920 | set(handles.ListCoord,'Data',Coord)
|
---|
| 921 | set(handles.APPLY,'BackgroundColor',[1 0 1])
|
---|
| 922 | set(handles.CheckEnableMouse,'value',0); %desactivate mouse to avoid spurious points
|
---|
| 923 |
|
---|
| 924 | % -----------------------------------------------------------------------
|
---|
[1062] | 925 | % --- automatic grid dectection from local maxima of the images
|
---|
[847] | 926 | function MenuDetectGrid_Callback(hObject, eventdata, handles)
|
---|
| 927 | %------------------------------------------------------------------------
|
---|
| 928 | %% read the four last point coordinates in pixels
|
---|
| 929 | Coord=get(handles.ListCoord,'Data');%read list of coordinates on geometry_calib
|
---|
| 930 | nbpoints=size(Coord,1); %nbre of calibration points
|
---|
| 931 | if nbpoints~=4
|
---|
| 932 | msgbox_uvmat('ERROR','four points must have be selected by the mouse to delimitate the phys grid area; the Ox axis will be defined by the two first points')
|
---|
| 933 | return
|
---|
| 934 | end
|
---|
| 935 | % corners_X=(Coord(end:-1:end-3,4)); %pixel absissa of the four corners
|
---|
[1062] | 936 | % corners_Y=(Coord(end:-1:end-3,5));
|
---|
[847] | 937 | corners_X=(Coord(:,4)); %pixel absissa of the four corners
|
---|
| 938 | corners_Y=(Coord(:,5));
|
---|
| 939 |
|
---|
| 940 | %%%%%%
|
---|
| 941 | % corners_X=1000*[1.5415 1.7557 1.7539 1.5415]';
|
---|
| 942 | % corners_Y=1000*[1.1515 1.1509 1.3645 1.3639]';
|
---|
| 943 |
|
---|
| 944 | %reorder the last two points (the two first in the list) if needed
|
---|
| 945 | angles=angle((corners_X-corners_X(1))+1i*(corners_Y-corners_Y(1)));
|
---|
| 946 | if abs(angles(4)-angles(2))>abs(angles(3)-angles(2))
|
---|
[1062] | 947 | X_end=corners_X(4);
|
---|
| 948 | Y_end=corners_Y(4);
|
---|
| 949 | corners_X(4)=corners_X(3);
|
---|
| 950 | corners_Y(4)=corners_Y(3);
|
---|
| 951 | corners_X(3)=X_end;
|
---|
| 952 | corners_Y(3)=Y_end;
|
---|
[847] | 953 | end
|
---|
| 954 |
|
---|
| 955 | %% initiate the grid in phys coordinates
|
---|
| 956 | CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib
|
---|
| 957 | grid_input=[];%default
|
---|
| 958 | if isfield(CalibData,'grid')
|
---|
| 959 | grid_input=CalibData.grid;%retrieve the previously used grid
|
---|
| 960 | end
|
---|
[993] | 961 | [T,CalibData.grid,CalibData.grid.CheckWhite,CalibData.grid.FilterWindow]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T
|
---|
[847] | 962 | set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use
|
---|
| 963 | X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm)
|
---|
| 964 | Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm)
|
---|
| 965 |
|
---|
| 966 | %% read the current image, displayed in the GUI uvmat
|
---|
| 967 | huvmat=findobj(allchild(0),'Name','uvmat');
|
---|
| 968 | UvData=get(huvmat,'UserData');
|
---|
| 969 | A=UvData.Field.A;%currently displayed image
|
---|
| 970 | npxy=size(A);
|
---|
| 971 |
|
---|
| 972 | %% calculate transform matrices for plane projection: rectangle assumed to be viewed in perspective
|
---|
| 973 | % reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren
|
---|
| 974 | B = [ X Y ones(size(X)) zeros(4,3) -X.*corners_X -Y.*corners_X ...
|
---|
[1062] | 975 | zeros(4,3) X Y ones(size(X)) -X.*corners_Y -Y.*corners_Y ];
|
---|
[847] | 976 | B = reshape (B', 8 , 8 )';
|
---|
| 977 | D = [ corners_X , corners_Y ];
|
---|
| 978 | D = reshape (D', 8 , 1 );
|
---|
| 979 | l = (B' * B)\B' * D;
|
---|
| 980 | Amat = reshape([l(1:6)' 0 0 1 ],3,3)';
|
---|
| 981 | C = [l(7:8)' 1];
|
---|
| 982 |
|
---|
[1062] | 983 | %% transform grid image into 'phys' coordinates
|
---|
[847] | 984 | GeometryCalib.CalibrationType='3D_linear';
|
---|
| 985 | GeometryCalib.fx_fy=[1 1];
|
---|
| 986 | GeometryCalib.Tx_Ty_Tz=[Amat(1,3) Amat(2,3) 1];
|
---|
| 987 | GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0];
|
---|
| 988 | GeometryCalib.CoordUnit='cm';
|
---|
| 989 | path_uvmat=which('uvmat');% check the path detected for source file uvmat
|
---|
| 990 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT
|
---|
| 991 | addpath(fullfile(path_UVMAT,'transform_field'))
|
---|
| 992 | Data.ListVarName={'Coord_y','Coord_x','A'};
|
---|
| 993 | Data.VarDimName={'Coord_y','Coord_x',{'Coord_y','Coord_x'}};
|
---|
| 994 | if ndims(A)==3
|
---|
| 995 | A=mean(A,3);
|
---|
| 996 | end
|
---|
| 997 | Data.A=A-min(min(A));
|
---|
| 998 | Data.Coord_y=[npxy(1)-0.5 0.5];
|
---|
| 999 | Data.Coord_x=[0.5 npxy(2)];
|
---|
| 1000 | Data.CoordUnit='pixel';
|
---|
| 1001 | Calib.GeometryCalib=GeometryCalib;
|
---|
| 1002 | DataOut=phys(Data,Calib);
|
---|
| 1003 | rmpath(fullfile(path_UVMAT,'transform_field'))
|
---|
| 1004 | Amod=DataOut.A;% current image expressed in 'phys' coord
|
---|
[1062] | 1005 | Rangx=DataOut.Coord_x;% x coordinates of first and last pixel centres in phys
|
---|
| 1006 | Rangy=DataOut.Coord_y;% y coordinates of first and last pixel centres in phys
|
---|
[847] | 1007 | if CalibData.grid.CheckWhite
|
---|
| 1008 | Amod=double(Amod);%case of white grid markers: will look for image maxima
|
---|
| 1009 | else
|
---|
| 1010 | Amod=-double(Amod);%case of black grid markers: will look for image minima
|
---|
| 1011 | end
|
---|
| 1012 |
|
---|
[993] | 1013 | %%%%%%filterfor i;proved detection of dots
|
---|
| 1014 | if ~isequal(CalibData.grid.FilterWindow,0)
|
---|
| 1015 | %definition of the cos shape matrix filter
|
---|
| 1016 | FilterBoxSize_x=CalibData.grid.FilterWindow;
|
---|
| 1017 | FilterBoxSize_y=CalibData.grid.FilterWindow;
|
---|
| 1018 | ix=1/2-FilterBoxSize_x/2:-1/2+FilterBoxSize_x/2;%
|
---|
| 1019 | iy=1/2-FilterBoxSize_y/2:-1/2+FilterBoxSize_y/2;%
|
---|
| 1020 | %del=np/3;
|
---|
| 1021 | %fct=exp(-(ix/del).^2);
|
---|
| 1022 | fct2_x=cos(ix/((FilterBoxSize_x-1)/2)*pi/2);
|
---|
| 1023 | fct2_y=cos(iy/((FilterBoxSize_y-1)/2)*pi/2);
|
---|
| 1024 | %Mfiltre=(ones(5,5)/5^2);
|
---|
| 1025 | Mfiltre=fct2_y'*fct2_x;
|
---|
| 1026 | Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter
|
---|
| 1027 |
|
---|
| 1028 | if ndims(Amod)==3
|
---|
| 1029 | Amod=filter2(Mfiltre,sum(Amod,3));%filter the input image, after summation on the color component (for color images)
|
---|
| 1030 | else
|
---|
| 1031 | Amod=filter2(Mfiltre,Amod);
|
---|
| 1032 | end
|
---|
| 1033 | end
|
---|
| 1034 | %%%%%%%%%%%%%%
|
---|
| 1035 |
|
---|
| 1036 |
|
---|
[847] | 1037 | %% detection of local image extrema in each direction
|
---|
| 1038 | Dx=(Rangx(2)-Rangx(1))/(npxy(2)-1); %x mesh in real space
|
---|
| 1039 | Dy=(Rangy(2)-Rangy(1))/(npxy(1)-1); %y mesh in real space
|
---|
| 1040 | 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
|
---|
| 1041 | 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
|
---|
| 1042 | nbpoints=size(T,1);
|
---|
| 1043 | TIndex=ones(size(T));% image indices corresponding to point coordinates
|
---|
| 1044 | %look for image maxima around each expected grid point
|
---|
| 1045 | for ipoint=1:nbpoints
|
---|
| 1046 | i0=1+round((T(ipoint,1)-Rangx(1))/Dx);% x index of the expected point in the phys image Amod
|
---|
| 1047 | j0=1+round((T(ipoint,2)-Rangy(1))/Dy);% y index of the expected point in the phys image Amod
|
---|
| 1048 | j0min=max(j0-ind_range_y,1);% min y index selected for the subimage (cut at the edge to avoid index <1)
|
---|
| 1049 | j0max=min(j0+ind_range_y,size(Amod,1));% max y index selected for the subimage (cut at the edge to avoid index > size)
|
---|
| 1050 | i0min=max(i0-ind_range_x,1);% min x index selected for the subimage (cut at the edge to avoid index <1)
|
---|
| 1051 | i0max=min(i0+ind_range_x,size(Amod,2));% max x index selected for the subimage (cut at the edge to avoid index > size)
|
---|
| 1052 | Asub=Amod(j0min:j0max,i0min:i0max); %subimage used to find brigthness extremum
|
---|
| 1053 | x_profile=sum(Asub,1);%profile of subimage summed over y
|
---|
| 1054 | y_profile=sum(Asub,2);%profile of subimage summed over x
|
---|
[1062] | 1055 |
|
---|
[847] | 1056 | [tild,ind_x_max]=max(x_profile);% index of max for the x profile
|
---|
| 1057 | [tild,ind_y_max]=max(y_profile);% index of max for the y profile
|
---|
| 1058 | %sub-pixel improvement using moments
|
---|
| 1059 | x_shift=0;
|
---|
| 1060 | y_shift=0;
|
---|
| 1061 | if ind_x_max+2<=numel(x_profile) && ind_x_max-2>=1
|
---|
| 1062 | Atop=x_profile(ind_x_max-2:ind_x_max+2);% extract x profile around the max
|
---|
| 1063 | x_shift=sum(Atop.*[-2 -1 0 1 2])/sum(Atop);
|
---|
| 1064 | end
|
---|
| 1065 | if ind_y_max+2<=numel(y_profile) && ind_y_max-2>=1
|
---|
| 1066 | Atop=y_profile(ind_y_max-2:ind_y_max+2);% extract y profile around the max
|
---|
| 1067 | y_shift=sum(Atop.*[-2 -1 0 1 2]')/sum(Atop);
|
---|
| 1068 | end
|
---|
| 1069 | %%%%
|
---|
[1062] | 1070 | % if ipoint==9
|
---|
| 1071 | % figure(11)
|
---|
| 1072 | % imagesc(Asub)
|
---|
| 1073 | % figure(12)
|
---|
| 1074 | % plot(x_profile,'r')
|
---|
| 1075 | % hold on
|
---|
| 1076 | % plot(y_profile,'b')
|
---|
| 1077 | % grid on
|
---|
| 1078 | % end
|
---|
| 1079 | %%%%
|
---|
[847] | 1080 | TIndex(ipoint,1)=(i0min+ind_x_max-1+x_shift);% x position of the maximum (in index of Amod)
|
---|
| 1081 | TIndex(ipoint,2)=(j0min+ind_y_max-1+y_shift);% y position of the maximum (in index of Amod)
|
---|
| 1082 | end
|
---|
| 1083 | Tmod(:,1)=(TIndex(:,1)-1)*Dx+Rangx(1);
|
---|
| 1084 | Tmod(:,2)=(TIndex(:,2)-1)*Dy+Rangy(1);
|
---|
[1062] | 1085 | %Tmod=T(:,(1:2))+Delta;% 'phys' coordinates of the detected points
|
---|
[847] | 1086 | [Xpx,Ypx]=px_XYZ(GeometryCalib,Tmod(:,1),Tmod(:,2));% image coordinates of the detected points
|
---|
| 1087 | Coord=[T Xpx Ypx zeros(size(T,1),1)];
|
---|
| 1088 | set(handles.ListCoord,'Data',Coord)
|
---|
| 1089 | PLOT_Callback(hObject, eventdata, handles)
|
---|
| 1090 | set(handles.APPLY,'BackgroundColor',[1 0 1])
|
---|
| 1091 | set(handles.CheckEnableMouse,'value',0); %desactivate mouse to avoid spurious points
|
---|
| 1092 |
|
---|
| 1093 |
|
---|
| 1094 | %-----------------------------------------------------------------------
|
---|
| 1095 | function MenuTranslatePoints_Callback(hObject, eventdata, handles)
|
---|
| 1096 | %-----------------------------------------------------------------------
|
---|
| 1097 | %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib
|
---|
| 1098 | CalibData=get(handles.geometry_calib,'UserData');
|
---|
| 1099 | Tinput=[];%default
|
---|
| 1100 | if isfield(CalibData,'translate')
|
---|
| 1101 | Tinput=CalibData.translate;
|
---|
| 1102 | end
|
---|
[1062] | 1103 | T=translate_points(Tinput);%display translate_points GUI and get shift parameters
|
---|
[847] | 1104 | CalibData.translate=T;
|
---|
| 1105 | set(handles.geometry_calib,'UserData',CalibData)
|
---|
| 1106 | %translation
|
---|
| 1107 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1108 | Coord(:,1)=T(1)+Coord(:,1);
|
---|
| 1109 | Coord(:,2)=T(2)+Coord(:,2);
|
---|
| 1110 | Coord(:,3)=T(3)+Coord(:,3);
|
---|
| 1111 | set(handles.ListCoord,'Data',Coord);
|
---|
| 1112 | set(handles.APPLY,'BackgroundColor',[1 0 1])
|
---|
| 1113 |
|
---|
| 1114 | % --------------------------------------------------------------------
|
---|
| 1115 | function MenuRotatePoints_Callback(hObject, eventdata, handles)
|
---|
| 1116 | %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib
|
---|
| 1117 | CalibData=get(handles.geometry_calib,'UserData');
|
---|
| 1118 | Tinput=[];%default
|
---|
| 1119 | if isfield(CalibData,'rotate')
|
---|
| 1120 | Tinput=CalibData.rotate;
|
---|
| 1121 | end
|
---|
[1062] | 1122 | T=rotate_points(Tinput);%display rotate_points GUI to introduce rotation parameters
|
---|
[847] | 1123 | CalibData.rotate=T;
|
---|
| 1124 | set(handles.geometry_calib,'UserData',CalibData)
|
---|
| 1125 | %-----------------------------------------------------
|
---|
| 1126 | %rotation
|
---|
| 1127 | Phi=T(1);
|
---|
| 1128 | O_x=0;%default
|
---|
| 1129 | O_y=0;%default
|
---|
| 1130 | if numel(T)>=2
|
---|
| 1131 | O_x=T(2);%default
|
---|
| 1132 | end
|
---|
| 1133 | if numel(T)>=3
|
---|
| 1134 | O_y=T(3);%default
|
---|
| 1135 | end
|
---|
| 1136 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1137 | r1=cos(pi*Phi/180);
|
---|
| 1138 | r2=-sin(pi*Phi/180);
|
---|
| 1139 | r3=sin(pi*Phi/180);
|
---|
| 1140 | r4=cos(pi*Phi/180);
|
---|
| 1141 | x=Coord(:,1)-O_x;
|
---|
| 1142 | y=Coord(:,2)-O_y;
|
---|
| 1143 | Coord(:,1)=r1*x+r2*y;
|
---|
| 1144 | Coord(:,2)=r3*x+r4*y;
|
---|
| 1145 | set(handles.ListCoord,'Data',Coord)
|
---|
| 1146 | set(handles.APPLY,'BackgroundColor',[1 0 1])
|
---|
| 1147 |
|
---|
| 1148 | % --------------------------------------------------------------------
|
---|
[891] | 1149 | function MenuFlip_x_Callback(hObject, eventdata, handles)
|
---|
| 1150 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1151 | Coord(:,1)=-Coord(:,1);
|
---|
| 1152 | set(handles.ListCoord,'Data',Coord)
|
---|
| 1153 |
|
---|
| 1154 | % --------------------------------------------------------------------
|
---|
| 1155 | function MenuFlip_y_Callback(hObject, eventdata, handles)
|
---|
| 1156 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1157 | Coord(:,2)=-Coord(:,2);
|
---|
| 1158 | set(handles.ListCoord,'Data',Coord)
|
---|
| 1159 |
|
---|
| 1160 | % --------------------------------------------------------------------
|
---|
[847] | 1161 | function MenuImportPoints_Callback(hObject, eventdata, handles)
|
---|
| 1162 | fileinput=browse_xml(hObject, eventdata, handles);
|
---|
| 1163 | if isempty(fileinput)
|
---|
| 1164 | return
|
---|
| 1165 | end
|
---|
| 1166 | [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib');
|
---|
| 1167 | if ~isfield(s,'GeometryCalib')
|
---|
| 1168 | msgbox_uvmat('ERROR','invalid input file: no geometry_calib data')
|
---|
| 1169 | return
|
---|
| 1170 | end
|
---|
| 1171 | GeometryCalib=s.GeometryCalib;
|
---|
| 1172 | if ~(isfield(GeometryCalib,'SourceCalib')&&isfield(GeometryCalib.SourceCalib,'PointCoord'))
|
---|
[1062] | 1173 | msgbox_uvmat('ERROR','invalid input file: no calibration points')
|
---|
[847] | 1174 | return
|
---|
| 1175 | end
|
---|
| 1176 | Coord=GeometryCalib.SourceCalib.PointCoord;
|
---|
| 1177 | Coord=[Coord zeros(size(Coord,1),1)];
|
---|
| 1178 | set(handles.ListCoord,'Data',Coord)
|
---|
| 1179 | PLOT_Callback(handles.geometry_calib, [], handles)
|
---|
| 1180 | set(handles.APPLY,'BackgroundColor',[1 0 1])
|
---|
| 1181 | set(handles.CheckEnableMouse,'value',0); %desactivate mouse to avoid modifications by default
|
---|
| 1182 |
|
---|
| 1183 | % -----------------------------------------------------------------------
|
---|
| 1184 | function MenuImportIntrinsic_Callback(hObject, eventdata, handles)
|
---|
| 1185 | %------------------------------------------------------------------------
|
---|
| 1186 | fileinput=browse_xml(hObject, eventdata, handles);
|
---|
| 1187 | if isempty(fileinput)
|
---|
| 1188 | return
|
---|
| 1189 | end
|
---|
| 1190 | [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib');
|
---|
| 1191 | GeometryCalib=s.GeometryCalib;
|
---|
| 1192 | display_intrinsic(GeometryCalib,handles)
|
---|
| 1193 |
|
---|
| 1194 | % -----------------------------------------------------------------------
|
---|
| 1195 | function MenuImportAll_Callback(hObject, eventdata, handles)
|
---|
| 1196 | %------------------------------------------------------------------------
|
---|
| 1197 | fileinput=browse_xml(hObject, eventdata, handles);
|
---|
| 1198 | if ~isempty(fileinput)
|
---|
| 1199 | loadfile(handles,fileinput)
|
---|
| 1200 | end
|
---|
| 1201 | set(handles.CheckEnableMouse,'value',0); %desactivate mouse to avoid modifications by default
|
---|
| 1202 |
|
---|
| 1203 | % -----------------------------------------------------------------------
|
---|
| 1204 | % --- Executes on menubar option Import/Grid file: introduce previous grid files
|
---|
| 1205 | function MenuGridFile_Callback(hObject, eventdata, handles)
|
---|
| 1206 | % -----------------------------------------------------------------------
|
---|
| 1207 | inputfile=browse_xml(hObject, eventdata, handles);
|
---|
| 1208 | listfile=get(handles.ListCoordFiles,'String');
|
---|
| 1209 | if isequal(listfile,{''})
|
---|
| 1210 | listfile={inputfile};
|
---|
| 1211 | else
|
---|
| 1212 | listfile=[listfile;{inputfile}];%update the list of coord files
|
---|
| 1213 | end
|
---|
| 1214 | set(handles.ListCoordFiles,'String',listfile);
|
---|
| 1215 |
|
---|
| 1216 |
|
---|
| 1217 | %------------------------------------------------------------------------
|
---|
| 1218 | function fileinput=browse_xml(hObject, eventdata, handles)
|
---|
| 1219 | %------------------------------------------------------------------------
|
---|
| 1220 | fileinput=[];%default
|
---|
| 1221 | oldfile=''; %default
|
---|
| 1222 | UserData=get(handles.geometry_calib,'UserData');
|
---|
| 1223 | if isfield(UserData,'XmlInputFile')
|
---|
| 1224 | oldfile=UserData.XmlInputFile;
|
---|
| 1225 | end
|
---|
| 1226 | [FileName, PathName, filterindex] = uigetfile( ...
|
---|
[1062] | 1227 | {'*.xml;*.mat', ' (*.xml,*.mat)';
|
---|
| 1228 | '*.xml', '.xml files '; ...
|
---|
| 1229 | '*.mat', '.mat matlab files '}, ...
|
---|
| 1230 | 'Pick a file',oldfile);
|
---|
| 1231 | fileinput=[PathName FileName];%complete file name
|
---|
[847] | 1232 | testblank=findstr(fileinput,' ');%look for blanks
|
---|
| 1233 | if ~isempty(testblank)
|
---|
| 1234 | msgbox_uvmat('ERROR','forbidden input file name or path: no blank character allowed')
|
---|
| 1235 | return
|
---|
| 1236 | end
|
---|
| 1237 | sizf=size(fileinput);
|
---|
| 1238 | if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
|
---|
| 1239 | UserData.XmlInputFile=fileinput;
|
---|
| 1240 | set(handles.geometry_calib,'UserData',UserData)%record current file foer further use of browser
|
---|
| 1241 |
|
---|
| 1242 | % -----------------------------------------------------------------------
|
---|
| 1243 | function Heading=loadfile(handles,fileinput)
|
---|
| 1244 | %------------------------------------------------------------------------
|
---|
| 1245 | Heading=[];%default
|
---|
| 1246 | [s,errormsg]=imadoc2struct(fileinput,'Heading','GeometryCalib');
|
---|
| 1247 | if ~isempty(errormsg)
|
---|
| 1248 | msgbox_uvmat('ERROR',errormsg)
|
---|
| 1249 | return
|
---|
| 1250 | end
|
---|
| 1251 | if ~isempty(s.Heading)
|
---|
| 1252 | Heading=s.Heading;
|
---|
| 1253 | end
|
---|
| 1254 |
|
---|
| 1255 | GeometryCalib=s.GeometryCalib;
|
---|
| 1256 | fx=1;fy=1;Cx=0;Cy=0;kc=0; %default
|
---|
| 1257 | CoordCell={};
|
---|
| 1258 | Tabchar={};%default
|
---|
| 1259 | val_cal=1;%default
|
---|
| 1260 | if ~isempty(GeometryCalib)
|
---|
| 1261 | % choose the calibration option
|
---|
| 1262 | if isfield(GeometryCalib,'CalibrationType')
|
---|
| 1263 | calib_list=get(handles.calib_type,'String');
|
---|
| 1264 | for ilist=1:numel(calib_list)
|
---|
| 1265 | if strcmp(calib_list{ilist},GeometryCalib.CalibrationType)
|
---|
| 1266 | val_cal=ilist;
|
---|
| 1267 | break
|
---|
| 1268 | end
|
---|
| 1269 | end
|
---|
| 1270 | end
|
---|
| 1271 | display_intrinsic(GeometryCalib,handles)%intrinsic param
|
---|
| 1272 | %extrinsic param
|
---|
| 1273 | if isfield(GeometryCalib,'Tx_Ty_Tz')
|
---|
| 1274 | Tx_Ty_Tz=GeometryCalib.Tx_Ty_Tz;
|
---|
| 1275 | set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4))
|
---|
| 1276 | set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4))
|
---|
| 1277 | set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4))
|
---|
| 1278 | end
|
---|
| 1279 | if isfield(GeometryCalib,'omc')
|
---|
| 1280 | set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4))
|
---|
| 1281 | set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4))
|
---|
| 1282 | set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
|
---|
| 1283 | end
|
---|
| 1284 | if isfield(GeometryCalib,'SourceCalib')&& isfield(GeometryCalib.SourceCalib,'PointCoord')
|
---|
| 1285 | calib=GeometryCalib.SourceCalib.PointCoord;
|
---|
| 1286 | Coord=[calib zeros(size(calib,1),1)];
|
---|
| 1287 | set(handles.ListCoord,'Data',Coord)
|
---|
| 1288 | end
|
---|
| 1289 | PLOT_Callback(handles.geometry_calib, [], handles)
|
---|
| 1290 | set(handles.APPLY,'BackgroundColor',[1 0 1])
|
---|
| 1291 | end
|
---|
| 1292 | set(handles.calib_type,'Value',val_cal)
|
---|
| 1293 |
|
---|
| 1294 | if isempty(CoordCell)% allow mouse action by default in the absence of input points
|
---|
| 1295 | set(handles.CheckEnableMouse,'Value',1)
|
---|
| 1296 | set(handles.CheckEnableMouse,'BackgroundColor',[1 1 0])
|
---|
| 1297 | else % does not allow mouse action by default in the presence of input points
|
---|
| 1298 | set(handles.CheckEnableMouse,'Value',0)
|
---|
| 1299 | set(handles.CheckEnableMouse,'BackgroundColor',[0.7 0.7 0.7])
|
---|
| 1300 | end
|
---|
| 1301 |
|
---|
| 1302 | %------------------------------------------------------------------------
|
---|
| 1303 | %---display calibration intrinsic parameters
|
---|
| 1304 | function display_intrinsic(GeometryCalib,handles)
|
---|
| 1305 | %------------------------------------------------------------------------
|
---|
| 1306 | fx=[];
|
---|
| 1307 | fy=[];
|
---|
| 1308 | if isfield(GeometryCalib,'fx_fy')
|
---|
| 1309 | fx=GeometryCalib.fx_fy(1);
|
---|
| 1310 | fy=GeometryCalib.fx_fy(2);
|
---|
| 1311 | end
|
---|
| 1312 | Cx_Cy=[0 0];%default
|
---|
| 1313 | if isfield(GeometryCalib,'Cx_Cy')
|
---|
| 1314 | Cx_Cy=GeometryCalib.Cx_Cy;
|
---|
| 1315 | end
|
---|
| 1316 | kc=0;
|
---|
| 1317 | if isfield(GeometryCalib,'kc')
|
---|
| 1318 | kc=GeometryCalib.kc; %* GeometryCalib.focal*GeometryCalib.focal;
|
---|
| 1319 | end
|
---|
| 1320 | set(handles.fx,'String',num2str(fx,5))
|
---|
| 1321 | set(handles.fy,'String',num2str(fy,5))
|
---|
| 1322 | set(handles.Cx,'String',num2str(Cx_Cy(1),'%1.1f'))
|
---|
| 1323 | set(handles.Cy,'String',num2str(Cx_Cy(2),'%1.1f'))
|
---|
| 1324 | set(handles.kc,'String',num2str(kc,'%1.4f'))
|
---|
| 1325 |
|
---|
[1001] | 1326 | %------------------------------------------------------------------------
|
---|
| 1327 | % ---display calibration extrinsic parameters
|
---|
| 1328 | function display_extrinsic(GeometryCalib,handles)
|
---|
| 1329 | %------------------------------------------------------------------------
|
---|
| 1330 | set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4))
|
---|
| 1331 | set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4))
|
---|
| 1332 | set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4))
|
---|
| 1333 | set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4))
|
---|
| 1334 | set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4))
|
---|
| 1335 | set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
|
---|
[847] | 1336 |
|
---|
[1001] | 1337 | %------------------------------------------------------------------------
|
---|
| 1338 | % --- executes when user attempts to close geometry_calib.
|
---|
[847] | 1339 | function geometry_calib_CloseRequestFcn(hObject, eventdata, handles)
|
---|
[1001] | 1340 | %------------------------------------------------------------------------
|
---|
[847] | 1341 | delete(hObject); % closes the figure
|
---|
| 1342 |
|
---|
| 1343 | %------------------------------------------------------------------------
|
---|
[1001] | 1344 | % --- executes on button press in PLOT.
|
---|
[847] | 1345 | %------------------------------------------------------------------------
|
---|
| 1346 | function PLOT_Callback(hObject, eventdata, handles)
|
---|
| 1347 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
|
---|
| 1348 | hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat
|
---|
| 1349 | h_menu_coord=findobj(huvmat,'Tag','TransformName');
|
---|
| 1350 | menu=get(h_menu_coord,'String');
|
---|
| 1351 | choice=get(h_menu_coord,'Value');
|
---|
| 1352 | option='';
|
---|
| 1353 | if iscell(menu)
|
---|
| 1354 | option=menu{choice};
|
---|
| 1355 | end
|
---|
| 1356 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1357 | if ~isempty(Coord)
|
---|
| 1358 | if isequal(option,'phys')
|
---|
| 1359 | Coord_plot=Coord(:,1:3);
|
---|
| 1360 | elseif isempty(option);%optionoption,'px')||isequal(option,'')
|
---|
| 1361 | Coord_plot=Coord(:,4:5);
|
---|
| 1362 | else
|
---|
| 1363 | msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be blank or phys ')
|
---|
| 1364 | end
|
---|
| 1365 | end
|
---|
| 1366 |
|
---|
| 1367 | set(0,'CurrentFigure',huvmat)
|
---|
| 1368 | set(huvmat,'CurrentAxes',hhuvmat.PlotAxes)
|
---|
| 1369 | hh=findobj('Tag','calib_points');
|
---|
| 1370 | if ~isempty(Coord) && isempty(hh)
|
---|
[926] | 1371 | hh=line(Coord_plot(:,1),Coord_plot(:,2),'Color','m','Tag','calib_points','LineStyle','none','Marker','+','MarkerSize',10);
|
---|
[847] | 1372 | elseif isempty(Coord)%empty list of points, suppress the plot
|
---|
| 1373 | delete(hh)
|
---|
| 1374 | else
|
---|
| 1375 | set(hh,'XData',Coord_plot(:,1))
|
---|
| 1376 | set(hh,'YData',Coord_plot(:,2))
|
---|
| 1377 | end
|
---|
| 1378 | pause(.1)
|
---|
| 1379 | figure(handles.geometry_calib)
|
---|
| 1380 |
|
---|
[1062] | 1381 | %------------------------------------------------------------------------
|
---|
[847] | 1382 | % --- Executes on button press in Copy: display Coord on the Matlab work space
|
---|
| 1383 | %------------------------------------------------------------------------
|
---|
| 1384 | function Copy_Callback(hObject, eventdata, handles)
|
---|
| 1385 | global Coord
|
---|
| 1386 | evalin('base','global Coord')%make CurData global in the workspace
|
---|
| 1387 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1388 | display('coordinates of calibration points (phys,px,marker) :')
|
---|
| 1389 | evalin('base','Coord') %display CurData in the workspace
|
---|
| 1390 | commandwindow; %brings the Matlab command window to the front
|
---|
| 1391 |
|
---|
[1062] | 1392 | %------------------------------------------------------------------------
|
---|
[847] | 1393 | % --- Executes when selected cell(s) is changed in ListCoord.
|
---|
[1062] | 1394 | %------------------------------------------------------------------------
|
---|
[847] | 1395 | function ListCoord_CellSelectionCallback(hObject, eventdata, handles)
|
---|
| 1396 | if ~isempty(eventdata.Indices)
|
---|
| 1397 | iline=eventdata.Indices(1);% selected line number
|
---|
| 1398 | set(handles.CoordLine,'String',num2str(iline))
|
---|
[1062] | 1399 | Data=get(handles.ListCoord,'Data');
|
---|
| 1400 | update_calib_marker(Data(iline,:))
|
---|
[847] | 1401 | end
|
---|
| 1402 |
|
---|
[1062] | 1403 | %------------------------------------------------------------------------
|
---|
[847] | 1404 | % --- Executes when entered data in editable cell(s) in ListCoord.
|
---|
[1062] | 1405 | %------------------------------------------------------------------------
|
---|
[847] | 1406 | function ListCoord_CellEditCallback(hObject, eventdata, handles)
|
---|
| 1407 |
|
---|
| 1408 | Input=str2num(eventdata.EditData);%pasted input
|
---|
| 1409 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1410 | iline=eventdata.Indices(1);% selected line number
|
---|
| 1411 | if size(Coord,1)<iline+numel(Input)
|
---|
| 1412 | Coord=[Coord ; zeros(iline+numel(Input)-size(Coord,1),6)];% append zeros to fit the new column
|
---|
| 1413 | end
|
---|
| 1414 | Coord(iline:iline+numel(Input)-1,eventdata.Indices(2))=Input';
|
---|
| 1415 | set(handles.ListCoord,'Data',Coord)
|
---|
| 1416 | PLOT_Callback(hObject, eventdata, handles)
|
---|
| 1417 |
|
---|
| 1418 | %------------------------------------------------------------------------
|
---|
| 1419 | % --- 'key_press_fcn:' function activated when a key is pressed on the keyboard
|
---|
| 1420 | %------------------------------------------------------------------------
|
---|
| 1421 | function ListCoord_KeyPressFcn(hObject, eventdata, handles)
|
---|
| 1422 | iline=str2num(get(handles.CoordLine,'String'));
|
---|
| 1423 | xx=double(get(handles.geometry_calib,'CurrentCharacter'));%get the keyboard character
|
---|
[851] | 1424 | if ismember(xx,[28 29 30 31])% directional arrow
|
---|
[847] | 1425 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1426 | switch xx
|
---|
| 1427 | case 30 % arrow upward
|
---|
| 1428 | iline=iline-1;
|
---|
| 1429 | case 31% arrow downward
|
---|
| 1430 | iline=iline+1;
|
---|
| 1431 | end
|
---|
| 1432 | if iline>=1 && iline<=size(Coord,1)
|
---|
| 1433 | set(handles.CoordLine,'String',num2str(iline))
|
---|
| 1434 | update_calib_marker(Coord(iline,1:5))% show the point corresponding to the selected line
|
---|
| 1435 | end
|
---|
| 1436 | else
|
---|
| 1437 | set(handles.APPLY,'BackgroundColor',[1 0 1])% paint APPLY in magenta to indicate that the table content has be modified
|
---|
[851] | 1438 | if ismember(xx,[127 31])% delete, or downward
|
---|
| 1439 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1440 | iline=str2double(get(handles.CoordLine,'String'));
|
---|
| 1441 | if isequal(xx, 31)
|
---|
| 1442 | if isequal(iline,size(Coord,1))% arrow downward
|
---|
| 1443 | Coord=[Coord;zeros(1,size(Coord,2))];
|
---|
| 1444 | end
|
---|
| 1445 | else
|
---|
| 1446 | Coord(iline,:)=[];% suppress the current line
|
---|
| 1447 | end
|
---|
| 1448 | set(handles.ListCoord,'Data',Coord);
|
---|
| 1449 | end
|
---|
[847] | 1450 | end
|
---|
| 1451 |
|
---|
| 1452 | %------------------------------------------------------------------------
|
---|
| 1453 | % --- update the plot of calibration points
|
---|
[1062] | 1454 | %------------------------------------------------------------------------
|
---|
[847] | 1455 | % draw a circle around the point defined by the input coordinates Coord as given by line in the table Listcoord
|
---|
| 1456 | function update_calib_marker(Coord)
|
---|
| 1457 |
|
---|
| 1458 | %% read config on uvmat
|
---|
| 1459 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
|
---|
| 1460 | hhuvmat=guidata(huvmat);
|
---|
| 1461 | hhh=findobj(hhuvmat.PlotAxes,'Tag','calib_marker');
|
---|
| 1462 | if numel(Coord)<5
|
---|
| 1463 | if ~isempty(hhh)
|
---|
| 1464 | delete(hhh)%delete the circle marker in case of no valid input
|
---|
| 1465 | end
|
---|
| 1466 | return
|
---|
| 1467 | end
|
---|
| 1468 | menu=get(hhuvmat.TransformName,'String');
|
---|
| 1469 | choice=get(hhuvmat.TransformName,'Value');
|
---|
| 1470 | option='';
|
---|
| 1471 | if iscell(menu)
|
---|
| 1472 | option=menu{choice};
|
---|
| 1473 | end
|
---|
| 1474 |
|
---|
| 1475 | %% read appropriate coordinates (px or phys) in the table ListCoord
|
---|
[1062] | 1476 | if isequal(option,'phys') % use phys coord
|
---|
[847] | 1477 | XCoord=Coord(1);
|
---|
| 1478 | YCoord=Coord(2);
|
---|
| 1479 | elseif isempty(option)% use coord in pixels
|
---|
| 1480 | XCoord=Coord(4);
|
---|
| 1481 | YCoord=Coord(5);
|
---|
| 1482 | else
|
---|
| 1483 | msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be blank or phys ')
|
---|
| 1484 | return
|
---|
| 1485 | end
|
---|
| 1486 |
|
---|
| 1487 | %% adjust the plot limits if needed
|
---|
| 1488 | xlim=get(hhuvmat.PlotAxes,'XLim');
|
---|
| 1489 | ylim=get(hhuvmat.PlotAxes,'YLim');
|
---|
| 1490 | ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/25;%defines the size of the circle marker
|
---|
| 1491 | check_xlim=0;
|
---|
| 1492 | if XCoord>xlim(2)
|
---|
| 1493 | xlim=xlim+XCoord-xlim(2)+ind_range;% translate plot limit
|
---|
| 1494 | check_xlim=1;
|
---|
| 1495 | elseif XCoord<xlim(1)
|
---|
| 1496 | xlim=xlim-XCoord+xlim(1)-ind_range;% translate plot limit
|
---|
| 1497 | check_xlim=1;
|
---|
| 1498 | end
|
---|
| 1499 | if check_xlim
|
---|
| 1500 | set(hhuvmat.PlotAxes,'XLim',xlim);
|
---|
| 1501 | set(hhuvmat.num_MaxX,'String',num2str(xlim(2)));
|
---|
| 1502 | set(hhuvmat.num_MinX,'String',num2str(xlim(1)));
|
---|
| 1503 | end
|
---|
| 1504 | check_ylim=0;
|
---|
| 1505 | if YCoord>ylim(2)
|
---|
| 1506 | ylim=ylim+YCoord-ylim(2)+ind_range;% translate plot limit
|
---|
| 1507 | check_ylim=1;
|
---|
| 1508 | elseif YCoord<ylim(1)
|
---|
| 1509 | ylim=ylim-YCoord+ylim(1)-ind_range;% translate plot limit
|
---|
| 1510 | check_ylim=1;
|
---|
| 1511 | end
|
---|
| 1512 | if check_ylim
|
---|
| 1513 | set(hhuvmat.PlotAxes,'YLim',ylim);
|
---|
| 1514 | set(hhuvmat.num_MaxY,'String',num2str(ylim(2)));
|
---|
| 1515 | set(hhuvmat.num_MinY,'String',num2str(ylim(1)));
|
---|
| 1516 | end
|
---|
| 1517 |
|
---|
| 1518 | %% plot a circle around the selected point
|
---|
| 1519 | if isempty(hhh)
|
---|
| 1520 | set(0,'CurrentFig',huvmat)
|
---|
| 1521 | set(huvmat,'CurrentAxes',hhuvmat.PlotAxes)
|
---|
| 1522 | rectangle('Curvature',[1 1],...
|
---|
| 1523 | 'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range],'EdgeColor','m',...
|
---|
| 1524 | 'LineStyle','-','Tag','calib_marker');
|
---|
| 1525 | else
|
---|
| 1526 | set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range])
|
---|
| 1527 | end
|
---|
| 1528 |
|
---|
| 1529 | %------------------------------------------------------------------------
|
---|
| 1530 | % --- Executes on button press in ClearPoint: remove the selected line in the table Coord
|
---|
| 1531 | %------------------------------------------------------------------------
|
---|
| 1532 | function ClearPoint_Callback(hObject, eventdata, handles)
|
---|
| 1533 |
|
---|
| 1534 | Coord=get(handles.ListCoord,'Data');
|
---|
| 1535 | iline=str2num(get(handles.CoordLine,'String'));
|
---|
| 1536 | if isempty(iline)
|
---|
| 1537 | msgbox_uvmat('WARNING','no line suppressed, select a line in the table')
|
---|
| 1538 | else
|
---|
| 1539 | answer=msgbox_uvmat('INPUT_Y-N',['suppress line ' num2str(iline) '?']);
|
---|
| 1540 | if isequal(answer,'Yes')
|
---|
| 1541 | Coord(iline,:)=[];
|
---|
| 1542 | set(handles.APPLY,'BackgroundColor',[1 0 1])
|
---|
| 1543 | set(handles.ListCoord,'Data',Coord);
|
---|
| 1544 | set(handles.CoordLine,'String','')
|
---|
| 1545 | PLOT_Callback(hObject,eventdata,handles)
|
---|
| 1546 | update_calib_marker([]);%remove circle marker
|
---|
| 1547 | end
|
---|
| 1548 | end
|
---|
[891] | 1549 |
|
---|
| 1550 |
|
---|
| 1551 |
|
---|