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