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