1 | %'probe_calib': performs geometric calibration from a set of reference points |
---|
2 | function varargout = probe_calib(varargin) |
---|
3 | % PROBE_CALIB M-file for probe_calib.fig |
---|
4 | % PROBE_CALIB, by itself, creates a MenuCoord PROBE_CALIB or raises the existing |
---|
5 | % singleton*. |
---|
6 | % |
---|
7 | % H = PROBE_CALIB returns the handle to a MenuCoord PROBE_CALIB or the handle to |
---|
8 | % the existing singleton*. |
---|
9 | % |
---|
10 | % PROBE_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local |
---|
11 | % function named CALLBACK in PROBE_CALIB.M with the given input arguments. |
---|
12 | % |
---|
13 | % PROBE_CALIB('Property','Value',...) creates a MenuCoord PROBE_CALIB or raises the |
---|
14 | % existing singleton*. Starting from the left, property value pairs are |
---|
15 | % applied to the GUI before probe_calib_OpeningFunction gets called. An |
---|
16 | % unrecognized property name or invalid value makes property application |
---|
17 | % stop. All inputs are passed to probe_calib_OpeningFcn via varargin. |
---|
18 | % |
---|
19 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one |
---|
20 | % instance to run (singleton)". |
---|
21 | % |
---|
22 | % See also: GUIDE, GUIDATA, GUIHANDLES |
---|
23 | |
---|
24 | % Edit the above text to modify the response to help probe_calib |
---|
25 | |
---|
26 | % Last Modified by GUIDE v2.5 04-Feb-2008 15:46:42 |
---|
27 | |
---|
28 | % Begin initialization code - DO NOT EDIT |
---|
29 | gui_Singleton = 1; |
---|
30 | gui_State = struct('gui_Name', mfilename, ... |
---|
31 | 'gui_Singleton', gui_Singleton, ... |
---|
32 | 'gui_OpeningFcn', @probe_calib_OpeningFcn, ... |
---|
33 | 'gui_OutputFcn', @probe_calib_OutputFcn, ... |
---|
34 | 'gui_LayoutFcn', [] , ... |
---|
35 | 'gui_Callback', []); |
---|
36 | if nargin & isstr(varargin{1}) |
---|
37 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
38 | end |
---|
39 | |
---|
40 | if nargout |
---|
41 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
42 | else |
---|
43 | gui_mainfcn(gui_State, varargin{:}); |
---|
44 | end |
---|
45 | % End initialization code - DO NOT EDIT |
---|
46 | |
---|
47 | |
---|
48 | % --- Executes just before probe_calib is made visible. |
---|
49 | %INPUT: |
---|
50 | %handles: handles of the probe_calib interface elements |
---|
51 | % PlotHandles: set of handles of the elements contolling the plotting |
---|
52 | % parameters on the uvmat interface (obtained by 'get_plot_handle.m') |
---|
53 | function probe_calib_OpeningFcn(hObject, eventdata, handles, data,pos,inputfile) |
---|
54 | |
---|
55 | % Choose default command line output for probe_calib |
---|
56 | handles.output = hObject; |
---|
57 | |
---|
58 | % Update handles structure |
---|
59 | guidata(hObject, handles); |
---|
60 | |
---|
61 | %default |
---|
62 | % set(hObject,'Unit','Normalized')% set the unit normalized to the screen size |
---|
63 | % set(hObject,'Position',[0.7 0.1 0.25 0.5])%set the position of the probe_calib interface |
---|
64 | set(hObject,'DeleteFcn',@closefcn) |
---|
65 | |
---|
66 | %set the position of the interface |
---|
67 | if exist('pos','var')& length(pos)>2 |
---|
68 | pos_gui=get(hObject,'Position'); |
---|
69 | pos_gui(1)=pos(1); |
---|
70 | pos_gui(2)=pos(2); |
---|
71 | set(hObject,'Position',pos_gui); |
---|
72 | end |
---|
73 | % set(handles.XImage,'String','') |
---|
74 | % set(handles.YImage,'String','') |
---|
75 | % set(handles.XObject,'String','') |
---|
76 | % set(handles.YObject,'String','') |
---|
77 | % set(handles.ZObject,'String','') |
---|
78 | inputxml=''; |
---|
79 | if exist('inputfile','var')& ~isempty(inputfile) |
---|
80 | [Path,Name,ext]=fileparts(inputfile); |
---|
81 | if isequal(ext,'.png') |
---|
82 | set(hObject,'UserData',inputfile) |
---|
83 | [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile); |
---|
84 | inputxml=[fullfile(Pathsub,RootFile) '.xml']; |
---|
85 | end |
---|
86 | end |
---|
87 | if exist(inputxml,'file') |
---|
88 | loadfile(handles,inputxml) |
---|
89 | end |
---|
90 | set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function |
---|
91 | |
---|
92 | |
---|
93 | % --- Outputs from this function are returned to the command line. |
---|
94 | function varargout = probe_calib_OutputFcn(hObject, eventdata, handles) |
---|
95 | % varargout cell array for returning output args (see VARARGOUT); |
---|
96 | % hObject handle to figure |
---|
97 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
98 | % handles structure with handles and user data (see GUIDATA) |
---|
99 | |
---|
100 | % Get default command line output from handles structure |
---|
101 | varargout{1} = handles.output; |
---|
102 | varargout{2}=handles; |
---|
103 | |
---|
104 | %------------ |
---|
105 | function Phi_Callback(hObject, eventdata, handles) |
---|
106 | |
---|
107 | |
---|
108 | %----------------------------------------------------- |
---|
109 | % --- Executes on button press in import. |
---|
110 | function import_Callback(hObject, eventdata, handles) |
---|
111 | %get the object file |
---|
112 | huvmat=findobj('Tag','uvmat'); |
---|
113 | UvData=get(huvmat,'UserData'); |
---|
114 | hchild=get(huvmat,'Children'); |
---|
115 | hrootpath=findobj(hchild,'Tag','RootPath'); |
---|
116 | oldfile=get(hrootpath,'String'); |
---|
117 | if isempty(oldfile) |
---|
118 | oldfile=''; |
---|
119 | end |
---|
120 | %[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile) |
---|
121 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
122 | {'*.xml;*.mat', ' (*.xml,*.mat)'; |
---|
123 | '*.xml', '.xml files '; ... |
---|
124 | '*.mat', '.mat matlab files '}, ... |
---|
125 | 'Pick a file',oldfile); |
---|
126 | fileinput=[PathName FileName];%complete file name |
---|
127 | testblank=findstr(fileinput,' ');%look for blanks |
---|
128 | if ~isempty(testblank) |
---|
129 | warndlg_uvmat('forbidden input file name or path: no blank character allowed','ERROR') |
---|
130 | return |
---|
131 | end |
---|
132 | sizf=size(fileinput); |
---|
133 | if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end |
---|
134 | loadfile(handles,fileinput) |
---|
135 | |
---|
136 | %-------------------------------------------------- |
---|
137 | %read input xml file and update the edit boxes |
---|
138 | function loadfile(handles,fileinput) |
---|
139 | |
---|
140 | %read the input xml file |
---|
141 | t=xmltree(fileinput); |
---|
142 | s=convert(t);%convert to matlab structure |
---|
143 | |
---|
144 | %read data currently displayed on the interface |
---|
145 | PointCoord=[]; |
---|
146 | data=read_probe_calib(handles); |
---|
147 | Coord=[]; %default |
---|
148 | if isfield(data,'Coord') |
---|
149 | Coord=data.Coord; |
---|
150 | end |
---|
151 | TabChar_0=get(handles.ListCoord,'String'); |
---|
152 | nbcoord_0=size(TabChar_0,1); |
---|
153 | if isequal(get(handles.edit_append,'Value'),1) %edit mode |
---|
154 | val=get(handles.ListCoord,'Value')-1; |
---|
155 | else |
---|
156 | val=length(TabChar_0); |
---|
157 | end |
---|
158 | nbcoord=0; |
---|
159 | |
---|
160 | %case of calibration (ImaDoc) input file |
---|
161 | if isfield(s,'GeometryCalib') |
---|
162 | Calib=s.GeometryCalib; |
---|
163 | if isfield(Calib,'SourceCalib') |
---|
164 | if isfield(Calib.SourceCalib,'PointCoord') |
---|
165 | PointCoord=Calib.SourceCalib.PointCoord; |
---|
166 | end |
---|
167 | if isfield(Calib.SourceCalib,'ImageCalib') |
---|
168 | hcalib=get(handles.import,'parent'); |
---|
169 | set(hcalib,'UserData',Calib.SourceCalib.ImageCalib);%store the source image name in the interface 'UserData' |
---|
170 | end |
---|
171 | end |
---|
172 | nbcoord=length(PointCoord); |
---|
173 | if ~isfield(Calib,'ErrorRms')&~isfield(Calib,'ErrorMax') %old convention of Gauthier (cord in mm) |
---|
174 | for i=1:length(PointCoord) |
---|
175 | line=str2num(PointCoord{i}); |
---|
176 | Coord(i+val,4:5)=line(4:5);%px x |
---|
177 | Coord(i+val,1:3)=line(1:3)/10;%phys x |
---|
178 | end |
---|
179 | else |
---|
180 | for i=1:length(PointCoord) |
---|
181 | line=str2num(PointCoord{i}); |
---|
182 | Coord(i,4:5)=line(4:5);%px x |
---|
183 | Coord(i,1:3)=line(1:3);%phys x |
---|
184 | end |
---|
185 | end |
---|
186 | end |
---|
187 | |
---|
188 | %case of xml files of points |
---|
189 | if isfield(s,'Coord') |
---|
190 | PointCoord=s.Coord; |
---|
191 | nbcoord=length(PointCoord); |
---|
192 | %case of image coordinates |
---|
193 | if isfield(s,'CoordType')& isequal(s.CoordType,'px') |
---|
194 | for i=1:nbcoord |
---|
195 | line=str2num(PointCoord{i}); |
---|
196 | Coord(i+val,4:5)=line(1:2); |
---|
197 | end |
---|
198 | %case of physical coordinates |
---|
199 | else |
---|
200 | for i=1:nbcoord |
---|
201 | line=str2num(PointCoord{i}) |
---|
202 | Coord(i+val,1:3)=line(1:3); |
---|
203 | nbcolumn=size(Coord,2); |
---|
204 | if nbcolumn<5 |
---|
205 | Coord(i+val,nbcolumn+1:5)=zeros(1,5-nbcolumn); |
---|
206 | end |
---|
207 | end |
---|
208 | end |
---|
209 | end |
---|
210 | CoordCell={}; |
---|
211 | for iline=1:size(Coord,1) |
---|
212 | for j=1:5 |
---|
213 | CoordCell{iline,j}=num2str(Coord(iline,j)); |
---|
214 | end |
---|
215 | end |
---|
216 | |
---|
217 | Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display |
---|
218 | set(handles.ListCoord,'Value',1) |
---|
219 | set(handles.ListCoord,'String',Tabchar) |
---|
220 | |
---|
221 | |
---|
222 | %---------------------------------------------------- |
---|
223 | % executed when closing: set the parent interface button to value 0 |
---|
224 | function closefcn(gcbo,eventdata) |
---|
225 | SetData=get(gcbf,'UserData'); |
---|
226 | if isfield(SetData,'ParentButton') & ishandle(SetData.ParentButton) |
---|
227 | set(SetData.ParentButton, 'Value',0) |
---|
228 | end |
---|
229 | |
---|
230 | %----------------------------------------------------------------------- |
---|
231 | % --- Executes on button press in edit: PLOT the defined object and its projected field |
---|
232 | function edit_Callback(hObject, eventdata, handles) |
---|
233 | %hsetobject=get(hObject,'parent'); |
---|
234 | %SetData=get(hsetobject,'UserData');%get the hidden interface data |
---|
235 | %IndexObj=SetData.IndexObj;%index of the current projection object in the list of projection objects (UvData.ProjObject) |
---|
236 | huvmat=findobj(allchild(0),'name','uvmat');%find the current uvmat interface handle |
---|
237 | UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface |
---|
238 | hplot=findobj(huvmat,'Tag','axes3'); |
---|
239 | h_menu_coord=findobj(huvmat,'Tag','menu_coord'); |
---|
240 | menu=get(h_menu_coord,'String'); |
---|
241 | choice=get(h_menu_coord,'Value'); |
---|
242 | if iscell(menu) |
---|
243 | option=menu{choice}; |
---|
244 | else |
---|
245 | option='px'; %default |
---|
246 | end |
---|
247 | %get axis |
---|
248 | %get CoordType |
---|
249 | ObjectData=read_probe_calib(handles);%read the interface input parameters defining the object |
---|
250 | if isequal(option,'phys') |
---|
251 | ObjectData.Coord=ObjectData.Coord(:,[1:3]); |
---|
252 | elseif isequal(option,'px') |
---|
253 | ObjectData.Coord=ObjectData.Coord(:,[4:5]); |
---|
254 | else |
---|
255 | errordlg('the choice in coord_coord must be px or phys ') |
---|
256 | end |
---|
257 | % [UvData,IndexObj]=update_obj(UvData,IndexObj,ObjectData,SetData.PlotHandles); |
---|
258 | % SetData.IndexObj=IndexObj; |
---|
259 | % set(gcbf,'UserData',SetData)%update object index in the probe_calib interface |
---|
260 | % set(huvmat,'UserData',UvData)%update the data in the uvmat interface |
---|
261 | ObjectData.ProjMode='none'; |
---|
262 | plot_object(ObjectData,[],hplot,'b'); |
---|
263 | |
---|
264 | |
---|
265 | % --- Executes on button press in MenuCoord. |
---|
266 | function MenuCoord_Callback(hObject, eventdata, handles) |
---|
267 | |
---|
268 | |
---|
269 | % --- Executes on button press in delete. |
---|
270 | function delete_Callback(hObject, eventdata, handles) |
---|
271 | SetData=get(gcbf,'UserData');%get the interface data |
---|
272 | IndexObj=SetData.IndexObj; |
---|
273 | delete_object(IndexObj); |
---|
274 | |
---|
275 | % --- Executes on button press in calibrate_lin. |
---|
276 | function calib_offset_Callback(hObject, eventdata, handles) |
---|
277 | Object=read_probe_calib(handles); |
---|
278 | |
---|
279 | %make linear calibration |
---|
280 | % 'calibration_lin' provides a linear transform on coordinates, |
---|
281 | X=Object.Coord(:,1); |
---|
282 | Y=Object.Coord(:,2); |
---|
283 | x_ima=Object.Coord(:,4); |
---|
284 | y_ima=Object.Coord(:,5); |
---|
285 | [px,sx]=polyfit(X,x_ima,1); |
---|
286 | [py,sy]=polyfit(Y,y_ima,1); |
---|
287 | %err_X1=max(abs(x1-x_ima));%error |
---|
288 | %err_Y1=max(abs(y1-y_ima));%error |
---|
289 | T_x=px(2); |
---|
290 | T_y=py(2); |
---|
291 | GeometryCalib.focal=1; |
---|
292 | GeometryCalib.Tx_Ty_Tz=[T_x T_y 1]; |
---|
293 | GeometryCalib.R=[px(1),0,0;0,py(1),0;0,0,1]; |
---|
294 | %check error |
---|
295 | Calib.dpx=1; |
---|
296 | Calib.dpy=1; |
---|
297 | Calib.sx=1; |
---|
298 | Calib.Cx=0; |
---|
299 | Calib.Cy=0; |
---|
300 | Calib.Tz=1; |
---|
301 | Calib.kappa1=0; |
---|
302 | Calib.f=GeometryCalib.focal; |
---|
303 | Calib.Tx=T_x; |
---|
304 | Calib.Ty=T_y; |
---|
305 | Calib.R=GeometryCalib.R; |
---|
306 | [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0); |
---|
307 | GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); |
---|
308 | GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima)); |
---|
309 | GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); |
---|
310 | GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima)) |
---|
311 | %calibrate_lin calibration results and point coordinates |
---|
312 | huvmat=findobj('Tag','uvmat'); |
---|
313 | hchild=get(huvmat,'Children'); |
---|
314 | hrootpath=findobj(hchild,'Tag','RootPath'); |
---|
315 | hrootfile=findobj(hchild,'Tag','RootFile'); |
---|
316 | RootPath=''; |
---|
317 | RootFile=''; |
---|
318 | if ~isempty(hrootpath)& ~isempty(hrootfile) |
---|
319 | testhandle=1; |
---|
320 | RootPath=get(hrootpath,'String'); |
---|
321 | RootFile=get(hrootfile,'String'); |
---|
322 | filebase=fullfile(RootPath,RootFile); |
---|
323 | outputfile=[filebase '.xml'] |
---|
324 | else |
---|
325 | question={'save the calibration data and point coordinates in'}; |
---|
326 | def={fullfile(RootPath,['ObjectCalib.xml'])}; |
---|
327 | options.Resize='on'; |
---|
328 | answer=inputdlg(question,'save average in a new file',1,def,options); |
---|
329 | outputfile=answer{1}; |
---|
330 | end |
---|
331 | testappend=0; |
---|
332 | if exist(outputfile,'file');%=1 if the output file already exists, 0 else |
---|
333 | t=xmltree(outputfile); %read the file |
---|
334 | uid=find(t,'ImaDoc'); |
---|
335 | if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup) |
---|
336 | backupfile=outputfile; |
---|
337 | testexist=2; |
---|
338 | while testexist==2 |
---|
339 | backupfile=[backupfile '~']; |
---|
340 | testexist=exist(backupfile,'file'); |
---|
341 | end |
---|
342 | [success,message]=copyfile(outputfile,backupfile);%make backup |
---|
343 | if isequal(success,1) |
---|
344 | delete(outputfile) |
---|
345 | else |
---|
346 | return |
---|
347 | end |
---|
348 | else |
---|
349 | uid_calib=find(t,'ImaDoc/GeometryCalib'); |
---|
350 | if ~isempty(uid) %if GeometryCalib already exists, delete its content |
---|
351 | backupfile=outputfile; |
---|
352 | testexist=2; |
---|
353 | while testexist==2 |
---|
354 | backupfile=[backupfile '~']; |
---|
355 | testexist=exist(backupfile,'file'); |
---|
356 | end |
---|
357 | [success,message]=copyfile(outputfile,backupfile)%make backup |
---|
358 | if isequal(success,1) |
---|
359 | delete(outputfile) |
---|
360 | else |
---|
361 | return |
---|
362 | end |
---|
363 | uid_child=children(t,uid_calib); |
---|
364 | t=delete(t,uid_child); |
---|
365 | testappend=1; |
---|
366 | end |
---|
367 | end |
---|
368 | end |
---|
369 | if ~testappend |
---|
370 | t=xmltree; |
---|
371 | t=set(t,1,'name','ImaDoc'); |
---|
372 | [t,uid_calib]=add(t,1,'element','GeometryCalib'); |
---|
373 | % t=struct2xml(GeometryCalib,t,uid_calib); |
---|
374 | end |
---|
375 | Object.Coord(:,[1:3])=Object.Coord(:,[1:3])*10; %transform in |
---|
376 | GeometryCalib.SourceCalib.PointCoord=Object.Coord; |
---|
377 | t=struct2xml(GeometryCalib,t,uid_calib); |
---|
378 | save(t,outputfile) |
---|
379 | |
---|
380 | warndlg_uvmat([outputfile 'updated with linear calibration data'],'CONFIRMATION') |
---|
381 | |
---|
382 | %display image with new calibration in the currently opened uvmat interface |
---|
383 | Indices=get(findobj(hchild,'Tag','FileIndex'),'String'); |
---|
384 | Ext=get(findobj(hchild,'Tag','FileExt'),'String'); |
---|
385 | imagename=[fullfile(RootPath,RootFile) Indices Ext]; |
---|
386 | % input.menu_coord=1; |
---|
387 | huvmat=uvmat(imagename,1);%open uvmat, set phys coord (Value 1) |
---|
388 | |
---|
389 | |
---|
390 | |
---|
391 | % --- Executes on button press in calibrate_lin. |
---|
392 | function calib_lin_Callback(hObject, eventdata, handles) |
---|
393 | Object=read_probe_calib(handles); |
---|
394 | |
---|
395 | %make linear calibration |
---|
396 | % 'calibration_lin' provides a linear transform on coordinates, |
---|
397 | X=Object.Coord(:,1); |
---|
398 | Y=Object.Coord(:,2); |
---|
399 | x_ima=Object.Coord(:,4); |
---|
400 | y_ima=Object.Coord(:,5); |
---|
401 | XY_mat=[ones(size(X)) X Y]; |
---|
402 | a_X1=XY_mat\x_ima; %transformation matrix for X |
---|
403 | x1=XY_mat*a_X1;%reconstruction |
---|
404 | err_X1=max(abs(x1-x_ima));%error |
---|
405 | a_Y1=XY_mat\y_ima;%transformation matrix for X |
---|
406 | y1=XY_mat*a_Y1; |
---|
407 | err_Y1=max(abs(y1-y_ima));%error |
---|
408 | T_x=a_X1(1); |
---|
409 | T_y=a_Y1(1); |
---|
410 | GeometryCalib.focal=1; |
---|
411 | GeometryCalib.Tx_Ty_Tz=[T_x T_y 1]; |
---|
412 | GeometryCalib.R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1]; |
---|
413 | |
---|
414 | %check error |
---|
415 | GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima))); |
---|
416 | GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima)); |
---|
417 | GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima))); |
---|
418 | GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima)) |
---|
419 | |
---|
420 | %calibrate_lin calibration results and point coordinates |
---|
421 | huvmat=findobj('Tag','uvmat'); |
---|
422 | hchild=get(huvmat,'Children'); |
---|
423 | hrootpath=findobj(hchild,'Tag','RootPath'); |
---|
424 | hrootfile=findobj(hchild,'Tag','RootFile'); |
---|
425 | RootPath=''; |
---|
426 | RootFile=''; |
---|
427 | if ~isempty(hrootpath)& ~isempty(hrootfile) |
---|
428 | testhandle=1; |
---|
429 | RootPath=get(hrootpath,'String'); |
---|
430 | RootFile=get(hrootfile,'String'); |
---|
431 | filebase=fullfile(RootPath,RootFile); |
---|
432 | outputfile=[filebase '.xml']; |
---|
433 | else |
---|
434 | question={'save the calibration data and point coordinates in'}; |
---|
435 | def={fullfile(RootPath,['ObjectCalib.xml'])}; |
---|
436 | options.Resize='on'; |
---|
437 | answer=inputdlg(question,'save average in a new file',1,def,options); |
---|
438 | outputfile=answer{1}; |
---|
439 | end |
---|
440 | testappend=0; |
---|
441 | if exist(outputfile,'file');%=1 if the output file already exists, 0 else |
---|
442 | t=xmltree(outputfile); %read the file |
---|
443 | uid=find(t,'ImaDoc'); |
---|
444 | if ~isequal(uid,1)%if the xml file is not ImaDoc, delete it (after backup) |
---|
445 | backupfile=outputfile; |
---|
446 | testexist=2; |
---|
447 | while testexist==2 |
---|
448 | backupfile=[backupfile '~']; |
---|
449 | testexist=exist(backupfile,'file'); |
---|
450 | end |
---|
451 | [success,message]=copyfile(outputfile,backupfile)%make backup |
---|
452 | if isequal(success,1); |
---|
453 | delete(outputfile) |
---|
454 | else |
---|
455 | return |
---|
456 | end |
---|
457 | else |
---|
458 | uid_calib=find(t,'ImaDoc/GeometryCalib'); |
---|
459 | if ~isempty(uid) %if GeometryCalib already exists, delete its content |
---|
460 | backupfile=outputfile; |
---|
461 | testexist=2; |
---|
462 | while testexist==2 |
---|
463 | backupfile=[backupfile '~']; |
---|
464 | testexist=exist(backupfile,'file'); |
---|
465 | end |
---|
466 | [success,message]=copyfile(outputfile,backupfile)%make backup |
---|
467 | if isequal(success,1) |
---|
468 | delete(outputfile) |
---|
469 | else |
---|
470 | return |
---|
471 | end |
---|
472 | uid_child=children(t,uid_calib); |
---|
473 | t=delete(t,uid_child); |
---|
474 | testappend=1; |
---|
475 | end |
---|
476 | end |
---|
477 | end |
---|
478 | if ~testappend |
---|
479 | t=xmltree; |
---|
480 | t=set(t,1,'name','ImaDoc'); |
---|
481 | [t,uid_calib]=add(t,1,'element','GeometryCalib'); |
---|
482 | % t=struct2xml(GeometryCalib,t,uid_calib); |
---|
483 | end |
---|
484 | % Object.Coord(:,[1:3])=Object.Coord(:,[1:3]); %transform in |
---|
485 | GeometryCalib.SourceCalib.PointCoord=Object.Coord; |
---|
486 | t=struct2xml(GeometryCalib,t,uid_calib); |
---|
487 | save(t,outputfile) |
---|
488 | |
---|
489 | warndlg_uvmat([outputfile 'updated with linear calibration data'],'CONFIRMATION') |
---|
490 | |
---|
491 | %display image with new calibration in the currently opened uvmat interface |
---|
492 | Indices=get(findobj(hchild,'Tag','FileIndex'),'String'); |
---|
493 | Ext=get(findobj(hchild,'Tag','FileExt'),'String'); |
---|
494 | imagename=[fullfile(RootPath,RootFile) Indices Ext]; |
---|
495 | % input.menu_coord=1; |
---|
496 | if exist(imagename,'file') |
---|
497 | huvmat=uvmat(imagename,1);%open uvmat, set phys coord (Value 1) |
---|
498 | else |
---|
499 | huvmat=uvmat; |
---|
500 | end |
---|
501 | |
---|
502 | |
---|
503 | % --- Executes on button press in translation. |
---|
504 | function translation_Callback(hObject, eventdata, handles) |
---|
505 | |
---|
506 | |
---|
507 | function T_x_Callback(hObject, eventdata, handles) |
---|
508 | % hObject handle to T_x (see GCBO) |
---|
509 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
510 | % handles structure with handles and user data (see GUIDATA) |
---|
511 | |
---|
512 | % Hints: get(hObject,'String') returns contents of T_x as text |
---|
513 | % str2double(get(hObject,'String')) returns contents of T_x as a double |
---|
514 | |
---|
515 | |
---|
516 | |
---|
517 | |
---|
518 | |
---|
519 | function T_y_Callback(hObject, eventdata, handles) |
---|
520 | % hObject handle to T_y (see GCBO) |
---|
521 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
522 | % handles structure with handles and user data (see GUIDATA) |
---|
523 | |
---|
524 | % Hints: get(hObject,'String') returns contents of T_y as text |
---|
525 | % str2double(get(hObject,'String')) returns contents of T_y as a double |
---|
526 | |
---|
527 | |
---|
528 | function T_z_Callback(hObject, eventdata, handles) |
---|
529 | % hObject handle to T_z (see GCBO) |
---|
530 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
531 | % handles structure with handles and user data (see GUIDATA) |
---|
532 | |
---|
533 | % Hints: get(hObject,'String') returns contents of T_z as text |
---|
534 | % str2double(get(hObject,'String')) returns contents of T_z as a double |
---|
535 | |
---|
536 | |
---|
537 | % --- Executes on button press in rotation. |
---|
538 | function rotation_Callback(hObject, eventdata, handles) |
---|
539 | angle_rot=(pi/180)*str2num(get(handles.Phi,'String')) |
---|
540 | data=read_probe_calib(handles) |
---|
541 | data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2); |
---|
542 | data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2); |
---|
543 | set(handles.XObject,'String',num2str(data.Coord(:,1))); |
---|
544 | set(handles.YObject,'String',num2str(data.Coord(:,2))); |
---|
545 | |
---|
546 | |
---|
547 | function XImage_Callback(hObject, eventdata, handles) |
---|
548 | update_list(hObject, eventdata,handles) |
---|
549 | |
---|
550 | function YImage_Callback(hObject, eventdata, handles) |
---|
551 | update_list(hObject, eventdata,handles) |
---|
552 | |
---|
553 | function XObject_Callback(hObject, eventdata, handles) |
---|
554 | update_list(hObject, eventdata,handles) |
---|
555 | |
---|
556 | function YObject_Callback(hObject, eventdata, handles) |
---|
557 | update_list(hObject, eventdata,handles) |
---|
558 | |
---|
559 | function ZObject_Callback(hObject, eventdata, handles) |
---|
560 | update_list(hObject, eventdata,handles) |
---|
561 | |
---|
562 | function update_list(hObject, eventdata, handles) |
---|
563 | str4=get(handles.XImage,'String'); |
---|
564 | str5=get(handles.YImage,'String'); |
---|
565 | str1=get(handles.XObject,'String'); |
---|
566 | tt=double(str1); |
---|
567 | str2=get(handles.YObject,'String'); |
---|
568 | str3=get(handles.ZObject,'String'); |
---|
569 | if ~isempty(str1) & ~isequal(double(str1),32) & (isempty(str3)|isequal(double(str3),32)) |
---|
570 | str3='0';%put z to 0 by default |
---|
571 | end |
---|
572 | strline=[str1 ' | ' str2 ' | ' str3 ' | ' str4 ' | ' str5]; |
---|
573 | Coord=get(handles.ListCoord,'String'); |
---|
574 | testappend=get(handles.edit_append,'Value'); |
---|
575 | if isequal(testappend,1); %edit mode |
---|
576 | val=get(handles.ListCoord,'Value'); |
---|
577 | Coord{val}=strline; |
---|
578 | else |
---|
579 | val=length(get(handles.ListCoord,'String')); |
---|
580 | Coord{val+1}=strline; |
---|
581 | set(handles.ListCoord,'Value',val+1) |
---|
582 | % if val+1<=length(Coord) |
---|
583 | % set(handles.ListCoord,'Value',val+1) |
---|
584 | % ListCoord_Callback(hObject, eventdata, handles) |
---|
585 | end |
---|
586 | set(handles.ListCoord,'String',Coord) |
---|
587 | %set(handles.ListCoord,'Value',val+1) |
---|
588 | |
---|
589 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
590 | function data=read_probe_calib(handles) |
---|
591 | data_XIma=[]; |
---|
592 | data_YIma=[]; |
---|
593 | data_XObject=[]; |
---|
594 | data_YObject=[]; |
---|
595 | data_ZObject=[]; |
---|
596 | Coord=get(handles.ListCoord,'String'); |
---|
597 | % XImage=get(handles.XImage,'String'); |
---|
598 | % YImage=get(handles.YImage,'String'); |
---|
599 | % XObject=get(handles.XObject,'String'); |
---|
600 | % YObject=get(handles.YObject,'String'); |
---|
601 | % ZObject=get(handles.ZObject,'String'); |
---|
602 | % if ischar(Xcolumn) |
---|
603 | % Xcolumn={Xcolumn}; |
---|
604 | % end |
---|
605 | nb_defining_points=length(Coord); |
---|
606 | iline=0; |
---|
607 | for i=1:nb_defining_points |
---|
608 | coord_str=Coord{i};%character string of line number i |
---|
609 | k=findstr('|',coord_str);%find separators '|' |
---|
610 | data1=str2num(coord_str(1:k(1)-5)); |
---|
611 | data2=str2num(coord_str(k(1)+5:k(2)-5)); |
---|
612 | data3=str2num(coord_str(k(2)+5:k(3)-5)); |
---|
613 | data4=str2num(coord_str(k(3)+5:k(4)-5)); |
---|
614 | data5=str2num(coord_str(k(4)+5:end)); |
---|
615 | if ~isempty(data1)|~isempty(data2)|~isempty(data3)|~isempty(data4)|~isempty(data5) |
---|
616 | iline=iline+1; |
---|
617 | if ~isempty(data1) |
---|
618 | data.Coord(iline,1)=data1; |
---|
619 | end |
---|
620 | if ~isempty(data2) |
---|
621 | data.Coord(iline,2)=data2; |
---|
622 | end |
---|
623 | if ~isempty(data3) |
---|
624 | data.Coord(iline,3)=data3; |
---|
625 | end |
---|
626 | if ~isempty(data4) |
---|
627 | data.Coord(iline,4)=data4; |
---|
628 | end |
---|
629 | if isempty(data5) |
---|
630 | data.Coord(iline,5)=0; |
---|
631 | else |
---|
632 | data.Coord(iline,5)=data5; |
---|
633 | end |
---|
634 | end |
---|
635 | end |
---|
636 | data.Style='points'; |
---|
637 | |
---|
638 | |
---|
639 | % --- Executes on selection change in ListCoord. |
---|
640 | function ListCoord_Callback(hObject, eventdata, handles) |
---|
641 | % hObject handle to ListCoord (see GCBO) |
---|
642 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
643 | % handles structure with handles and user data (see GUIDATA) |
---|
644 | |
---|
645 | % Hints: contents = get(hObject,'String') returns ListCoord contents as cell array |
---|
646 | % contents{get(hObject,'Value')} returns selected item from ListCoord |
---|
647 | set(handles.edit_append,'Value',1); %set to edit mode |
---|
648 | Coord=get(handles.ListCoord,'String'); |
---|
649 | val=get(handles.ListCoord,'Value'); |
---|
650 | if length(Coord)>0 |
---|
651 | coord_str=Coord{val}; |
---|
652 | k=findstr('|',coord_str); |
---|
653 | set(handles.XObject,'String',coord_str(1:k(1)-5)) |
---|
654 | set(handles.YObject,'String',coord_str(k(1)+5:k(2)-5)) |
---|
655 | set(handles.ZObject,'String',coord_str(k(2)+5:k(3)-5)) |
---|
656 | set(handles.XImage,'String',coord_str(k(3)+5:k(4)-5)) |
---|
657 | set(handles.YImage,'String',coord_str(k(4)+5:end)) |
---|
658 | end |
---|
659 | |
---|
660 | %------------------------------------------------------ |
---|
661 | % --- Executes on button press in translation_plus. |
---|
662 | function translation_plus_Callback(hObject, eventdata, handles) |
---|
663 | |
---|
664 | T=[0 0 0]; |
---|
665 | T_x=get(handles.T_x,'String') |
---|
666 | T_y=get(handles.T_y,'String') |
---|
667 | T_z=get(handles.T_z,'String') |
---|
668 | if ~isempty(T_x) |
---|
669 | T(1)=str2num(T_x); |
---|
670 | end |
---|
671 | if ~isempty(T_y) |
---|
672 | T(2)=str2num(T_y); |
---|
673 | end |
---|
674 | if ~isempty(T_z) |
---|
675 | T(3)=str2num(T_z); |
---|
676 | end |
---|
677 | translation(handles,T) |
---|
678 | |
---|
679 | |
---|
680 | |
---|
681 | % --- Executes on button press in translation_minus. |
---|
682 | function translation_minus_Callback(hObject, eventdata, handles) |
---|
683 | |
---|
684 | T=[0 0 0]; |
---|
685 | T_x=get(handles.T_x,'String') |
---|
686 | T_y=get(handles.T_y,'String') |
---|
687 | T_z=get(handles.T_z,'String') |
---|
688 | if ~isempty(T_x) |
---|
689 | T(1)=-str2num(T_x); |
---|
690 | end |
---|
691 | if ~isempty(T_y) |
---|
692 | T(2)=-str2num(T_y); |
---|
693 | end |
---|
694 | if ~isempty(T_z) |
---|
695 | T(3)=-str2num(T_z); |
---|
696 | end |
---|
697 | translation(handles,T) |
---|
698 | |
---|
699 | |
---|
700 | %%%-------------------------------------- |
---|
701 | function translation(handles,T) |
---|
702 | data=read_probe_calib(handles); |
---|
703 | data.Coord(:,1)=T(1)+data.Coord(:,1); |
---|
704 | data.Coord(:,2)=T(2)+data.Coord(:,2); |
---|
705 | data.Coord(:,3)=T(3)+data.Coord(:,3); |
---|
706 | data.Coord(:,[4 5])=data.Coord(:,[4 5]); |
---|
707 | for i=1:size(data.Coord,1) |
---|
708 | for j=1:5 |
---|
709 | Coord{i,j}=num2str(data.Coord(i,j));%phys x,y,z |
---|
710 | end |
---|
711 | end |
---|
712 | Tabchar=cell2tab(Coord,' | '); |
---|
713 | set(handles.ListCoord,'String',Tabchar) |
---|
714 | |
---|
715 | %---------------------------------------------------- |
---|
716 | % --- Executes on button press in rotation_plus. |
---|
717 | function rotation_plus_Callback(hObject, eventdata, handles) |
---|
718 | Phi=0; |
---|
719 | Phi=get(handles.Phi,'String') |
---|
720 | if ~isempty(Phi) |
---|
721 | Phi=str2num(Phi); |
---|
722 | end |
---|
723 | rotation(handles,Phi) |
---|
724 | |
---|
725 | %------------------------------------------------- |
---|
726 | % --- Executes on button press in rotation_minus. |
---|
727 | function rotation_minus_Callback(hObject, eventdata, handles) |
---|
728 | Phi=0; |
---|
729 | Phi=get(handles.Phi,'String') |
---|
730 | if ~isempty(Phi) |
---|
731 | Phi=-str2num(Phi); |
---|
732 | end |
---|
733 | rotation(handles,Phi) |
---|
734 | |
---|
735 | %----------------------------------------------------- |
---|
736 | %rotation |
---|
737 | function rotation(handles,Phi) |
---|
738 | O_x=str2num(get(handles.O_x,'String')); |
---|
739 | O_y=str2num(get(handles.O_y,'String')); |
---|
740 | if isempty(O_x) |
---|
741 | O_x=0;%default |
---|
742 | end |
---|
743 | if isempty(O_y) |
---|
744 | O_y=0;%default |
---|
745 | end |
---|
746 | data=read_probe_calib(handles); |
---|
747 | r1=cos(pi*Phi/180); |
---|
748 | r2=-sin(pi*Phi/180); |
---|
749 | r3=sin(pi*Phi/180); |
---|
750 | r4=cos(pi*Phi/180); |
---|
751 | data.Coord(:,1)=r1*data.Coord(:,1)+r2*data.Coord(:,2); |
---|
752 | data.Coord(:,2)=r3*data.Coord(:,1)+r4*data.Coord(:,2); |
---|
753 | % data.Coord(:,[4 5])=data.Coord(:,[4 5]); |
---|
754 | for i=1:size(data.Coord,1) |
---|
755 | for j=1:5 |
---|
756 | Coord{i,j}=num2str(data.Coord(i,j));%phys x,y,z |
---|
757 | end |
---|
758 | end |
---|
759 | Tabchar=cell2tab(Coord,' | '); |
---|
760 | set(handles.ListCoord,'String',Tabchar) |
---|
761 | |
---|
762 | function O_x_Callback(hObject, eventdata, handles) |
---|
763 | % hObject handle to O_x (see GCBO) |
---|
764 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
765 | % handles structure with handles and user data (see GUIDATA) |
---|
766 | |
---|
767 | % Hints: get(hObject,'String') returns contents of O_x as text |
---|
768 | % str2double(get(hObject,'String')) returns contents of O_x as a double |
---|
769 | |
---|
770 | |
---|
771 | |
---|
772 | function O_y_Callback(hObject, eventdata, handles) |
---|
773 | % hObject handle to O_y (see GCBO) |
---|
774 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
775 | % handles structure with handles and user data (see GUIDATA) |
---|
776 | |
---|
777 | % Hints: get(hObject,'String') returns contents of O_y as text |
---|
778 | % str2double(get(hObject,'String')) returns contents of O_y as a double |
---|
779 | |
---|
780 | |
---|
781 | function O_z_Callback(hObject, eventdata, handles) |
---|
782 | % hObject handle to O_z (see GCBO) |
---|
783 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
784 | % handles structure with handles and user data (see GUIDATA) |
---|
785 | |
---|
786 | % Hints: get(hObject,'String') returns contents of O_z as text |
---|
787 | % str2double(get(hObject,'String')) returns contents of O_z as a double |
---|
788 | |
---|
789 | |
---|
790 | |
---|
791 | |
---|
792 | |
---|
793 | |
---|
794 | |
---|
795 | % --- Executes on selection change in edit_append. |
---|
796 | function edit_append_Callback(hObject, eventdata, handles) |
---|
797 | val=get(handles.edit_append,'Value'); |
---|
798 | if isequal(val,2); %append mode |
---|
799 | %appeler mouse |
---|
800 | end |
---|
801 | |
---|
802 | |
---|
803 | function NEW_Callback(hObject, eventdata, handles) |
---|
804 | %A METTRE SOUS UN BOUTON |
---|
805 | huvmat=findobj('name','uvmat'); |
---|
806 | hchild=get(huvmat,'children'); |
---|
807 | hcoord=findobj(hchild,'Tag','menu_coord') |
---|
808 | coordtype=get(hcoord,'Value') |
---|
809 | haxes=findobj(hchild,'Tag','axes3'); |
---|
810 | AxeData=get(haxes,'UserData'); |
---|
811 | if ~isequal(hcoord,2) |
---|
812 | set(hcoord,'Value',2) |
---|
813 | huvmat=uvmat(AxeData) |
---|
814 | 'relancer uvmat' |
---|
815 | end |
---|
816 | if ~isfield(AxeData,'ZoomAxes') |
---|
817 | warndlg_uvmat('first draw a window around a grid marker','ERRROR') |
---|
818 | return |
---|
819 | end |
---|
820 | XLim=get(AxeData.ZoomAxes,'XLim'); |
---|
821 | YLim=get(AxeData.ZoomAxes,'YLim'); |
---|
822 | np=size(AxeData.A); |
---|
823 | ind_sub_x=round(XLim) |
---|
824 | ind_sub_y=np(1)-round(YLim) |
---|
825 | Mfiltre=AxeData.A([ind_sub_y(2):ind_sub_y(1)] ,ind_sub_x,:); |
---|
826 | Mfiltre_norm=double(Mfiltre); |
---|
827 | Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm)); |
---|
828 | Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm))); |
---|
829 | Atype=class(AxeData.A) |
---|
830 | Data.NbDim=2; |
---|
831 | Data.A=filter2(Mfiltre_norm,double(AxeData.A)); |
---|
832 | Data.A=feval(Atype,Data.A); |
---|
833 | Data.AName='image'; |
---|
834 | Data.AX=AxeData.AX; |
---|
835 | Data.AY=AxeData.AY; |
---|
836 | Data.CoordType='px'; |
---|
837 | plot_field(Data) |
---|
838 | |
---|
839 | |
---|
840 | % --- Executes on button press in HELP. |
---|
841 | function HELP_Callback(hObject, eventdata, handles) |
---|
842 | % hObject handle to HELP (see GCBO) |
---|
843 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
844 | % handles structure with handles and user data (see GUIDATA) |
---|
845 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
846 | pathelp=fileparts(path_to_uvmat); |
---|
847 | helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html'); |
---|
848 | if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC') |
---|
849 | else |
---|
850 | web([helpfile '#probe_calib']) |
---|
851 | end |
---|
852 | |
---|
853 | %'move_key:' function activated when a key is pressed on the keyboard |
---|
854 | %----------------------------------- |
---|
855 | function key_press_fcn(hObject,eventdata,handles) |
---|
856 | hh=get(hObject,'parent') |
---|
857 | xx=double(get(hh,'CurrentCharacter')) %get the keyboard character |
---|
858 | |
---|
859 | if isequal(xx,8)%move arrow right |
---|
860 | data=read_probe_calib(handles); |
---|
861 | Coord=[]; %default |
---|
862 | if isfield(data,'Coord') |
---|
863 | Coord=data.Coord |
---|
864 | end |
---|
865 | val=get(handles.ListCoord,'Value'); |
---|
866 | Coord(val,:)=[]; |
---|
867 | CoordCell={}; |
---|
868 | for iline=1:size(Coord,1) |
---|
869 | for j=1:5 |
---|
870 | CoordCell{iline,j}=num2str(Coord(iline,j)); |
---|
871 | end |
---|
872 | end |
---|
873 | Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display |
---|
874 | val=min(size(Coord,1),val); |
---|
875 | set(handles.ListCoord,'Value',max(val,1)) |
---|
876 | set(handles.ListCoord,'String',Tabchar) |
---|
877 | end |
---|