Home > functions > common > coordinate > vb_search_matching.m

vb_search_matching

PURPOSE ^

Find optimal transformation to fit two sets of markers

SYNOPSIS ^

function [trans_opt] = vb_search_matching(V0,Vref,trans_mat,Option)

DESCRIPTION ^

 Find optimal transformation to fit two sets of markers
 [trans_opt] = vb_search_fit_coord(V0,Vref,trans_mat)
 --- Input
 V0     : Vivid vertex    : target points
 Vref   : MRI face vertex : reference points
 Option : Optimization setting
 trans_mat : Initial Rigid Body Transformation matrix
 --- Output
 trans_opt : optimal transformation to fit MRI face and vivid data

  M. Sato  2006-2-3

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [trans_opt] = vb_search_matching(V0,Vref,trans_mat,Option)
0002 % Find optimal transformation to fit two sets of markers
0003 % [trans_opt] = vb_search_fit_coord(V0,Vref,trans_mat)
0004 % --- Input
0005 % V0     : Vivid vertex    : target points
0006 % Vref   : MRI face vertex : reference points
0007 % Option : Optimization setting
0008 % trans_mat : Initial Rigid Body Transformation matrix
0009 % --- Output
0010 % trans_opt : optimal transformation to fit MRI face and vivid data
0011 %
0012 %  M. Sato  2006-2-3
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
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 % Optimization setting
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 % Coordinate Transform by Initial Rigid Body Transformation
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 % --- Minimize the distance by MATLAB optimization
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     %     = 0;    % Use 'fminsearch'
0071     %     = 1;    % Use 'fminunc' in Optimization Toolbox
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

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005