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