source: trunk/src/geometry_calib.m @ 810

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