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