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 | %A%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
13 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
14 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
15 | % This file is part of the toolbox UVMAT. |
---|
16 | % |
---|
17 | % UVMAT is free software; you can redistribute it and/or modify |
---|
18 | % it under the terms of the GNU General Public License as published by |
---|
19 | % the Free Software Foundation; either version 2 of the License, or |
---|
20 | % (at your option) any later version. |
---|
21 | % |
---|
22 | % UVMAT is distributed in the hope that it will be useful, |
---|
23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
25 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
26 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
27 | |
---|
28 | function varargout = geometry_calib(varargin) |
---|
29 | % GEOMETRY_CALIB M-file for geometry_calib.fig |
---|
30 | % GEOMETRY_CALIB, by itself, creates a MenuCoord GEOMETRY_CALIB or raises the existing |
---|
31 | % singleton*. |
---|
32 | % |
---|
33 | % H = GEOMETRY_CALIB returns the handle to a MenuCoord GEOMETRY_CALIB or the handle to |
---|
34 | % the existing singleton*. |
---|
35 | % |
---|
36 | % GEOMETRY_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local |
---|
37 | % function named CALLBACK in GEOMETRY_CALIB.M with the given input arguments. |
---|
38 | % |
---|
39 | % GEOMETRY_CALIB('Property','Value',...) creates a MenuCoord GEOMETRY_CALIB or raises the |
---|
40 | % existing singleton*. Starting from the left, property value pairs are |
---|
41 | % applied to the GUI before geometry_calib_OpeningFunction gets called. An |
---|
42 | % unrecognized property name or invalid value makes property application |
---|
43 | % stop. All inputs are passed to geometry_calib_OpeningFcn via varargin. |
---|
44 | % |
---|
45 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one |
---|
46 | % instance to run (singleton)". |
---|
47 | % |
---|
48 | % See also: GUIDE, GUIDATA, GUIHANDLES |
---|
49 | |
---|
50 | % Edit the above text to modify the response to help geometry_calib |
---|
51 | |
---|
52 | % Last Modified by GUIDE v2.5 05-Oct-2010 13:47:00 |
---|
53 | |
---|
54 | % Begin initialization code - DO NOT edit |
---|
55 | gui_Singleton = 1; |
---|
56 | gui_State = struct('gui_Name', mfilename, ... |
---|
57 | 'gui_Singleton', gui_Singleton, ... |
---|
58 | 'gui_OpeningFcn', @geometry_calib_OpeningFcn, ... |
---|
59 | 'gui_OutputFcn', @geometry_calib_OutputFcn, ... |
---|
60 | 'gui_LayoutFcn', [] , ... |
---|
61 | 'gui_Callback', []); |
---|
62 | if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once')) |
---|
63 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
64 | end |
---|
65 | |
---|
66 | if nargout |
---|
67 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
68 | else |
---|
69 | gui_mainfcn(gui_State, varargin{:}); |
---|
70 | end |
---|
71 | % End initialization code - DO NOT edit |
---|
72 | |
---|
73 | |
---|
74 | % --- Executes just before geometry_calib is made visible. |
---|
75 | %INPUT: |
---|
76 | %handles: handles of the geometry_calib interface elements |
---|
77 | % PlotHandles: set of handles of the elements contolling the plotting |
---|
78 | % parameters on the uvmat interface (obtained by 'get_plot_handle.m') |
---|
79 | %------------------------------------------------------------------------ |
---|
80 | function geometry_calib_OpeningFcn(hObject, eventdata, handles,inputfile,pos) |
---|
81 | %------------------------------------------------------------------------ |
---|
82 | % Choose default command line output for geometry_calib |
---|
83 | |
---|
84 | handles.output = hObject; |
---|
85 | |
---|
86 | % Update handles structure |
---|
87 | guidata(hObject, handles); |
---|
88 | set(hObject,'DeleteFcn',{@closefcn})% |
---|
89 | |
---|
90 | %set the position of the interface |
---|
91 | if exist('pos','var')&& length(pos)>=4 |
---|
92 | % %pos_gui=get(hObject,'Position'); |
---|
93 | % pos_gui(1)=pos(1); |
---|
94 | % pos_gui(2)=pos(2); |
---|
95 | set(hObject,'Position',pos); |
---|
96 | end |
---|
97 | |
---|
98 | %set menu of calibration options |
---|
99 | set(handles.calib_type,'String',{'rescale';'linear';'3D_linear';'3D_quadr';'3D_extrinsic'}) |
---|
100 | inputxml=''; |
---|
101 | if exist('inputfile','var')&& ~isempty(inputfile) |
---|
102 | struct.XmlInputFile=inputfile; |
---|
103 | [Pathsub,RootFile,field_count,str2,str_a,str_b,ext]=name2display(inputfile); |
---|
104 | if ~strcmp(ext,'.xml') |
---|
105 | inputfile=[fullfile(Pathsub,RootFile) '.xml'];%xml file corresponding to the input file |
---|
106 | end |
---|
107 | set(handles.ListCoord,'String',{'......'}) |
---|
108 | if exist(inputfile,'file') |
---|
109 | Heading=loadfile(handles,inputfile);% load the point coordiantes existing in the xml file |
---|
110 | if isfield(Heading,'Campaign')&& ischar(Heading.Campaign) |
---|
111 | struct.Campaign=Heading.Campaign; |
---|
112 | end |
---|
113 | end |
---|
114 | set(hObject,'UserData',struct) |
---|
115 | end |
---|
116 | |
---|
117 | set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function |
---|
118 | |
---|
119 | |
---|
120 | %------------------------------------------------------------------------ |
---|
121 | % --- Outputs from this function are returned to the command line. |
---|
122 | function varargout = geometry_calib_OutputFcn(hObject, eventdata, handles) |
---|
123 | %------------------------------------------------------------------------ |
---|
124 | % Get default command line output from handles structure |
---|
125 | varargout{1} = handles.output; |
---|
126 | varargout{2}=handles; |
---|
127 | % |
---|
128 | %------------------------------------------------------------------------ |
---|
129 | % executed when closing: set the parent interface button to value 0 |
---|
130 | function closefcn(gcbo,eventdata) |
---|
131 | %------------------------------------------------------------------------ |
---|
132 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
133 | if ~isempty(huvmat) |
---|
134 | handles=guidata(huvmat); |
---|
135 | % set(handles.MenuMask,'enable','on') |
---|
136 | % set(handles.MenuGrid,'enable','on') |
---|
137 | % set(handles.MenuObject,'enable','on') |
---|
138 | % set(handles.MenuEdit,'enable','on') |
---|
139 | % set(handles.edit,'enable','on') |
---|
140 | hobject=findobj(handles.axes3,'tag','calib_points'); |
---|
141 | if ~isempty(hobject) |
---|
142 | delete(hobject) |
---|
143 | end |
---|
144 | hobject=findobj(handles.axes3,'tag','calib_marker'); |
---|
145 | if ~isempty(hobject) |
---|
146 | delete(hobject) |
---|
147 | end |
---|
148 | end |
---|
149 | |
---|
150 | %------------------------------------------------------------------------ |
---|
151 | % --- Executes on button press in calibrate_lin. |
---|
152 | function APPLY_Callback(hObject, eventdata, handles) |
---|
153 | %------------------------------------------------------------------------ |
---|
154 | %read the current calibration points |
---|
155 | Coord_cell=get(handles.ListCoord,'String'); |
---|
156 | Object=read_geometry_calib(Coord_cell); |
---|
157 | Coord=Object.Coord; |
---|
158 | % apply the calibration, whose type is selected in handles.calib_type |
---|
159 | if ~isempty(Coord) |
---|
160 | calib_cell=get(handles.calib_type,'String'); |
---|
161 | val=get(handles.calib_type,'Value'); |
---|
162 | GeometryCalib=feval(['calib_' calib_cell{val}],Coord,handles); |
---|
163 | else |
---|
164 | msgbox_uvmat('ERROR','No calibration points, abort') |
---|
165 | return |
---|
166 | end |
---|
167 | Z_plane=[]; |
---|
168 | if ~isempty(Coord) |
---|
169 | %check error |
---|
170 | X=Coord(:,1); |
---|
171 | Y=Coord(:,2); |
---|
172 | Z=Coord(:,3); |
---|
173 | x_ima=Coord(:,4); |
---|
174 | y_ima=Coord(:,5); |
---|
175 | [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z); |
---|
176 | GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); |
---|
177 | [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima)); |
---|
178 | GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); |
---|
179 | [GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima)); |
---|
180 | [EM,ind_dim]=max(GeometryCalib.ErrorMax); |
---|
181 | index=index(ind_dim); |
---|
182 | %set the Z position of the reference plane used for calibration |
---|
183 | if isequal(max(Z),min(Z))%Z constant |
---|
184 | Z_plane=Z(1); |
---|
185 | GeometryCalib.NbSlice=1; |
---|
186 | GeometryCalib.SliceCoord=[0 0 Z_plane]; |
---|
187 | end |
---|
188 | end |
---|
189 | %set the coordinate unit |
---|
190 | unitlist=get(handles.CoordUnit,'String'); |
---|
191 | unit=unitlist{get(handles.CoordUnit,'value')}; |
---|
192 | GeometryCalib.CoordUnit=unit; |
---|
193 | %record the points |
---|
194 | GeometryCalib.SourceCalib.PointCoord=Coord; |
---|
195 | display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters |
---|
196 | |
---|
197 | % Display extrinsinc parameters (rotation and translation of camera with respect to the phys coordiantes) |
---|
198 | set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) |
---|
199 | set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) |
---|
200 | set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) |
---|
201 | set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) |
---|
202 | set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) |
---|
203 | set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) |
---|
204 | |
---|
205 | % store the calibration data, by default in the xml file of the currently displayed image |
---|
206 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
207 | UvData=get(huvmat,'UserData'); |
---|
208 | NbSlice_j=1;%default |
---|
209 | ZStart=Z_plane; |
---|
210 | ZEnd=Z_plane; |
---|
211 | volume_scan='n'; |
---|
212 | if isfield(UvData,'XmlData') |
---|
213 | UvData.XmlData |
---|
214 | if isfield(UvData.XmlData,'TranslationMotor') |
---|
215 | NbSlice_j=UvData.XmlData.TranslationMotor.Nbslice; |
---|
216 | ZStart=UvData.XmlData.TranslationMotor.ZStart/10; |
---|
217 | ZEnd=UvData.XmlData.TranslationMotor.ZEnd/10; |
---|
218 | volume_scan='y'; |
---|
219 | end |
---|
220 | end |
---|
221 | hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat |
---|
222 | RootPath=''; |
---|
223 | RootFile=''; |
---|
224 | if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile) |
---|
225 | testhandle=1; |
---|
226 | RootPath=get(hhuvmat.RootPath,'String'); |
---|
227 | RootFile=get(hhuvmat.RootFile,'String'); |
---|
228 | filebase=fullfile(RootPath,RootFile); |
---|
229 | outputfile=[filebase '.xml'];%xml file associated with the currently displayed image |
---|
230 | else |
---|
231 | question={'save the calibration data and point coordinates in'}; |
---|
232 | def={fullfile(RootPath,'ObjectCalib.xml')}; |
---|
233 | options.Resize='on'; |
---|
234 | answer=inputdlg(question,'save average in a new file',1,def,options); |
---|
235 | outputfile=answer{1}; |
---|
236 | end |
---|
237 | answer=msgbox_uvmat('INPUT_Y-N',{[outputfile ' updated with calibration data'];... |
---|
238 | ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];... |
---|
239 | ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']}); |
---|
240 | |
---|
241 | %% record the calibration parameters and display the current image of uvmat in the new phys coordinates |
---|
242 | if strcmp(answer,'Yes') |
---|
243 | if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration |
---|
244 | input_key={'Z (first position)','Z (last position)','Z (water surface)', 'refractive index','NbSlice','volume scan (y/n)','tilt angle y axis','tilt angle x axis'}; |
---|
245 | input_val=[{num2str(ZEnd)} {num2str(ZStart)} {num2str(ZStart)} {'1.333'} num2str(NbSlice_j) {volume_scan} {'0'} {'0'}]; |
---|
246 | answer=inputdlg(input_key,'slice position(s)',ones(1,8), input_val,'on'); |
---|
247 | %answer_1=msgbox_uvmat('INPUT_TXT',' Z= ',num2str(Z_plane)); |
---|
248 | GeometryCalib.NbSlice=str2double(answer{5}); |
---|
249 | GeometryCalib.VolumeScan=answer{6}; |
---|
250 | if isempty(answer) |
---|
251 | Z_plane=0; %default |
---|
252 | else |
---|
253 | Z_plane=linspace(str2double(answer{1}),str2double(answer{2}),GeometryCalib.NbSlice); |
---|
254 | end |
---|
255 | GeometryCalib.SliceCoord=Z_plane'*[0 0 1]; |
---|
256 | GeometryCalib.SliceAngle(:,3)=0; |
---|
257 | GeometryCalib.SliceAngle(:,2)=str2double(answer{7})*ones(GeometryCalib.NbSlice,1);%rotation around y axis (to generalise) |
---|
258 | GeometryCalib.SliceAngle(:,1)=str2double(answer{8})*ones(GeometryCalib.NbSlice,1);%rotation around x axis (to generalise) |
---|
259 | GeometryCalib.InterfaceCoord=[0 0 str2double(answer{3})]; |
---|
260 | GeometryCalib.RefractionIndex=str2double(answer{4}); |
---|
261 | end |
---|
262 | errormsg=update_imadoc(GeometryCalib,outputfile);% introduce the calibration data in the xml file |
---|
263 | if ~strcmp(errormsg,'') |
---|
264 | msgbox_uvmat('ERROR',errormsg); |
---|
265 | end |
---|
266 | |
---|
267 | %display image with new calibration in the currently opened uvmat interface |
---|
268 | hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');% delete calib points and markers |
---|
269 | if ~isempty(hhh) |
---|
270 | delete(hhh); |
---|
271 | end |
---|
272 | hhh=findobj(hhuvmat.axes3,'Tag','calib_points'); |
---|
273 | if ~isempty(hhh) |
---|
274 | delete(hhh); |
---|
275 | end |
---|
276 | set(hhuvmat.FixLimits,'Value',0)% put FixedLimits option to 'off' |
---|
277 | set(hhuvmat.FixLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
278 | UserData=get(handles.geometry_calib,'UserData'); |
---|
279 | UserData.XmlInputFile=outputfile;%save the current xml file name |
---|
280 | set(handles.geometry_calib,'UserData',UserData) |
---|
281 | uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat, show the image in phys coordinates |
---|
282 | MenuPlot_Callback(hObject, eventdata, handles) |
---|
283 | set(handles.ListCoord,'Value',index)% indicate in the list the point with max deviation (possible mistake) |
---|
284 | ListCoord_Callback(hObject, eventdata, handles) |
---|
285 | figure(handles.geometry_calib) |
---|
286 | end |
---|
287 | |
---|
288 | %------------------------------------------------------------------ |
---|
289 | % --- Executes on button press in calibrate_lin. |
---|
290 | |
---|
291 | function REPLICATE_Callback(hObject, eventdata, handles) |
---|
292 | %------------------------------------------------------------------------ |
---|
293 | |
---|
294 | %% Apply calibration |
---|
295 | calib_cell=get(handles.calib_type,'String'); %#ok<NASGU> |
---|
296 | val=get(handles.calib_type,'Value'); %#ok<NASGU> |
---|
297 | |
---|
298 | %read the current calibration points |
---|
299 | Coord_cell=get(handles.ListCoord,'String'); |
---|
300 | Object=read_geometry_calib(Coord_cell); |
---|
301 | Coord=Object.Coord; |
---|
302 | |
---|
303 | % apply the calibration, whose type is selected in handles.calib_type |
---|
304 | if ~isempty(Coord) |
---|
305 | calib_cell=get(handles.calib_type,'String'); |
---|
306 | val=get(handles.calib_type,'Value'); |
---|
307 | GeometryCalib=feval(['calib_' calib_cell{val}],Coord,handles); |
---|
308 | else |
---|
309 | msgbox_uvmat('ERROR','No calibration points, abort') |
---|
310 | return |
---|
311 | end |
---|
312 | |
---|
313 | if ~isempty(Coord) |
---|
314 | %check error |
---|
315 | X=Coord(:,1); |
---|
316 | Y=Coord(:,2); |
---|
317 | Z=Coord(:,3); |
---|
318 | x_ima=Coord(:,4); |
---|
319 | y_ima=Coord(:,5); |
---|
320 | [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z); |
---|
321 | GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); |
---|
322 | [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima)); |
---|
323 | GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); |
---|
324 | [GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima)); |
---|
325 | [EM,ind_dim]=max(GeometryCalib.ErrorMax); |
---|
326 | % index=index(ind_dim); |
---|
327 | %set the Z position of the reference plane used for calibration |
---|
328 | Z_plane=[]; |
---|
329 | if isequal(max(Z),min(Z)) |
---|
330 | Z_plane=Z(1); |
---|
331 | end |
---|
332 | answer_1=msgbox_uvmat('INPUT_TXT',' Z= ',num2str(Z_plane)); |
---|
333 | Z_plane=str2double(answer_1); |
---|
334 | GeometryCalib.NbSlice=1; |
---|
335 | GeometryCalib.SliceCoord=[0 0 Z_plane]; |
---|
336 | %set the coordinate unit |
---|
337 | unitlist=get(handles.CoordUnit,'String'); |
---|
338 | unit=unitlist{get(handles.CoordUnit,'value')}; |
---|
339 | GeometryCalib.CoordUnit=unit; |
---|
340 | %record the points |
---|
341 | GeometryCalib.SourceCalib.PointCoord=Coord; |
---|
342 | end |
---|
343 | |
---|
344 | %% display calibration paprameters |
---|
345 | display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters |
---|
346 | |
---|
347 | % Display extrinsinc parameters (rotation and translation of camera with respect to the phys coordiantes) |
---|
348 | set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) |
---|
349 | set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) |
---|
350 | set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) |
---|
351 | set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) |
---|
352 | set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) |
---|
353 | set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) |
---|
354 | |
---|
355 | %% open the GUI dataview |
---|
356 | h_dataview=findobj(allchild(0),'name','dataview'); |
---|
357 | if ~isempty(h_dataview) |
---|
358 | delete(h_dataview) |
---|
359 | end |
---|
360 | CalibData=get(handles.geometry_calib,'UserData');%read the calibration image source on the interface userdata |
---|
361 | InputFile=''; |
---|
362 | if isfield(CalibData,'XmlInputFile') |
---|
363 | InputDir=fileparts(CalibData.XmlInputFile); |
---|
364 | [InputDir,DirName]=fileparts(InputDir); |
---|
365 | end |
---|
366 | SubCampaignTest='n'; %default |
---|
367 | testup=0; |
---|
368 | if isfield(CalibData,'SubCampaign') |
---|
369 | SubCampaignTest='y'; |
---|
370 | dir_ref=CalibData.SubCampaign; |
---|
371 | testup=1; |
---|
372 | elseif isfield(CalibData,'Campaign') |
---|
373 | dir_ref=CalibData.Campaign; |
---|
374 | testup=1; |
---|
375 | end |
---|
376 | while testup |
---|
377 | [InputDir,DirName]=fileparts(InputDir); |
---|
378 | if strcmp(DirName,dir_ref) |
---|
379 | break |
---|
380 | end |
---|
381 | end |
---|
382 | InputDir=fullfile(InputDir,DirName); |
---|
383 | answer=msgbox_uvmat('INPUT_TXT','Campaign ?',InputDir); |
---|
384 | if strcmp(answer,'Cancel') |
---|
385 | return |
---|
386 | end |
---|
387 | |
---|
388 | dataview(answer,SubCampaignTest,GeometryCalib); |
---|
389 | |
---|
390 | % if isfield(Heading,'Device') && isequal([filename ext],Heading.Device) |
---|
391 | % [XmlInput,filename,ext]=fileparts(XmlInput); |
---|
392 | % Device=Heading.Device; |
---|
393 | % end |
---|
394 | % if isfield(Heading,'Experiment') && isequal([filename ext],Heading.Experiment) |
---|
395 | % [PP,filename,ext]=fileparts(XmlInput); |
---|
396 | % end |
---|
397 | % testinput=0; |
---|
398 | % if isfield(Heading,'SubCampaign') && isequal([filename ext],Heading.SubCampaign) |
---|
399 | % SubCampaignTest='y'; |
---|
400 | % testinput=1; |
---|
401 | % elseif isfield(Heading,'Campaign') && isequal([filename ext],Heading.Campaign) |
---|
402 | % testinput=1; |
---|
403 | % % end |
---|
404 | % end |
---|
405 | % if ~testinput |
---|
406 | % filename='PROJETS';%default |
---|
407 | % if isfield(CalibData,'XmlInputFile') |
---|
408 | % [pp,filename]=fileparts(CalibData.XmlInputFile); |
---|
409 | % end |
---|
410 | % while ~isequal(filename,'PROJETS') && numel(filename)>1 |
---|
411 | % filename_1=filename; |
---|
412 | % pp_1=pp; |
---|
413 | % [pp,filename]=fileparts(pp); |
---|
414 | % end |
---|
415 | % XmlInput=fullfile(pp_1,filename_1); |
---|
416 | % testinput=1; |
---|
417 | % end |
---|
418 | % if testinput |
---|
419 | % outcome=dataview(XmlInput,SubCampaignTest,GeometryCalib); |
---|
420 | % end |
---|
421 | |
---|
422 | %------------------------------------------------------------------------ |
---|
423 | % determine the parameters for a calibration by an affine function (rescaling and offset, no rotation) |
---|
424 | function GeometryCalib=calib_rescale(Coord,handles) |
---|
425 | %------------------------------------------------------------------------ |
---|
426 | X=Coord(:,1); |
---|
427 | Y=Coord(:,2);% Z not used |
---|
428 | x_ima=Coord(:,4); |
---|
429 | y_ima=Coord(:,5); |
---|
430 | [px,sx]=polyfit(X,x_ima,1); |
---|
431 | [py,sy]=polyfit(Y,y_ima,1); |
---|
432 | T_x=px(2); |
---|
433 | T_y=py(2); |
---|
434 | GeometryCalib.CalibrationType='rescale'; |
---|
435 | GeometryCalib.fx_fy=[px(1) py(1)];%.fx_fy corresponds to pxcm along x and y |
---|
436 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
437 | GeometryCalib.Tx_Ty_Tz=[px(2)/px(1) py(2)/py(1) 1]; |
---|
438 | %GeometryCalib.R=[1,0,0;0,1,0;0,0,0]; |
---|
439 | GeometryCalib.omc=[0 0 0]; |
---|
440 | |
---|
441 | %------------------------------------------------------------------------ |
---|
442 | % determine the parameters for a calibration by a linear transform matrix (rescale and rotation) |
---|
443 | |
---|
444 | |
---|
445 | function GeometryCalib=calib_linear(Coord,handles) |
---|
446 | %------------------------------------------------------------------------ |
---|
447 | X=Coord(:,1); |
---|
448 | Y=Coord(:,2);% Z not used |
---|
449 | x_ima=Coord(:,4); |
---|
450 | y_ima=Coord(:,5); |
---|
451 | XY_mat=[ones(size(X)) X Y]; |
---|
452 | a_X1=XY_mat\x_ima; %transformation matrix for X |
---|
453 | % x1=XY_mat*a_X1;%reconstruction |
---|
454 | % err_X1=max(abs(x1-x_ima));%error |
---|
455 | a_Y1=XY_mat\y_ima;%transformation matrix for X |
---|
456 | % y1=XY_mat*a_Y1; |
---|
457 | % err_Y1=max(abs(y1-y_ima));%error |
---|
458 | % R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1]; |
---|
459 | R=[a_X1(2),a_X1(3);a_Y1(2),a_Y1(3)]; |
---|
460 | epsilon=sign(det(R)); |
---|
461 | norm=abs(det(R)); |
---|
462 | GeometryCalib.CalibrationType='linear'; |
---|
463 | if (a_X1(2)/a_Y1(3))>0 |
---|
464 | GeometryCalib.fx_fy(1)=sqrt((a_X1(2)/a_Y1(3))*norm); |
---|
465 | else |
---|
466 | GeometryCalib.fx_fy(1)=-sqrt(-(a_X1(2)/a_Y1(3))*norm); |
---|
467 | end |
---|
468 | GeometryCalib.fx_fy(2)=(a_Y1(3)/a_X1(2))*GeometryCalib.fx_fy(1); |
---|
469 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
470 | %GeometryCalib.Tx_Ty_Tz=[a_X1(1) a_Y1(1) 1]; |
---|
471 | GeometryCalib.Tx_Ty_Tz=[a_X1(1)/GeometryCalib.fx_fy(1) a_Y1(1)/GeometryCalib.fx_fy(2) 1]; |
---|
472 | R(1,:)=R(1,:)/GeometryCalib.fx_fy(1); |
---|
473 | R(2,:)=R(2,:)/GeometryCalib.fx_fy(2); |
---|
474 | R=[R;[0 0]]; |
---|
475 | GeometryCalib.R=[R [0;0;-epsilon]]; |
---|
476 | GeometryCalib.omc=(180/pi)*[acos(GeometryCalib.R(1,1)) 0 0]; |
---|
477 | %------------------------------------------------------------------------ |
---|
478 | % determine the tsai parameters for a view normal to the grid plane |
---|
479 | % NOT USED |
---|
480 | function GeometryCalib=calib_normal(Coord,handles) |
---|
481 | %------------------------------------------------------------------------ |
---|
482 | Calib.f1=str2num(get(handles.fx,'String')); |
---|
483 | Calib.f2=str2num(get(handles.fy,'String')); |
---|
484 | Calib.k=str2num(get(handles.kc,'String')); |
---|
485 | Calib.Cx=str2num(get(handles.Cx,'String')); |
---|
486 | Calib.Cy=str2num(get(handles.Cy,'String')); |
---|
487 | %default |
---|
488 | if isempty(Calib.f1) |
---|
489 | Calib.f1=25/0.012; |
---|
490 | end |
---|
491 | if isempty(Calib.f2) |
---|
492 | Calib.f2=25/0.012; |
---|
493 | end |
---|
494 | if isempty(Calib.k) |
---|
495 | Calib.k=0; |
---|
496 | end |
---|
497 | if isempty(Calib.Cx)||isempty(Calib.Cy) |
---|
498 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
---|
499 | hhuvmat=guidata(huvmat); |
---|
500 | Calib.Cx=str2num(get(hhuvmat.npx,'String'))/2; |
---|
501 | Calib.Cx=str2num(get(hhuvmat.npy,'String'))/2; |
---|
502 | end |
---|
503 | %tsai parameters |
---|
504 | Calib.dpx=0.012;%arbitrary |
---|
505 | Calib.dpy=0.012; |
---|
506 | Calib.sx=Calib.f1*Calib.dpx/(Calib.f2*Calib.dpy); |
---|
507 | Calib.f=Calib.f2*Calib.dpy; |
---|
508 | Calib.kappa1=Calib.k/(Calib.f*Calib.f); |
---|
509 | |
---|
510 | %initial guess |
---|
511 | X=Coord(:,1); |
---|
512 | Y=Coord(:,2); |
---|
513 | Zmean=mean(Coord(:,3)); |
---|
514 | x_ima=Coord(:,4)-Calib.Cx; |
---|
515 | y_ima=Coord(:,5)-Calib.Cy; |
---|
516 | XY_mat=[ones(size(X)) X Y]; |
---|
517 | a_X1=XY_mat\x_ima; %transformation matrix for X |
---|
518 | a_Y1=XY_mat\y_ima;%transformation matrix for Y |
---|
519 | R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,-1];% rotation+ z axis reversal (upward) |
---|
520 | norm=sqrt(det(-R)); |
---|
521 | calib_param(1)=0;% quadratic distortion |
---|
522 | calib_param(2)=a_X1(1); |
---|
523 | calib_param(3)=a_Y1(1); |
---|
524 | calib_param(4)=Calib.f/(norm*Calib.dpx)-R(3,3)*Zmean; |
---|
525 | calib_param(5)=angle(a_X1(2)+1i*a_X1(3)); |
---|
526 | display(['initial guess=' num2str(calib_param)]) |
---|
527 | |
---|
528 | %optimise the parameters: minimisation of error |
---|
529 | calib_param = fminsearch(@(calib_param) error_calib(calib_param,Calib,Coord),calib_param); |
---|
530 | |
---|
531 | GeometryCalib.CalibrationType='tsai_normal'; |
---|
532 | GeometryCalib.focal=Calib.f; |
---|
533 | GeometryCalib.dpx_dpy=[Calib.dpx Calib.dpy]; |
---|
534 | GeometryCalib.Cx_Cy=[Calib.Cx Calib.Cy]; |
---|
535 | GeometryCalib.sx=Calib.sx; |
---|
536 | GeometryCalib.kappa1=calib_param(1); |
---|
537 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
538 | GeometryCalib.Tx_Ty_Tz=[calib_param(2) calib_param(3) calib_param(4)]; |
---|
539 | alpha=calib_param(5); |
---|
540 | GeometryCalib.R=[cos(alpha) sin(alpha) 0;-sin(alpha) cos(alpha) 0;0 0 -1]; |
---|
541 | |
---|
542 | %------------------------------------------------------------------------ |
---|
543 | function GeometryCalib=calib_3D_linear(Coord,handles) |
---|
544 | %------------------------------------------------------------------ |
---|
545 | path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
546 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
547 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
---|
548 | hhuvmat=guidata(huvmat); |
---|
549 | coord_files=get(handles.coord_files,'String'); |
---|
550 | if ischar(coord_files) |
---|
551 | coord_files={coord_files}; |
---|
552 | end |
---|
553 | if isempty(coord_files{1}) || isequal(coord_files,{''}) |
---|
554 | coord_files={}; |
---|
555 | end |
---|
556 | %retrieve the calibration points stored in the files listed in the popup list coord_files |
---|
557 | x_1=Coord(:,4:5)';%px coordinates of the ref points |
---|
558 | nx=str2num(get(hhuvmat.npx,'String')); |
---|
559 | ny=str2num(get(hhuvmat.npy,'String')); |
---|
560 | x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates |
---|
561 | X_1=Coord(:,1:3)';%phys coordinates of the ref points |
---|
562 | n_ima=numel(coord_files)+1; |
---|
563 | if ~isempty(coord_files) |
---|
564 | msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used']) |
---|
565 | for ifile=1:numel(coord_files) |
---|
566 | t=xmltree(coord_files{ifile}); |
---|
567 | s=convert(t);%convert to matlab structure |
---|
568 | if isfield(s,'GeometryCalib') |
---|
569 | if isfield(s.GeometryCalib,'SourceCalib') |
---|
570 | if isfield(s.GeometryCalib.SourceCalib,'PointCoord') |
---|
571 | PointCoord=s.GeometryCalib.SourceCalib.PointCoord; |
---|
572 | Coord_file=zeros(length(PointCoord),5);%default |
---|
573 | for i=1:length(PointCoord) |
---|
574 | line=str2num(PointCoord{i}); |
---|
575 | Coord_file(i,4:5)=line(4:5);%px x |
---|
576 | Coord_file(i,1:3)=line(1:3);%phys x |
---|
577 | end |
---|
578 | eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']); |
---|
579 | eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]); |
---|
580 | eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']); |
---|
581 | end |
---|
582 | end |
---|
583 | end |
---|
584 | end |
---|
585 | end |
---|
586 | n_ima=numel(coord_files)+1; |
---|
587 | est_dist=[0;0;0;0;0]; |
---|
588 | est_aspect_ratio=0; |
---|
589 | est_fc=[1;1]; |
---|
590 | %fc=[25;25]/0.012; |
---|
591 | center_optim=0; |
---|
592 | run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim')); |
---|
593 | GeometryCalib.CalibrationType='3D_linear'; |
---|
594 | GeometryCalib.fx_fy=fc'; |
---|
595 | %GeometryCalib.focal=fc(2); |
---|
596 | %GeometryCalib.dpx_dpy=[1 1]; |
---|
597 | GeometryCalib.Cx_Cy=cc'; |
---|
598 | %GeometryCalib.sx=fc(1)/fc(2); |
---|
599 | GeometryCalib.kc=kc(1); |
---|
600 | %GeometryCalib.kappa1=-kc(1)/fc(2)^2; |
---|
601 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
602 | GeometryCalib.Tx_Ty_Tz=Tc_1'; |
---|
603 | GeometryCalib.R=Rc_1; |
---|
604 | GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate |
---|
605 | GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate |
---|
606 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate |
---|
607 | GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees |
---|
608 | GeometryCalib.ErrorRMS=[]; |
---|
609 | GeometryCalib.ErrorMax=[]; |
---|
610 | |
---|
611 | %------------------------------------------------------------------------ |
---|
612 | function GeometryCalib=calib_3D_quadr(Coord,handles) |
---|
613 | %------------------------------------------------------------------ |
---|
614 | |
---|
615 | path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
616 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
617 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
---|
618 | hhuvmat=guidata(huvmat); |
---|
619 | % check_cond=0; |
---|
620 | coord_files=get(handles.coord_files,'String'); |
---|
621 | if ischar(coord_files) |
---|
622 | coord_files={coord_files}; |
---|
623 | end |
---|
624 | if isempty(coord_files{1}) || isequal(coord_files,{''}) |
---|
625 | coord_files={}; |
---|
626 | end |
---|
627 | |
---|
628 | %retrieve the calibration points stored in the files listed in the popup list coord_files |
---|
629 | x_1=Coord(:,4:5)';%px coordinates of the ref points |
---|
630 | nx=str2num(get(hhuvmat.npx,'String')); |
---|
631 | ny=str2num(get(hhuvmat.npy,'String')); |
---|
632 | x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates |
---|
633 | X_1=Coord(:,1:3)';%phys coordinates of the ref points |
---|
634 | n_ima=numel(coord_files)+1; |
---|
635 | if ~isempty(coord_files) |
---|
636 | msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used']) |
---|
637 | for ifile=1:numel(coord_files) |
---|
638 | t=xmltree(coord_files{ifile}); |
---|
639 | s=convert(t);%convert to matlab structure |
---|
640 | if isfield(s,'GeometryCalib') |
---|
641 | if isfield(s.GeometryCalib,'SourceCalib') |
---|
642 | if isfield(s.GeometryCalib.SourceCalib,'PointCoord') |
---|
643 | PointCoord=s.GeometryCalib.SourceCalib.PointCoord; |
---|
644 | Coord_file=zeros(length(PointCoord),5);%default |
---|
645 | for i=1:length(PointCoord) |
---|
646 | line=str2num(PointCoord{i}); |
---|
647 | Coord_file(i,4:5)=line(4:5);%px x |
---|
648 | Coord_file(i,1:3)=line(1:3);%phys x |
---|
649 | end |
---|
650 | eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']); |
---|
651 | eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]); |
---|
652 | eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']); |
---|
653 | end |
---|
654 | end |
---|
655 | end |
---|
656 | end |
---|
657 | end |
---|
658 | n_ima=numel(coord_files)+1; |
---|
659 | est_dist=[1;0;0;0;0]; |
---|
660 | est_aspect_ratio=1; |
---|
661 | %est_fc=[0;0]; |
---|
662 | %fc=[25;25]/0.012; |
---|
663 | center_optim=0; |
---|
664 | run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim')); |
---|
665 | |
---|
666 | GeometryCalib.CalibrationType='3D_quadr'; |
---|
667 | GeometryCalib.fx_fy=fc'; |
---|
668 | %GeometryCalib.focal=fc(2); |
---|
669 | %GeometryCalib.dpx_dpy=[1 1]; |
---|
670 | GeometryCalib.Cx_Cy=cc'; |
---|
671 | %GeometryCalib.sx=fc(1)/fc(2); |
---|
672 | GeometryCalib.kc=kc(1); |
---|
673 | %GeometryCalib.kappa1=-kc(1)/fc(2)^2; |
---|
674 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
675 | GeometryCalib.Tx_Ty_Tz=Tc_1'; |
---|
676 | GeometryCalib.R=Rc_1; |
---|
677 | GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate |
---|
678 | GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate |
---|
679 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate |
---|
680 | GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees |
---|
681 | GeometryCalib.ErrorRMS=[]; |
---|
682 | GeometryCalib.ErrorMax=[]; |
---|
683 | |
---|
684 | |
---|
685 | %------------------------------------------------------------------------ |
---|
686 | function GeometryCalib=calib_3D_extrinsic(Coord,handles) |
---|
687 | %------------------------------------------------------------------ |
---|
688 | path_uvmat=which('geometry_calib');% check the path detected for source file uvmat |
---|
689 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
690 | x_1=double(Coord(:,4:5)');%image coordiantes |
---|
691 | X_1=double(Coord(:,1:3)');% phys coordinates |
---|
692 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
---|
693 | hhuvmat=guidata(huvmat); |
---|
694 | ny=str2double(get(hhuvmat.npy,'String')); |
---|
695 | x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates |
---|
696 | n_ima=1; |
---|
697 | GeometryCalib.CalibrationType='3D_extrinsic'; |
---|
698 | GeometryCalib.fx_fy(1)=str2num(get(handles.fx,'String')); |
---|
699 | GeometryCalib.fx_fy(2)=str2num(get(handles.fy,'String')); |
---|
700 | GeometryCalib.Cx_Cy(1)=str2num(get(handles.Cx,'String')); |
---|
701 | GeometryCalib.Cx_Cy(2)=str2num(get(handles.Cy,'String')); |
---|
702 | GeometryCalib.kc=str2num(get(handles.kc,'String')); |
---|
703 | fct_path=fullfile(path_UVMAT,'toolbox_calib'); |
---|
704 | addpath(fct_path) |
---|
705 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%reverse Cx_Cy(2) for calibration (inversion of px ordinate) |
---|
706 | % [omc1,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,... |
---|
707 | % [Calib.f Calib.f*Calib.sx]',... |
---|
708 | % [Calib.Cx Calib.Cy]',... |
---|
709 | % [-Calib.kappa1*Calib.f^2 0 0 0 0]); |
---|
710 | [omc,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,... |
---|
711 | (GeometryCalib.fx_fy)',GeometryCalib.Cx_Cy',[GeometryCalib.kc 0 0 0 0]); |
---|
712 | rmpath(fct_path); |
---|
713 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
714 | GeometryCalib.Tx_Ty_Tz=Tc1'; |
---|
715 | %inversion of z axis |
---|
716 | GeometryCalib.R=Rc1; |
---|
717 | GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate |
---|
718 | GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate |
---|
719 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate |
---|
720 | GeometryCalib.omc=(180/pi)*omc'; |
---|
721 | %GeometryCalib.R(3,1:3)=-GeometryCalib.R(3,1:3);%inversion for z upward |
---|
722 | |
---|
723 | |
---|
724 | |
---|
725 | %------------------------------------------------------------------------ |
---|
726 | %function GeometryCalib=calib_tsai_heikkila(Coord) |
---|
727 | % TEST: NOT IMPLEMENTED |
---|
728 | %------------------------------------------------------------------ |
---|
729 | % path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
730 | % path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
731 | % path_calib=fullfile(path_UVMAT,'toolbox_calib_heikkila'); |
---|
732 | % addpath(path_calib) |
---|
733 | % npoints=size(Coord,1); |
---|
734 | % Coord(:,1:3)=10*Coord(:,1:3); |
---|
735 | % Coord=[Coord zeros(npoints,2) -ones(npoints,1)]; |
---|
736 | % [par,pos,iter,res,er,C]=cacal('dalsa',Coord); |
---|
737 | % GeometryCalib.CalibrationType='tsai'; |
---|
738 | % GeometryCalib.focal=par(2); |
---|
739 | |
---|
740 | |
---|
741 | %-------------------------------------------------------------------------- |
---|
742 | function GeometryCalib=calib_tsai(Coord,handles)% OBSOLETE: old version using gauthier's bianry ccal_fo |
---|
743 | % NOT USED |
---|
744 | %------------------------------------------------------------------------ |
---|
745 | %TSAI |
---|
746 | path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
747 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
748 | xmlfile=fullfile(path_UVMAT,'PARAM.xml');%name of the file containing names of binary executables |
---|
749 | if exist(xmlfile,'file') |
---|
750 | t=xmltree(xmlfile);% read the (xml) file containing names of binary executables |
---|
751 | sparam=convert(t);% convert to matlab structure |
---|
752 | end |
---|
753 | if ~isfield(sparam,'GeometryCalibBin') |
---|
754 | msgbox_uvmat('ERROR',['calibration program <GeometryCalibBin> undefined in parameter file ' xmlfile]) |
---|
755 | return |
---|
756 | end |
---|
757 | Tsai_exe=sparam.GeometryCalibBin; |
---|
758 | if ~exist(Tsai_exe,'file')%the binary is defined in /bin, default setting |
---|
759 | Tsai_exe=fullfile(path_UVMAT,Tsai_exe); |
---|
760 | end |
---|
761 | if ~exist(Tsai_exe,'file') |
---|
762 | msgbox_uvmat('ERROR',['calibration program ' sparam.GeometryCalibBin ' defined in PARAM.xml does not exist']) |
---|
763 | return |
---|
764 | end |
---|
765 | |
---|
766 | textcoord=num2str(Coord,4); |
---|
767 | dlmwrite('t.txt',textcoord,''); |
---|
768 | % ['!' Tsai_exe ' -fx 0 -fy t.txt'] |
---|
769 | eval(['!' Tsai_exe ' -f t.txt > tsaicalib.log']); |
---|
770 | if ~exist('calib.dat','file') |
---|
771 | msgbox_uvmat('ERROR','no output from calibration program Tsai_exe: possibly too few points') |
---|
772 | end |
---|
773 | calibdat=dlmread('calib.dat'); |
---|
774 | delete('calib.dat') |
---|
775 | %delete('t.txt') |
---|
776 | GeometryCalib.CalibrationType='tsai'; |
---|
777 | GeometryCalib.focal=calibdat(10); |
---|
778 | GeometryCalib.dpx_dpy=[calibdat(5) calibdat(6)]; |
---|
779 | GeometryCalib.Cx_Cy=[calibdat(7) calibdat(8)]; |
---|
780 | GeometryCalib.sx=calibdat(9); |
---|
781 | GeometryCalib.kappa1=calibdat(11); |
---|
782 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
783 | GeometryCalib.Tx_Ty_Tz=[calibdat(12) calibdat(13) calibdat(14)]; |
---|
784 | Rx_Ry_Rz=calibdat(15:17); |
---|
785 | sa = sin(Rx_Ry_Rz(1)) ; |
---|
786 | ca=cos(Rx_Ry_Rz(1)); |
---|
787 | sb=sin(Rx_Ry_Rz(2)); |
---|
788 | cb =cos(Rx_Ry_Rz(2)); |
---|
789 | sg =sin(Rx_Ry_Rz(3)); |
---|
790 | cg =cos(Rx_Ry_Rz(3)); |
---|
791 | r1 = cb * cg; |
---|
792 | r2 = cg * sa * sb - ca * sg; |
---|
793 | r3 = sa * sg + ca * cg * sb; |
---|
794 | r4 = cb * sg; |
---|
795 | r5 = sa * sb * sg + ca * cg; |
---|
796 | r6 = ca * sb * sg - cg * sa; |
---|
797 | r7 = -sb; |
---|
798 | r8 = cb * sa; |
---|
799 | r9 = ca * cb; |
---|
800 | %EN DEDUIRE MATRICE R ?? |
---|
801 | GeometryCalib.R=[r1,r2,r3;r4,r5,r6;r7,r8,r9]; |
---|
802 | |
---|
803 | %------------------------------------------------------------------------ |
---|
804 | % --- determine the rms of calibration error |
---|
805 | function ErrorRms=error_calib(calib_param,Calib,Coord) |
---|
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 | function XImage_Callback(hObject, eventdata, handles) |
---|
834 | %------------------------------------------------------------------------ |
---|
835 | update_list(hObject, eventdata,handles) |
---|
836 | |
---|
837 | %------------------------------------------------------------------------ |
---|
838 | function YImage_Callback(hObject, eventdata, handles) |
---|
839 | %------------------------------------------------------------------------ |
---|
840 | update_list(hObject, eventdata,handles) |
---|
841 | |
---|
842 | %------------------------------------------------------------------------ |
---|
843 | % --- Executes on button press in STORE. |
---|
844 | function STORE_Callback(hObject, eventdata, handles) |
---|
845 | Coord_cell=get(handles.ListCoord,'String'); |
---|
846 | Object=read_geometry_calib(Coord_cell); |
---|
847 | unitlist=get(handles.CoordUnit,'String'); |
---|
848 | unit=unitlist{get(handles.CoordUnit,'value')}; |
---|
849 | GeometryCalib.CoordUnit=unit; |
---|
850 | GeometryCalib.SourceCalib.PointCoord=Object.Coord; |
---|
851 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
852 | hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat |
---|
853 | % RootPath=''; |
---|
854 | % RootFile=''; |
---|
855 | if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile) |
---|
856 | testhandle=1; |
---|
857 | RootPath=get(hhuvmat.RootPath,'String'); |
---|
858 | RootFile=get(hhuvmat.RootFile,'String'); |
---|
859 | filebase=fullfile(RootPath,RootFile); |
---|
860 | while exist([filebase '.xml'],'file') |
---|
861 | filebase=[filebase '~']; |
---|
862 | end |
---|
863 | outputfile=[filebase '.xml']; |
---|
864 | errormsg=update_imadoc(GeometryCalib,outputfile); |
---|
865 | if ~strcmp(errormsg,'') |
---|
866 | msgbox_uvmat('ERROR',errormsg); |
---|
867 | end |
---|
868 | listfile=get(handles.coord_files,'string'); |
---|
869 | if isequal(listfile,{''}) |
---|
870 | listfile={outputfile}; |
---|
871 | else |
---|
872 | listfile=[listfile;{outputfile}];%update the list of coord files |
---|
873 | end |
---|
874 | set(handles.coord_files,'string',listfile); |
---|
875 | end |
---|
876 | set(handles.ListCoord,'Value',1)% refresh the display of coordinates |
---|
877 | set(handles.ListCoord,'String',{'......'}) |
---|
878 | |
---|
879 | % -------------------------------------------------------------------- |
---|
880 | % --- Executes on button press in CLEAR_PTS: clear the list of calibration points |
---|
881 | function CLEAR_PTS_Callback(hObject, eventdata, handles) |
---|
882 | % -------------------------------------------------------------------- |
---|
883 | set(handles.ListCoord,'Value',1)% refresh the display of coordinates |
---|
884 | set(handles.ListCoord,'String',{'......'}) |
---|
885 | MenuPlot_Callback(hObject, eventdata, handles) |
---|
886 | |
---|
887 | %------------------------------------------------------------------------ |
---|
888 | % --- Executes on button press in CLEAR. |
---|
889 | function CLEAR_Callback(hObject, eventdata, handles) |
---|
890 | %------------------------------------------------------------------------ |
---|
891 | set(handles.coord_files,'Value',1) |
---|
892 | set(handles.coord_files,'String',{''}) |
---|
893 | |
---|
894 | %------------------------------------------------------------------------ |
---|
895 | function XObject_Callback(hObject, eventdata, handles) |
---|
896 | %------------------------------------------------------------------------ |
---|
897 | update_list(hObject, eventdata,handles) |
---|
898 | |
---|
899 | %------------------------------------------------------------------------ |
---|
900 | function YObject_Callback(hObject, eventdata, handles) |
---|
901 | %------------------------------------------------------------------------ |
---|
902 | update_list(hObject, eventdata,handles) |
---|
903 | |
---|
904 | %------------------------------------------------------------------------ |
---|
905 | function ZObject_Callback(hObject, eventdata, handles) |
---|
906 | %------------------------------------------------------------------------ |
---|
907 | update_list(hObject, eventdata,handles) |
---|
908 | |
---|
909 | %------------------------------------------------------------------------ |
---|
910 | function update_list(hObject, eventdata, handles) |
---|
911 | %------------------------------------------------------------------------ |
---|
912 | newval(4)=str2double(get(handles.XImage,'String')); |
---|
913 | newval(5)=str2double(get(handles.YImage,'String')); |
---|
914 | newval(1)=str2double(get(handles.XObject,'String')); |
---|
915 | newval(2)=str2double(get(handles.YObject,'String')); |
---|
916 | newval(3)=str2double(get(handles.ZObject,'String')); |
---|
917 | if isnan(newval(3)) |
---|
918 | newval(3)=0;%put z to 0 by default |
---|
919 | end |
---|
920 | Coord=get(handles.ListCoord,'String'); |
---|
921 | Coord(end)=[]; %remove last string '.....' |
---|
922 | val=get(handles.ListCoord,'Value'); |
---|
923 | data=read_geometry_calib(Coord); |
---|
924 | data.Coord(val,:)=newval; |
---|
925 | for i=1:size(data.Coord,1) |
---|
926 | for j=1:5 |
---|
927 | Coord_cell{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits |
---|
928 | end |
---|
929 | end |
---|
930 | |
---|
931 | Tabchar=cell2tab(Coord_cell,' | '); |
---|
932 | Tabchar=[Tabchar ;{'......'}]; |
---|
933 | set(handles.ListCoord,'String',Tabchar) |
---|
934 | |
---|
935 | %update the plot |
---|
936 | ListCoord_Callback(hObject, eventdata, handles) |
---|
937 | MenuPlot_Callback(hObject, eventdata, handles) |
---|
938 | |
---|
939 | %------------------------------------------------------------------------ |
---|
940 | % --- Executes on selection change in ListCoord. |
---|
941 | function ListCoord_Callback(hObject, eventdata, handles) |
---|
942 | %------------------------------------------------------------------------ |
---|
943 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle |
---|
944 | hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat |
---|
945 | hhh=findobj(hplot,'Tag','calib_marker'); |
---|
946 | Coord_cell=get(handles.ListCoord,'String'); |
---|
947 | val=get(handles.ListCoord,'Value'); |
---|
948 | if numel(val)>1 |
---|
949 | return %no action if several lines have been selected |
---|
950 | end |
---|
951 | coord_str=Coord_cell{val}; |
---|
952 | k=findstr(' | ',coord_str); |
---|
953 | if isempty(k)%last line '.....' selected |
---|
954 | if ~isempty(hhh) |
---|
955 | delete(hhh)%delete the circle marker |
---|
956 | end |
---|
957 | return |
---|
958 | end |
---|
959 | %fill the edit boxex |
---|
960 | set(handles.XObject,'String',coord_str(1:k(1)-1)) |
---|
961 | set(handles.YObject,'String',coord_str(k(1)+3:k(2)-1)) |
---|
962 | set(handles.ZObject,'String',coord_str(k(2)+3:k(3)-1)) |
---|
963 | set(handles.XImage,'String',coord_str(k(3)+3:k(4)-1)) |
---|
964 | set(handles.YImage,'String',coord_str(k(4)+3:end)) |
---|
965 | h_menu_coord=findobj(huvmat,'Tag','transform_fct'); |
---|
966 | menu=get(h_menu_coord,'String'); |
---|
967 | choice=get(h_menu_coord,'Value'); |
---|
968 | if iscell(menu) |
---|
969 | option=menu{choice}; |
---|
970 | else |
---|
971 | option='px'; %default |
---|
972 | end |
---|
973 | if isequal(option,'phys') |
---|
974 | XCoord=str2double(coord_str(1:k(1)-1)); |
---|
975 | YCoord=str2double(coord_str(k(1)+3:k(2)-1)); |
---|
976 | elseif isequal(option,'px')|| isequal(option,'') |
---|
977 | XCoord=str2double(coord_str(k(3)+3:k(4)-1)); |
---|
978 | YCoord=str2double(coord_str(k(4)+3:end)); |
---|
979 | else |
---|
980 | msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ') |
---|
981 | end |
---|
982 | if isempty(XCoord)||isempty(YCoord) |
---|
983 | if ~isempty(hhh) |
---|
984 | delete(hhh)%delete the circle marker |
---|
985 | end |
---|
986 | return |
---|
987 | end |
---|
988 | xlim=get(hplot,'XLim'); |
---|
989 | ylim=get(hplot,'YLim'); |
---|
990 | ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/20;%defines the size of the circle marker |
---|
991 | if isempty(hhh) |
---|
992 | set(0,'CurrentFig',huvmat) |
---|
993 | set(huvmat,'CurrentAxes',hplot) |
---|
994 | rectangle('Curvature',[1 1],... |
---|
995 | 'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range],'EdgeColor','m',... |
---|
996 | 'LineStyle','-','Tag','calib_marker'); |
---|
997 | else |
---|
998 | set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range]) |
---|
999 | end |
---|
1000 | |
---|
1001 | %------------------------------------------------------------------------ |
---|
1002 | % --- Executes on selection change in edit_append. |
---|
1003 | function edit_append_Callback(hObject, eventdata, handles) |
---|
1004 | %------------------------------------------------------------------------ |
---|
1005 | choice=get(handles.edit_append,'Value'); |
---|
1006 | if choice |
---|
1007 | set(handles.edit_append,'BackgroundColor',[1 1 0]) |
---|
1008 | huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
1009 | if ishandle(huvmat) |
---|
1010 | hhuvmat=guidata(huvmat); |
---|
1011 | set(hhuvmat.edit_object,'Value',0) |
---|
1012 | set(hhuvmat.edit_object,'BackgroundColor',[0.7 0.7 0.7]) |
---|
1013 | end |
---|
1014 | else |
---|
1015 | set(handles.edit_append,'BackgroundColor',[0.7 0.7 0.7]) |
---|
1016 | end |
---|
1017 | |
---|
1018 | function NEW_Callback(hObject, eventdata, handles) |
---|
1019 | %A METTRE SOUS UN BOUTON |
---|
1020 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
1021 | hchild=get(huvmat,'children'); |
---|
1022 | hcoord=findobj(hchild,'Tag','menu_coord'); |
---|
1023 | coordtype=get(hcoord,'Value'); |
---|
1024 | haxes=findobj(hchild,'Tag','axes3'); |
---|
1025 | AxeData=get(haxes,'UserData'); |
---|
1026 | if ~isequal(hcoord,2) |
---|
1027 | set(hcoord,'Value',2) |
---|
1028 | huvmat=uvmat(AxeData); |
---|
1029 | 'relancer uvmat'; |
---|
1030 | end |
---|
1031 | if ~isfield(AxeData,'ZoomAxes') |
---|
1032 | msgbox_uvmat('ERROR','first draw a window around a grid marker') |
---|
1033 | return |
---|
1034 | end |
---|
1035 | XLim=get(AxeData.ZoomAxes,'XLim'); |
---|
1036 | YLim=get(AxeData.ZoomAxes,'YLim'); |
---|
1037 | np=size(AxeData.A); |
---|
1038 | ind_sub_x=round(XLim); |
---|
1039 | ind_sub_y=np(1)-round(YLim); |
---|
1040 | Mfiltre=AxeData.A(ind_sub_y(2):ind_sub_y(1) ,ind_sub_x,:); |
---|
1041 | Mfiltre_norm=double(Mfiltre); |
---|
1042 | Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm)); |
---|
1043 | Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm))); |
---|
1044 | Atype=class(AxeData.A); |
---|
1045 | Data.NbDim=2; |
---|
1046 | Data.A=filter2(Mfiltre_norm,double(AxeData.A)); |
---|
1047 | Data.A=feval(Atype,Data.A); |
---|
1048 | Data.AName='image'; |
---|
1049 | Data.AX=AxeData.AX; |
---|
1050 | Data.AY=AxeData.AY; |
---|
1051 | Data.CoordType='px'; |
---|
1052 | plot_field(Data) |
---|
1053 | |
---|
1054 | %------------------------------------------------------------------------ |
---|
1055 | function MenuPlot_Callback(hObject, eventdata, handles) |
---|
1056 | %------------------------------------------------------------------------ |
---|
1057 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle |
---|
1058 | %UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface |
---|
1059 | hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat |
---|
1060 | %hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat |
---|
1061 | h_menu_coord=findobj(huvmat,'Tag','transform_fct'); |
---|
1062 | menu=get(h_menu_coord,'String'); |
---|
1063 | choice=get(h_menu_coord,'Value'); |
---|
1064 | if iscell(menu) |
---|
1065 | option=menu{choice}; |
---|
1066 | else |
---|
1067 | option='px'; %default |
---|
1068 | end |
---|
1069 | Coord_cell=get(handles.ListCoord,'String'); |
---|
1070 | ObjectData=read_geometry_calib(Coord_cell); |
---|
1071 | %ObjectData=read_geometry_calib(handles);%read the interface input parameters defining the object |
---|
1072 | if ~isempty(ObjectData.Coord) |
---|
1073 | if isequal(option,'phys') |
---|
1074 | ObjectData.Coord=ObjectData.Coord(:,1:3); |
---|
1075 | elseif isequal(option,'px')||isequal(option,'') |
---|
1076 | ObjectData.Coord=ObjectData.Coord(:,4:5); |
---|
1077 | else |
---|
1078 | msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be '''', px or phys ') |
---|
1079 | end |
---|
1080 | end |
---|
1081 | %axes(hhuvmat.axes3) |
---|
1082 | set(0,'CurrentFigure',huvmat) |
---|
1083 | set(huvmat,'CurrentAxes',hhuvmat.axes3) |
---|
1084 | hh=findobj('Tag','calib_points'); |
---|
1085 | if ~isempty(ObjectData.Coord) && isempty(hh) |
---|
1086 | hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); |
---|
1087 | elseif isempty(ObjectData.Coord)%empty list of points, suppress the plot |
---|
1088 | delete(hh) |
---|
1089 | else |
---|
1090 | set(hh,'XData',ObjectData.Coord(:,1)) |
---|
1091 | set(hh,'YData',ObjectData.Coord(:,2)) |
---|
1092 | end |
---|
1093 | pause(.1) |
---|
1094 | figure(handles.geometry_calib) |
---|
1095 | |
---|
1096 | % -------------------------------------------------------------------- |
---|
1097 | function MenuHelp_Callback(hObject, eventdata, handles) |
---|
1098 | path_to_uvmat=which('uvmat');% check the path of uvmat |
---|
1099 | pathelp=fileparts(path_to_uvmat); |
---|
1100 | helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html'); |
---|
1101 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package') |
---|
1102 | else |
---|
1103 | addpath (fullfile(pathelp,'uvmat_doc')) |
---|
1104 | web([helpfile '#geometry_calib']) |
---|
1105 | end |
---|
1106 | |
---|
1107 | %------------------------------------------------------------------------ |
---|
1108 | function MenuCreateGrid_Callback(hObject, eventdata, handles) |
---|
1109 | %------------------------------------------------------------------------ |
---|
1110 | %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib |
---|
1111 | CalibData=get(handles.geometry_calib,'UserData'); |
---|
1112 | Tinput=[];%default |
---|
1113 | if isfield(CalibData,'grid') |
---|
1114 | Tinput=CalibData.grid; |
---|
1115 | end |
---|
1116 | [T,CalibData.grid]=create_grid(Tinput);%display the GUI create_grid |
---|
1117 | set(handles.geometry_calib,'UserData',CalibData) |
---|
1118 | |
---|
1119 | %grid in phys space |
---|
1120 | Coord=get(handles.ListCoord,'String'); |
---|
1121 | val=get(handles.ListCoord,'Value'); |
---|
1122 | data=read_geometry_calib(Coord); |
---|
1123 | %nbpoints=size(data.Coord,1); %nbre of calibration points |
---|
1124 | data.Coord(val:val+size(T,1)-1,1:3)=T(end:-1:1,:);%update the existing list of phys coordinates from the GUI create_grid |
---|
1125 | % for i=1:nbpoints |
---|
1126 | % for j=1:5 |
---|
1127 | % Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits |
---|
1128 | % end |
---|
1129 | % end |
---|
1130 | %update the phys coordinates starting from the selected point (down in the |
---|
1131 | Coord(end,:)=[]; %remove last string '.....' |
---|
1132 | for i=1:size(data.Coord,1) |
---|
1133 | for j=1:5 |
---|
1134 | Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits |
---|
1135 | end |
---|
1136 | end |
---|
1137 | |
---|
1138 | %size(data.Coord,1) |
---|
1139 | Tabchar=cell2tab(Coord,' | '); |
---|
1140 | Tabchar=[Tabchar ;{'......'}]; |
---|
1141 | set(handles.ListCoord,'String',Tabchar) |
---|
1142 | |
---|
1143 | % ----------------------------------------------------------------------- |
---|
1144 | % --- automatic grid dectection from local maxima of the images |
---|
1145 | function MenuDetectGrid_Callback(hObject, eventdata, handles) |
---|
1146 | %------------------------------------------------------------------------ |
---|
1147 | %% read the four last point coordinates in pixels |
---|
1148 | Coord_cell=get(handles.ListCoord,'String');%read list of coordinates on geometry_calib |
---|
1149 | data=read_geometry_calib(Coord_cell); |
---|
1150 | nbpoints=size(data.Coord,1); %nbre of calibration points |
---|
1151 | if nbpoints~=4 |
---|
1152 | 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') |
---|
1153 | return |
---|
1154 | end |
---|
1155 | corners_X=(data.Coord(end:-1:end-3,4)); %pixel absissa of the four corners |
---|
1156 | corners_Y=(data.Coord(end:-1:end-3,5)); |
---|
1157 | |
---|
1158 | %reorder the last two points (the two first in the list) if needed |
---|
1159 | angles=angle((corners_X-corners_X(1))+1i*(corners_Y-corners_Y(1))); |
---|
1160 | if abs(angles(4)-angles(2))>abs(angles(3)-angles(2)) |
---|
1161 | X_end=corners_X(4); |
---|
1162 | Y_end=corners_Y(4); |
---|
1163 | corners_X(4)=corners_X(3); |
---|
1164 | corners_Y(4)=corners_Y(3); |
---|
1165 | corners_X(3)=X_end; |
---|
1166 | corners_Y(3)=Y_end; |
---|
1167 | end |
---|
1168 | |
---|
1169 | %% initiate the grid |
---|
1170 | CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib |
---|
1171 | grid_input=[];%default |
---|
1172 | if isfield(CalibData,'grid') |
---|
1173 | grid_input=CalibData.grid;%retrieve the previously used grid |
---|
1174 | end |
---|
1175 | [T,CalibData.grid,white_test]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T |
---|
1176 | set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use |
---|
1177 | |
---|
1178 | |
---|
1179 | |
---|
1180 | %% read the current image, displayed in the GUI uvmat |
---|
1181 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
1182 | UvData=get(huvmat,'UserData'); |
---|
1183 | A=UvData.Field.A; |
---|
1184 | npxy=size(A); |
---|
1185 | X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm) |
---|
1186 | Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm) |
---|
1187 | |
---|
1188 | %calculate transform matrices for plane projection |
---|
1189 | % reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren |
---|
1190 | B = [ X Y ones(size(X)) zeros(4,3) -X.*corners_X -Y.*corners_X ... |
---|
1191 | zeros(4,3) X Y ones(size(X)) -X.*corners_Y -Y.*corners_Y ]; |
---|
1192 | B = reshape (B', 8 , 8 )'; |
---|
1193 | D = [ corners_X , corners_Y ]; |
---|
1194 | D = reshape (D', 8 , 1 ); |
---|
1195 | l = (B' * B)\B' * D; |
---|
1196 | Amat = reshape([l(1:6)' 0 0 1 ],3,3)'; |
---|
1197 | C = [l(7:8)' 1]; |
---|
1198 | |
---|
1199 | % transform grid image into 'phys' coordinates |
---|
1200 | GeometryCalib.fx_fy=[1 1]; |
---|
1201 | GeometryCalib.Tx_Ty_Tz=[Amat(1,3) Amat(2,3) 1]; |
---|
1202 | GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0]; |
---|
1203 | GeometryCalib.CoordUnit='cm'; |
---|
1204 | path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
1205 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
1206 | addpath(fullfile(path_UVMAT,'transform_field')) |
---|
1207 | Data.ListVarName={'AY','AX','A'}; |
---|
1208 | Data.VarDimName={'AY','AX',{'AY','AX'}}; |
---|
1209 | if ndims(A)==3 |
---|
1210 | A=mean(A,3); |
---|
1211 | end |
---|
1212 | Data.A=A-min(min(A)); |
---|
1213 | Data.AY=[npxy(1)-0.5 0.5]; |
---|
1214 | Data.AX=[0.5 npxy(2)]; |
---|
1215 | Data.CoordUnit='pixel'; |
---|
1216 | Calib.GeometryCalib=GeometryCalib; |
---|
1217 | DataOut=phys(Data,Calib); |
---|
1218 | rmpath(fullfile(path_UVMAT,'transform_field')) |
---|
1219 | Amod=DataOut.A; |
---|
1220 | Rangx=DataOut.AX; |
---|
1221 | Rangy=DataOut.AY; |
---|
1222 | if white_test |
---|
1223 | Amod=double(Amod);%case of white grid markers: will look for image maxima |
---|
1224 | else |
---|
1225 | Amod=-double(Amod);%case of black grid markers: will look for image minima |
---|
1226 | end |
---|
1227 | % figure(12) %display corrected image |
---|
1228 | % Amax=max(max(Amod)); |
---|
1229 | % image(Rangx,Rangy,uint8(255*Amod/Amax)) |
---|
1230 | |
---|
1231 | %% detection of local image extrema in each direction |
---|
1232 | Dx=(Rangx(2)-Rangx(1))/(npxy(2)-1); %x mesh in real space |
---|
1233 | Dy=(Rangy(2)-Rangy(1))/(npxy(1)-1); %y mesh in real space |
---|
1234 | 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 |
---|
1235 | 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 |
---|
1236 | nbpoints=size(T,1); |
---|
1237 | for ipoint=1:nbpoints |
---|
1238 | i0=1+round((T(ipoint,1)-Rangx(1))/Dx);%round(Xpx(ipoint)); |
---|
1239 | j0=1+round((T(ipoint,2)-Rangy(1))/Dy);%round(Xpx(ipoint)); |
---|
1240 | j0min=max(j0-ind_range_y,1); |
---|
1241 | j0max=min(j0+ind_range_y,size(Amod,1)); |
---|
1242 | i0min=max(i0-ind_range_x,1); |
---|
1243 | i0max=min(i0+ind_range_x,size(Amod,2)); |
---|
1244 | Asub=Amod(j0min:j0max,i0min:i0max); |
---|
1245 | x_profile=sum(Asub,1); |
---|
1246 | y_profile=sum(Asub,2); |
---|
1247 | [Amax,ind_x_max]=max(x_profile); |
---|
1248 | [Amax,ind_y_max]=max(y_profile); |
---|
1249 | %sub-pixel improvement using moments |
---|
1250 | x_shift=0; |
---|
1251 | y_shift=0; |
---|
1252 | if ind_x_max+2<=numel(x_profile) && ind_x_max-2>=1 |
---|
1253 | Atop=x_profile(ind_x_max-2:ind_x_max+2); |
---|
1254 | x_shift=sum(Atop.*[-2 -1 0 1 2])/sum(Atop); |
---|
1255 | end |
---|
1256 | if ind_y_max+2<=numel(y_profile) && ind_y_max-2>=1 |
---|
1257 | Atop=y_profile(ind_y_max-2:ind_y_max+2); |
---|
1258 | y_shift=sum(Atop.*[-2 -1 0 1 2]')/sum(Atop); |
---|
1259 | end |
---|
1260 | Delta(ipoint,1)=(x_shift+ind_x_max+i0min-i0-1)*Dx;%shift from the initial guess |
---|
1261 | Delta(ipoint,2)=(y_shift+ind_y_max+j0min-j0-1)*Dy; |
---|
1262 | end |
---|
1263 | Tmod=T(:,(1:2))+Delta; |
---|
1264 | [Xpx,Ypx]=px_XYZ(GeometryCalib,Tmod(:,1),Tmod(:,2)); |
---|
1265 | for ipoint=1:nbpoints |
---|
1266 | Coord{ipoint,1}=num2str(T(ipoint,1),4);%display coordiantes with 4 digits |
---|
1267 | Coord{ipoint,2}=num2str(T(ipoint,2),4);%display coordiantes with 4 digits |
---|
1268 | Coord{ipoint,3}=num2str(T(ipoint,3),4);%display coordiantes with 4 digits; |
---|
1269 | Coord{ipoint,4}=num2str(Xpx(ipoint),4);%display coordiantes with 4 digits |
---|
1270 | Coord{ipoint,5}=num2str(Ypx(ipoint),4);%display coordiantes with 4 digits |
---|
1271 | end |
---|
1272 | Tabchar=cell2tab(Coord(end:-1:1,:),' | '); |
---|
1273 | Tabchar=[Tabchar ;{'......'}]; |
---|
1274 | set(handles.ListCoord,'Value',1) |
---|
1275 | set(handles.ListCoord,'String',Tabchar) |
---|
1276 | MenuPlot_Callback(hObject, eventdata, handles) |
---|
1277 | |
---|
1278 | %----------------------------------------------------------------------- |
---|
1279 | function MenuTranslatePoints_Callback(hObject, eventdata, handles) |
---|
1280 | %----------------------------------------------------------------------- |
---|
1281 | %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib |
---|
1282 | CalibData=get(handles.geometry_calib,'UserData'); |
---|
1283 | Tinput=[];%default |
---|
1284 | if isfield(CalibData,'translate') |
---|
1285 | Tinput=CalibData.translate; |
---|
1286 | end |
---|
1287 | T=translate_points(Tinput);%display translate_points GUI and get shift parameters |
---|
1288 | CalibData.translate=T; |
---|
1289 | set(handles.geometry_calib,'UserData',CalibData) |
---|
1290 | %translation |
---|
1291 | Coord_cell=get(handles.ListCoord,'String'); |
---|
1292 | data=read_geometry_calib(Coord_cell); |
---|
1293 | data.Coord(:,1)=T(1)+data.Coord(:,1); |
---|
1294 | data.Coord(:,2)=T(2)+data.Coord(:,2); |
---|
1295 | data.Coord(:,3)=T(3)+data.Coord(:,3); |
---|
1296 | data.Coord(:,[4 5])=data.Coord(:,[4 5]); |
---|
1297 | for i=1:size(data.Coord,1) |
---|
1298 | for j=1:5 |
---|
1299 | Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z |
---|
1300 | end |
---|
1301 | end |
---|
1302 | Tabchar=cell2tab(Coord,' | '); |
---|
1303 | Tabchar=[Tabchar; {'.....'}]; |
---|
1304 | %set(handles.ListCoord,'Value',1) |
---|
1305 | set(handles.ListCoord,'String',Tabchar) |
---|
1306 | |
---|
1307 | |
---|
1308 | % -------------------------------------------------------------------- |
---|
1309 | function MenuRotatePoints_Callback(hObject, eventdata, handles) |
---|
1310 | %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib |
---|
1311 | CalibData=get(handles.geometry_calib,'UserData'); |
---|
1312 | Tinput=[];%default |
---|
1313 | if isfield(CalibData,'rotate') |
---|
1314 | Tinput=CalibData.rotate; |
---|
1315 | end |
---|
1316 | T=rotate_points(Tinput);%display translate_points GUI and get shift parameters |
---|
1317 | CalibData.rotate=T; |
---|
1318 | set(handles.geometry_calib,'UserData',CalibData) |
---|
1319 | %----------------------------------------------------- |
---|
1320 | %rotation |
---|
1321 | Phi=T(1); |
---|
1322 | O_x=0;%default |
---|
1323 | O_y=0;%default |
---|
1324 | if numel(T)>=2 |
---|
1325 | O_x=T(2);%default |
---|
1326 | end |
---|
1327 | if numel(T)>=3 |
---|
1328 | O_y=T(3);%default |
---|
1329 | end |
---|
1330 | Coord_cell=get(handles.ListCoord,'String'); |
---|
1331 | data=read_geometry_calib(Coord_cell); |
---|
1332 | r1=cos(pi*Phi/180); |
---|
1333 | r2=-sin(pi*Phi/180); |
---|
1334 | r3=sin(pi*Phi/180); |
---|
1335 | r4=cos(pi*Phi/180); |
---|
1336 | x=data.Coord(:,1)-O_x; |
---|
1337 | y=data.Coord(:,2)-O_y; |
---|
1338 | data.Coord(:,1)=r1*x+r2*y; |
---|
1339 | data.Coord(:,2)=r3*x+r4*y; |
---|
1340 | % data.Coord(:,[4 5])=data.Coord(:,[4 5]); |
---|
1341 | for i=1:size(data.Coord,1) |
---|
1342 | for j=1:5 |
---|
1343 | Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z |
---|
1344 | end |
---|
1345 | end |
---|
1346 | Tabchar=cell2tab(Coord,' | '); |
---|
1347 | Tabchar=[Tabchar;{'......'}]; |
---|
1348 | set(handles.ListCoord,'Value',1) |
---|
1349 | set(handles.ListCoord,'String',Tabchar) |
---|
1350 | |
---|
1351 | |
---|
1352 | % %------------------------------------------------------------------------ |
---|
1353 | % % --- Executes on button press in rotation. |
---|
1354 | % function rotation_Callback(hObject, eventdata, handles) |
---|
1355 | % %------------------------------------------------------------------------ |
---|
1356 | % angle_rot=(pi/180)*str2num(get(handles.Phi,'String')); |
---|
1357 | % Coord_cell=get(handles.ListCoord,'String'); |
---|
1358 | % data=read_geometry_calib(Coord_cell); |
---|
1359 | % data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2); |
---|
1360 | % data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2); |
---|
1361 | % set(handles.XObject,'String',num2str(data.Coord(:,1),4)); |
---|
1362 | % set(handles.YObject,'String',num2str(data.Coord(:,2),4)); |
---|
1363 | |
---|
1364 | |
---|
1365 | %------------------------------------------------------------------------ |
---|
1366 | % image transform from px to phys |
---|
1367 | %INPUT: |
---|
1368 | %Zindex: index of plane |
---|
1369 | % function [A_out,Rangx,Rangy]=phys_Ima(A,Calib,ZIndex) |
---|
1370 | % %------------------------------------------------------------------------ |
---|
1371 | % xcorner=[]; |
---|
1372 | % ycorner=[]; |
---|
1373 | % npx=[]; |
---|
1374 | % npy=[]; |
---|
1375 | % siz=size(A) |
---|
1376 | % npx=[npx siz(2)]; |
---|
1377 | % npy=[npy siz(1)] |
---|
1378 | % xima=[0.5 siz(2)-0.5 0.5 siz(2)-0.5];%image coordinates of corners |
---|
1379 | % yima=[0.5 0.5 siz(1)-0.5 siz(1)-0.5]; |
---|
1380 | % [xcorner,ycorner]=phys_XYZ(Calib,xima,yima,ZIndex);%corresponding physical coordinates |
---|
1381 | % Rangx(1)=min(xcorner); |
---|
1382 | % Rangx(2)=max(xcorner); |
---|
1383 | % Rangy(2)=min(ycorner); |
---|
1384 | % Rangy(1)=max(ycorner); |
---|
1385 | % test_multi=(max(npx)~=min(npx)) | (max(npy)~=min(npy)); |
---|
1386 | % npx=max(npx); |
---|
1387 | % npy=max(npy); |
---|
1388 | % x=linspace(Rangx(1),Rangx(2),npx); |
---|
1389 | % y=linspace(Rangy(1),Rangy(2),npy); |
---|
1390 | % [X,Y]=meshgrid(x,y);%grid in physical coordiantes |
---|
1391 | % vec_B=[]; |
---|
1392 | % |
---|
1393 | % zphys=0; %default |
---|
1394 | % if isfield(Calib,'SliceCoord') %.Z= index of plane |
---|
1395 | % SliceCoord=Calib.SliceCoord(ZIndex,:); |
---|
1396 | % zphys=SliceCoord(3); %to generalize for non-parallel planes |
---|
1397 | % end |
---|
1398 | % [XIMA,YIMA]=px_XYZ(Calib,X,Y,zphys);%corresponding image indices for each point in the real space grid |
---|
1399 | % XIMA=reshape(round(XIMA),1,npx*npy);%indices reorganized in 'line' |
---|
1400 | % YIMA=reshape(round(YIMA),1,npx*npy); |
---|
1401 | % flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image |
---|
1402 | % testuint8=isa(A,'uint8'); |
---|
1403 | % testuint16=isa(A,'uint16'); |
---|
1404 | % if numel(siz)==2 %(B/W images) |
---|
1405 | % vec_A=reshape(A,1,npx*npy);%put the original image in line |
---|
1406 | % ind_in=find(flagin); |
---|
1407 | % ind_out=find(~flagin); |
---|
1408 | % ICOMB=((XIMA-1)*npy+(npy+1-YIMA)); |
---|
1409 | % ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A |
---|
1410 | % vec_B(ind_in)=vec_A(ICOMB); |
---|
1411 | % vec_B(ind_out)=zeros(size(ind_out)); |
---|
1412 | % A_out=reshape(vec_B,npy,npx);%new image in real coordinates |
---|
1413 | % elseif numel(siz)==3 |
---|
1414 | % for icolor=1:siz(3) |
---|
1415 | % vec_A=reshape(A{icell}(:,:,icolor),1,npx*npy);%put the original image in line |
---|
1416 | % ind_in=find(flagin); |
---|
1417 | % ind_out=find(~flagin); |
---|
1418 | % ICOMB=((XIMA-1)*npy+(npy+1-YIMA)); |
---|
1419 | % ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A |
---|
1420 | % vec_B(ind_in)=vec_A(ICOMB); |
---|
1421 | % vec_B(ind_out)=zeros(size(ind_out)); |
---|
1422 | % A_out(:,:,icolor)=reshape(vec_B,npy,npx);%new image in real coordinates |
---|
1423 | % end |
---|
1424 | % end |
---|
1425 | % if testuint8 |
---|
1426 | % A_out=uint8(A_out); |
---|
1427 | % end |
---|
1428 | % if testuint16 |
---|
1429 | % A_out=uint16(A_out); |
---|
1430 | % end |
---|
1431 | |
---|
1432 | %------------------------------------------------------------------------ |
---|
1433 | % pointwise transform from px to phys |
---|
1434 | %INPUT: |
---|
1435 | %Z: index of plane |
---|
1436 | % function [Xphys,Yphys,Zphys]=phys_XYZ(Calib,X,Y,Z) |
---|
1437 | % %------------------------------------------------------------------------ |
---|
1438 | % if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'SliceCoord')&length(Calib.SliceCoord)>=Z |
---|
1439 | % Zindex=Z; |
---|
1440 | % Zphys=Calib.SliceCoord(Zindex,3);%GENERALISER AUX CAS AVEC ANGLE |
---|
1441 | % else |
---|
1442 | % Zphys=0; |
---|
1443 | % end |
---|
1444 | % if ~exist('X','var')||~exist('Y','var') |
---|
1445 | % Xphys=[]; |
---|
1446 | % Yphys=[];%default |
---|
1447 | % return |
---|
1448 | % end |
---|
1449 | % Xphys=X;%default |
---|
1450 | % Yphys=Y; |
---|
1451 | % %image transform |
---|
1452 | % if isfield(Calib,'R') |
---|
1453 | % R=(Calib.R)'; |
---|
1454 | % Dx=R(5)*R(7)-R(4)*R(8); |
---|
1455 | % Dy=R(1)*R(8)-R(2)*R(7); |
---|
1456 | % D0=Calib.f*(R(2)*R(4)-R(1)*R(5)); |
---|
1457 | % Z11=R(6)*R(8)-R(5)*R(9); |
---|
1458 | % Z12=R(2)*R(9)-R(3)*R(8); |
---|
1459 | % Z21=R(4)*R(9)-R(6)*R(7); |
---|
1460 | % Z22=R(3)*R(7)-R(1)*R(9); |
---|
1461 | % Zx0=R(3)*R(5)-R(2)*R(6); |
---|
1462 | % Zy0=R(1)*R(6)-R(3)*R(4); |
---|
1463 | % A11=R(8)*Calib.Ty-R(5)*Calib.Tz+Z11*Zphys; |
---|
1464 | % A12=R(2)*Calib.Tz-R(8)*Calib.Tx+Z12*Zphys; |
---|
1465 | % A21=-R(7)*Calib.Ty+R(4)*Calib.Tz+Z21*Zphys; |
---|
1466 | % A22=-R(1)*Calib.Tz+R(7)*Calib.Tx+Z11*Zphys; |
---|
1467 | % X0=Calib.f*(R(5)*Calib.Tx-R(2)*Calib.Ty+Zx0*Zphys); |
---|
1468 | % Y0=Calib.f*(-R(4)*Calib.Tx+R(1)*Calib.Ty+Zy0*Zphys); |
---|
1469 | % %px to camera: |
---|
1470 | % Xd=(Calib.dpx/Calib.sx)*(X-Calib.Cx); % sensor coordinates |
---|
1471 | % Yd=Calib.dpy*(Y-Calib.Cy); |
---|
1472 | % dist_fact=1+Calib.kappa1*(Xd.*Xd+Yd.*Yd); %distortion factor |
---|
1473 | % Xu=dist_fact.*Xd;%undistorted sensor coordinates |
---|
1474 | % Yu=dist_fact.*Yd; |
---|
1475 | % denom=Dx*Xu+Dy*Yu+D0; |
---|
1476 | % % denom2=denom.*denom; |
---|
1477 | % Xphys=(A11.*Xu+A12.*Yu+X0)./denom;%world coordinates |
---|
1478 | % Yphys=(A21.*Xu+A22.*Yu+Y0)./denom; |
---|
1479 | % end |
---|
1480 | |
---|
1481 | |
---|
1482 | % -------------------------------------------------------------------- |
---|
1483 | function MenuImportPoints_Callback(hObject, eventdata, handles) |
---|
1484 | fileinput=browse_xml(hObject, eventdata, handles); |
---|
1485 | if isempty(fileinput) |
---|
1486 | return |
---|
1487 | end |
---|
1488 | [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); |
---|
1489 | GeometryCalib=s.GeometryCalib; |
---|
1490 | %GeometryCalib=load_calib(hObject, eventdata, handles) |
---|
1491 | calib=reshape(GeometryCalib.PointCoord,[],1); |
---|
1492 | for ilist=1:numel(calib) |
---|
1493 | CoordCell{ilist}=num2str(calib(ilist)); |
---|
1494 | end |
---|
1495 | CoordCell=reshape(CoordCell,[],5); |
---|
1496 | Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display |
---|
1497 | Tabchar=[Tabchar;{'......'}]; |
---|
1498 | set(handles.ListCoord,'Value',1) |
---|
1499 | set(handles.ListCoord,'String',Tabchar) |
---|
1500 | MenuPlot_Callback(handles.geometry_calib, [], handles) |
---|
1501 | |
---|
1502 | % ----------------------------------------------------------------------- |
---|
1503 | function MenuImportIntrinsic_Callback(hObject, eventdata, handles) |
---|
1504 | %------------------------------------------------------------------------ |
---|
1505 | fileinput=browse_xml(hObject, eventdata, handles); |
---|
1506 | if isempty(fileinput) |
---|
1507 | return |
---|
1508 | end |
---|
1509 | [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); |
---|
1510 | GeometryCalib=s.GeometryCalib; |
---|
1511 | display_intrinsic(GeometryCalib,handles) |
---|
1512 | |
---|
1513 | % ----------------------------------------------------------------------- |
---|
1514 | function MenuImportAll_Callback(hObject, eventdata, handles) |
---|
1515 | %------------------------------------------------------------------------ |
---|
1516 | fileinput=browse_xml(hObject, eventdata, handles); |
---|
1517 | if ~isempty(fileinput) |
---|
1518 | loadfile(handles,fileinput) |
---|
1519 | end |
---|
1520 | |
---|
1521 | % ----------------------------------------------------------------------- |
---|
1522 | % --- Executes on menubar option Import/Grid file: introduce previous grid files |
---|
1523 | function MenuGridFile_Callback(hObject, eventdata, handles) |
---|
1524 | % ----------------------------------------------------------------------- |
---|
1525 | inputfile=browse_xml(hObject, eventdata, handles); |
---|
1526 | listfile=get(handles.coord_files,'string'); |
---|
1527 | if isequal(listfile,{''}) |
---|
1528 | listfile={inputfile}; |
---|
1529 | else |
---|
1530 | listfile=[listfile;{inputfile}];%update the list of coord files |
---|
1531 | end |
---|
1532 | set(handles.coord_files,'string',listfile); |
---|
1533 | |
---|
1534 | %------------------------------------------------------------------------ |
---|
1535 | % --- 'key_press_fcn:' function activated when a key is pressed on the keyboard |
---|
1536 | function key_press_fcn(hObject,eventdata,handles) |
---|
1537 | %------------------------------------------------------------------------ |
---|
1538 | xx=double(get(handles.geometry_calib,'CurrentCharacter')); %get the keyboard character |
---|
1539 | if ismember(xx,[8 127])%backspace or delete |
---|
1540 | Coord_cell=get(handles.ListCoord,'String'); |
---|
1541 | val=get(handles.ListCoord,'Value'); |
---|
1542 | if max(val)<numel(Coord_cell) % the last element '...' has not been selected |
---|
1543 | Coord_cell(val)=[];%remove the selected line |
---|
1544 | set(handles.ListCoord,'Value',min(val)) |
---|
1545 | set(handles.ListCoord,'String',Coord_cell) |
---|
1546 | ListCoord_Callback(hObject, eventdata, handles) |
---|
1547 | MenuPlot_Callback(hObject,eventdata,handles) |
---|
1548 | end |
---|
1549 | end |
---|
1550 | |
---|
1551 | %------------------------------------------------------------------------ |
---|
1552 | function fileinput=browse_xml(hObject, eventdata, handles) |
---|
1553 | %------------------------------------------------------------------------ |
---|
1554 | fileinput=[];%default |
---|
1555 | oldfile=''; %default |
---|
1556 | UserData=get(handles.geometry_calib,'UserData'); |
---|
1557 | if isfield(UserData,'XmlInputFile') |
---|
1558 | oldfile=UserData.XmlInputFile; |
---|
1559 | end |
---|
1560 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
1561 | {'*.xml;*.mat', ' (*.xml,*.mat)'; |
---|
1562 | '*.xml', '.xml files '; ... |
---|
1563 | '*.mat', '.mat matlab files '}, ... |
---|
1564 | 'Pick a file',oldfile); |
---|
1565 | fileinput=[PathName FileName];%complete file name |
---|
1566 | testblank=findstr(fileinput,' ');%look for blanks |
---|
1567 | if ~isempty(testblank) |
---|
1568 | msgbox_uvmat('ERROR','forbidden input file name or path: no blank character allowed') |
---|
1569 | return |
---|
1570 | end |
---|
1571 | sizf=size(fileinput); |
---|
1572 | if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end |
---|
1573 | UserData.XmlInputFile=fileinput; |
---|
1574 | set(handles.geometry_calib,'UserData',UserData)%record current file foer further use of browser |
---|
1575 | |
---|
1576 | % ----------------------------------------------------------------------- |
---|
1577 | function Heading=loadfile(handles,fileinput) |
---|
1578 | %------------------------------------------------------------------------ |
---|
1579 | Heading=[];%default |
---|
1580 | [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); |
---|
1581 | if ~isempty(errormsg) |
---|
1582 | msgbox_uvmat('ERROR',['Error for reading ' fileinput ': ' errormsg]) |
---|
1583 | return |
---|
1584 | end |
---|
1585 | if ~isempty(s.Heading) |
---|
1586 | Heading=s.Heading; |
---|
1587 | end |
---|
1588 | |
---|
1589 | GeometryCalib=s.GeometryCalib; |
---|
1590 | fx=1;fy=1;Cx=0;Cy=0;kc=0; %default |
---|
1591 | % Tabchar={}; |
---|
1592 | CoordCell={}; |
---|
1593 | % kc=0;%default |
---|
1594 | % f1=1000; |
---|
1595 | % f2=1000; |
---|
1596 | % hhuvmat=guidata(findobj(allchild(0),'Name','uvmat')); |
---|
1597 | % Cx=str2num(get(hhuvmat.npx,'String'))/2; |
---|
1598 | % Cy=str2num(get(hhuvmat.npy,'String'))/2; |
---|
1599 | Tabchar={};%default |
---|
1600 | val_cal=1;%default |
---|
1601 | if ~isempty(GeometryCalib) |
---|
1602 | % choose the calibration option |
---|
1603 | if isfield(GeometryCalib,'CalibrationType') |
---|
1604 | calib_list=get(handles.calib_type,'String'); |
---|
1605 | for ilist=1:numel(calib_list) |
---|
1606 | if strcmp(calib_list{ilist},GeometryCalib.CalibrationType) |
---|
1607 | val_cal=ilist; |
---|
1608 | break |
---|
1609 | end |
---|
1610 | end |
---|
1611 | end |
---|
1612 | display_intrinsic(GeometryCalib,handles)%intrinsic param |
---|
1613 | %extrinsic param |
---|
1614 | if isfield(GeometryCalib,'Tx_Ty_Tz') |
---|
1615 | Tx_Ty_Tz=GeometryCalib.Tx_Ty_Tz; |
---|
1616 | set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) |
---|
1617 | set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) |
---|
1618 | set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) |
---|
1619 | end |
---|
1620 | if isfield(GeometryCalib,'omc') |
---|
1621 | set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) |
---|
1622 | set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) |
---|
1623 | set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) |
---|
1624 | end |
---|
1625 | calib=reshape(GeometryCalib.PointCoord,[],1); |
---|
1626 | for ilist=1:numel(calib) |
---|
1627 | CoordCell{ilist}=num2str(calib(ilist)); |
---|
1628 | end |
---|
1629 | CoordCell=reshape(CoordCell,[],5); |
---|
1630 | Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display |
---|
1631 | MenuPlot_Callback(handles.geometry_calib, [], handles) |
---|
1632 | end |
---|
1633 | set(handles.calib_type,'Value',val_cal) |
---|
1634 | Tabchar=[Tabchar;{'......'}]; |
---|
1635 | set(handles.ListCoord,'Value',1) |
---|
1636 | set(handles.ListCoord,'String',Tabchar) |
---|
1637 | |
---|
1638 | if isempty(CoordCell)% allow mouse action by default in the absence of input points |
---|
1639 | set(handles.edit_append,'Value',1) |
---|
1640 | set(handles.edit_append,'BackgroundColor',[1 1 0]) |
---|
1641 | else % does not allow mouse action by default in the presence of input points |
---|
1642 | set(handles.edit_append,'Value',0) |
---|
1643 | set(handles.edit_append,'BackgroundColor',[0.7 0.7 0.7]) |
---|
1644 | end |
---|
1645 | |
---|
1646 | %------------------------------------------------------------------------ |
---|
1647 | %---display calibration intrinsic parameters |
---|
1648 | function display_intrinsic(GeometryCalib,handles) |
---|
1649 | %------------------------------------------------------------------------ |
---|
1650 | fx=[]; |
---|
1651 | fy=[]; |
---|
1652 | if isfield(GeometryCalib,'fx_fy') |
---|
1653 | fx=GeometryCalib.fx_fy(1); |
---|
1654 | fy=GeometryCalib.fx_fy(2); |
---|
1655 | end |
---|
1656 | Cx_Cy=[0 0];%default |
---|
1657 | if isfield(GeometryCalib,'Cx_Cy') |
---|
1658 | Cx_Cy=GeometryCalib.Cx_Cy; |
---|
1659 | end |
---|
1660 | kc=0; |
---|
1661 | if isfield(GeometryCalib,'kc') |
---|
1662 | kc=GeometryCalib.kc; %* GeometryCalib.focal*GeometryCalib.focal; |
---|
1663 | end |
---|
1664 | set(handles.fx,'String',num2str(fx,5)) |
---|
1665 | set(handles.fy,'String',num2str(fy,5)) |
---|
1666 | set(handles.Cx,'String',num2str(Cx_Cy(1),'%1.1f')) |
---|
1667 | set(handles.Cy,'String',num2str(Cx_Cy(2),'%1.1f')) |
---|
1668 | set(handles.kc,'String',num2str(kc,'%1.4f')) |
---|
1669 | |
---|
1670 | |
---|