Load surface normal data created by FreeSurfer and 'mris_convert' (.curv.asc file). Vertex number is reduced. Inverse talairach transformation is applied. --- Syntax [N,C] = vb_fs_load_surface(ascfile,xfmfile) --- Input ascfile: include cortical structure created by FreeSurfer xfmfile: Linear transformation file (Talairach transformation) N: Unit normal vector C: Curvature - This program supports linear transformation only (.xfm). --- History 2006-01-30 Taku Yoshioka 2008-10-16 Taku Yoshioka Input variable 'xfmfile' can be empty. Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [N,C] = vb_fs_load_normal(ascfile,xfmfile) 0002 % Load surface normal data created by FreeSurfer and 'mris_convert' 0003 % (.curv.asc file). Vertex number is reduced. Inverse talairach 0004 % transformation is applied. 0005 % 0006 % --- Syntax 0007 % [N,C] = vb_fs_load_surface(ascfile,xfmfile) 0008 % 0009 % --- Input 0010 % ascfile: include cortical structure created by FreeSurfer 0011 % xfmfile: Linear transformation file (Talairach transformation) 0012 % N: Unit normal vector 0013 % C: Curvature 0014 % 0015 % - This program supports linear transformation only (.xfm). 0016 % 0017 % --- History 0018 % 2006-01-30 Taku Yoshioka 0019 % 2008-10-16 Taku Yoshioka 0020 % Input variable 'xfmfile' can be empty. 0021 % 0022 % Copyright (C) 2011, ATR All Rights Reserved. 0023 % License : New BSD License(see VBMEG_LICENSE.txt) 0024 0025 % Load normal data 0026 n = load('-ascii',ascfile); % inner function 0027 N = n(:,2:4); 0028 C = n(:,5); 0029 ix = find(C==0); 0030 C(ix) = 1; 0031 0032 if nargin>=2 & ~isempty(xfmfile), 0033 % Load .xfm file 0034 xfm = load_xfm(xfmfile); 0035 0036 % Inverse transformation 0037 xfm_inv = inv(xfm); 0038 Next = [N'; zeros(1,size(N,1))]; 0039 N = (xfm_inv*Next)'; 0040 N = N(:,1:3).*repmat(sign(C),[1 3]); 0041 end; 0042 0043 % Normalization 0044 Nnorm = sqrt(sum(N.^2,2)); 0045 N = N./repmat(Nnorm,[1 3]); 0046 0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0048 % 0049 % Inner functions 0050 % 0051 function xfm = load_xfm(xfmfile) 0052 0053 % Open file 0054 fid = fopen(xfmfile,'r'); 0055 0056 % Search line starts with 'Linear_Transform' 0057 chk = 0; 0058 while chk==0, 0059 str = fgetl(fid); 0060 if strcmp(str,'Linear_Transform ='), chk = 1; end; 0061 end 0062 0063 % Read three lines (transformation matrix) 0064 xfm = zeros(4,4); 0065 for i=1:3, xfm(i,:) = str2num(fgetl(fid)); end; 0066 xfm(4,:) = [0 0 0 1]; 0067 0068 fclose(fid); 0069