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