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