applybvtrf.m

来自「toolbox of BVQX, This is the access betw」· M 代码 · 共 57 行

M
57
字号
function tc = applybvtrf(c, t, it)
% applybvtrf  - apply BV transformation matrix to system coords
%
% FORMAT:       tc = applybvtrf(c, t [, it])
%
% Input fields:
%
%       c           Cx3 coordinate list
%       t           4x4 transformation matrix (from TRF file, type 2)
%       it          inverse transformation flag, default: true (!)
%
% Output fields:
%
%       tc          transformed coordinates
% 
% Note: since BV stores the transformation as to sample the intensities
%       the matrix is actually already an inverse of the configured
%       matrix. To keep this logic, the it parameter must be set to false

% Version:  v0.7b
% Build:    7083014
% Date:     Aug-30 2007, 2:41 PM CEST
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 2 || ...
   ~isa(c, 'double') || ...
   ~isa(t, 'double') || ...
    size(c, 2) ~= 3 || ...
    numel(t) ~= 16 || ...
    any(size(t) ~= 4) || ...
    any(isinf(t(:)) | isnan(t(:)))
    error( ...
        'BVQXtools:BadArgument', ...
        'Bad or missing input argument.' ...
    );
end
if nargin < 3 || ...
   ~islogical(it) || ...
    isempty(it)
    it = true;
end

% swap and append columns, subtract center coordinate
tc = [c(:, [2, 3, 1]) - 127.5, ones(size(c, 1), 1)];

% apply transformation
if it(1)
    tc = tc * inv(t)';
else
    tc = tc * t';
end

% swap and remove columns again and add center again
tc = 127.5 + tc(:, [3, 1, 2]);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?