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