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