0001 function [trans_opt] = vb_search_matching(V0,Vref,trans_mat,Option)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 NP = size(Vref,1);
0018 NP2 = size(V0,1);
0019
0020 if NP ~= NP2,
0021 error('Number of marker points are different');
0022 end
0023
0024 fprintf('Number of marker = %d\n',NP)
0025
0026 if isfield(Option,'Weight') & ~isempty(Option.Weight)
0027 Weight = Option.Weight;
0028 else
0029 Weight = ones(NP,1);
0030 end;
0031
0032
0033 if isfield(Option,'MaxIter') & ~isempty(Option.MaxIter)
0034 MaxIter = Option.MaxIter;
0035 else
0036 MaxIter = 200;
0037 end;
0038
0039 if isfield(Option,'TolFun') & ~isempty(Option.TolFun)
0040 TolFun = Option.TolFun;
0041 else
0042 TolFun = 1.e-10;
0043 end;
0044
0045 OPTIONS = optimset( ...
0046 'MaxIter', MaxIter, ...
0047 'MaxFunEvals', 2*MaxIter,...
0048 'TolX', 1e-6, ...
0049 'TolFun', TolFun, ...
0050 'display', 'iter', ...
0051 'GradObj', 'off' ...
0052 );
0053
0054
0055 if exist('trans_mat','var') & ~isempty(trans_mat)
0056 V0 = [V0 ones(size(V0,1),1)]*trans_mat;
0057 else
0058 trans_mat = eye(4,3);
0059 end
0060
0061
0062
0063
0064 param_init = zeros(6,1);
0065
0066 if isfield(Option,'method') & ~isempty(Option.method)
0067 mode = Option.method;
0068 else
0069 mode = vb_tool_check('Optimization');
0070
0071
0072 end
0073
0074 switch mode
0075 case 0
0076 [optparam, minval, exitflg, output]= ...
0077 fminsearch(@vb_calc_matching, param_init, OPTIONS, V0, Vref, Weight);
0078 case 1
0079 [optparam, minval, exitflg, output]= ...
0080 fminunc(@vb_calc_matching, param_init, OPTIONS, V0, Vref, Weight);
0081 end
0082
0083 trans_opt = vb_rigid_trans_matrix(optparam);
0084
0085 trans_opt = [trans_mat [zeros(3,1); 1]] * trans_opt;
0086