0001 function [trans_opt] = vb_search_fit_coord(V0,Vref,trans_mat,Option)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 Npoint = size(V0,1);
0018
0019 fprintf('Number of reference points = %d\n',size(Vref,1))
0020 fprintf('Number of target points = %d\n',Npoint)
0021
0022
0023 if isfield(Option,'MaxIter') & ~isempty(Option.MaxIter)
0024 MaxIter = Option.MaxIter;
0025 else
0026 MaxIter = 200;
0027 end;
0028
0029 if isfield(Option,'TolFun') & ~isempty(Option.TolFun)
0030 TolFun = Option.TolFun;
0031 else
0032 TolFun = 1.e-10;
0033 end;
0034
0035 OPTIONS = optimset( ...
0036 'MaxIter', MaxIter, ...
0037 'MaxFunEvals', 2*MaxIter,...
0038 'TolX', 1e-6, ...
0039 'TolFun', TolFun, ...
0040 'display', 'iter', ...
0041 'GradObj', 'off' ...
0042 );
0043
0044
0045 if exist('trans_mat','var') & ~isempty(trans_mat)
0046 V0 = [V0 ones(size(V0,1),1)]*trans_mat;
0047 else
0048 trans_mat = eye(4,3);
0049 end
0050
0051
0052
0053
0054
0055
0056 if isfield(Option,'Rmax') & ~isempty(Option.Rmax)
0057 parm.Rmax = Option.Rmax;
0058 else
0059 parm.Rmax = 0.003;
0060 end;
0061
0062
0063 if isfield(Option,'Npos') & ~isempty(Option.Npos)
0064 parm.Npos = Option.Npos;
0065 else
0066 parm.Npos = 0;
0067 end;
0068
0069
0070
0071 if isfield(Option,'pos_rate') & ~isempty(Option.pos_rate)
0072 parm.pos_rate = Option.pos_rate;
0073 else
0074 parm.pos_rate = 1;
0075 end;
0076 if isfield(Option,'scan_rate') & ~isempty(Option.scan_rate)
0077 parm.scan_rate = Option.scan_rate;
0078 else
0079 parm.scan_rate = 1.0;
0080 end;
0081
0082
0083 if isfield(Option,'method') & ~isempty(Option.method)
0084 mode = Option.method;
0085 else
0086 mode = vb_tool_check('Optimization');
0087
0088
0089 end
0090
0091 param_init = zeros(6,1);
0092
0093 switch mode
0094 case 0
0095
0096 [optparam, minval, exitflg, output]= ...
0097 fminsearch(@vb_calc_fitting, param_init, OPTIONS, V0, Vref, parm);
0098 case 1
0099
0100 [optparam, minval, exitflg, output]= ...
0101 fminunc(@vb_calc_fitting, param_init, OPTIONS, V0, Vref, parm);
0102 case 2
0103
0104 [optparam, minval, exitflg, output]= ...
0105 fmincon(@vb_calc_fitting, param_init, ...
0106 [],[],[],[], Option.low, Option.up, [], OPTIONS, V0, Vref, parm);
0107 end
0108
0109 trans_opt = vb_rigid_trans_matrix(optparam);
0110
0111 trans_opt = [trans_mat [zeros(3,1); 1]] * trans_opt;
0112