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