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