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