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