Home > vbmeg > functions > common > coordinate > vb_search_fit_coord.m

vb_search_fit_coord

PURPOSE ^

Find optimal transformation to fit MRI face and vivid data

SYNOPSIS ^

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

DESCRIPTION ^

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

  M. Sato  2006-5-22

 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_fit_coord(V0,Vref,trans_mat,Option)
0002 % Find optimal transformation to fit MRI face and vivid data
0003 % [trans_opt] = vb_search_fit_coord(V0,Vref,trans_mat,Option)
0004 % --- Input
0005 % V0     : Vivid vertex    : target points
0006 % Vref   : MRI face vertex : reference points
0007 % trans_mat : Initial Rigid Body Transformation matrix
0008 % Option : Optimization setting
0009 % --- Output
0010 % trans_opt : optimal transformation to fit MRI face and vivid data
0011 %
0012 %  M. Sato  2006-5-22
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
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 % Optimization setting
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 % Coordinate Transform by Initial Rigid Body Transformation
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 % --- Minimize the distance by MATLAB optimization
0053 %
0054 
0055 % Rmax = Minimun distance search radius
0056 if isfield(Option,'Rmax') & ~isempty(Option.Rmax)
0057     parm.Rmax = Option.Rmax; 
0058 else
0059     parm.Rmax = 0.003; % = 3 [mm]
0060 end;
0061 
0062 % Npos = # of head points
0063 if isfield(Option,'Npos') & ~isempty(Option.Npos)
0064     parm.Npos = Option.Npos; 
0065 else
0066     parm.Npos = 0;
0067 end;
0068 
0069 % pos_rate  = distance weight for head points
0070 % scan_rate = distance weight for scaned face points
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 % Search method
0083 if isfield(Option,'method') & ~isempty(Option.method)
0084     mode = Option.method;
0085 else
0086     mode = vb_tool_check('Optimization');
0087     %     = 0;    % Use 'fminsearch'
0088     %     = 1;    % Use 'fminunc' in Optimization Toolbox
0089 end
0090 
0091 param_init = zeros(6,1);
0092 
0093 switch    mode
0094 case    0
0095     % Nelder-Mead Simplex Method
0096     [optparam, minval, exitflg, output]= ...
0097         fminsearch(@vb_calc_fitting, param_init, OPTIONS, V0, Vref, parm);
0098 case    1
0099     % Unconstrained optimization
0100     [optparam, minval, exitflg, output]= ...
0101         fminunc(@vb_calc_fitting, param_init, OPTIONS, V0, Vref, parm);
0102 case    2
0103     % Optimization in bounded region
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

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005