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