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