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