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