Home > vbmeg > functions > common > loadfunc > subdirectory > vb_fs_load_surface.m

vb_fs_load_surface

PURPOSE ^

Load surface data created by FreeSurfer and 'mris_convert'

SYNOPSIS ^

function [V,F] = vb_fs_load_surface(ascfile,xfmfile,reduce_ratio)

DESCRIPTION ^

 Load surface data created by FreeSurfer and 'mris_convert' 
 (.asc file). Vertex number is reduced. Inverse talairach 
 transformation is applied. 

 --- Syntax
 function [V,F] = vb_fs_load_surface(ascfile,xfmfile,reduce_ratio)

 --- Input
 ascfile: include cortical structure created by FreeSurfer
 reduce_ratio: Reduction ratio of vertex number (0-1)
 xfmfile: Linear transformation file (Talairach transformation)

 - This program supports linear transformation only (.xfm). 

 --- History
 2005-08-24 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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [V,F] = vb_fs_load_surface(ascfile,xfmfile,reduce_ratio)
0002 % Load surface data created by FreeSurfer and 'mris_convert'
0003 % (.asc file). Vertex number is reduced. Inverse talairach
0004 % transformation is applied.
0005 %
0006 % --- Syntax
0007 % function [V,F] = vb_fs_load_surface(ascfile,xfmfile,reduce_ratio)
0008 %
0009 % --- Input
0010 % ascfile: include cortical structure created by FreeSurfer
0011 % reduce_ratio: Reduction ratio of vertex number (0-1)
0012 % xfmfile: Linear transformation file (Talairach transformation)
0013 %
0014 % - This program supports linear transformation only (.xfm).
0015 %
0016 % --- History
0017 % 2005-08-24 Taku Yoshioka
0018 % 2008-10-16 Taku Yoshioka
0019 %   Input variable 'xfmfile' can be empty.
0020 %
0021 % Copyright (C) 2011, ATR All Rights Reserved.
0022 % License : New BSD License(see VBMEG_LICENSE.txt)
0023 
0024 % Load surface data
0025 [F0,V0] = load_surface(ascfile); % inner function
0026 
0027 % Vertex reduction
0028 if nargin>=3 & reduce_ratio<1, 
0029   [F,V] = vb_reducepatch(F0,V0,reduce_ratio); 
0030 else 
0031   F = F0; V = V0; 
0032 end
0033 
0034 if nargin>=2 & ~isempty(xfmfile), 
0035   % Load .xfm file
0036   xfm = load_xfm(xfmfile);
0037 
0038   % Inverse transformation
0039   xfm_inv = inv(xfm); 
0040   Vext = [V'; ones(1,size(V,1))];
0041   V = (xfm_inv*Vext)'; 
0042   V = V(:,1:3); 
0043 end
0044 
0045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0046 %
0047 % Inner functions
0048 %
0049 function [F,V] = load_surface(ascfile)
0050 
0051 % Open file
0052 fid = fopen(ascfile,'r');
0053 fgetl(fid); % comment line
0054 tmp = fscanf(fid,'%d %d',2); % # of vertices and patches
0055 NV = tmp(1);
0056 NF = tmp(2);
0057 tmp = fscanf(fid,'%e %e %e %e',inf);
0058 V = reshape(tmp(1:NV*4),[4 NV])';
0059 F = reshape(tmp(NV*4+1:end),[4 NF])';
0060 V = V(:,1:3); 
0061 F = F(:,1:3)+1;
0062 
0063 fclose(fid);
0064 
0065 function xfm = load_xfm(xfmfile)
0066 
0067 % Open file
0068 fid = fopen(xfmfile,'r');
0069 
0070 % Search line starts with 'Linear_Transform'
0071 chk = 0;
0072 while chk==0, 
0073   str = fgetl(fid);
0074   if strcmp(str,'Linear_Transform ='), chk = 1; end; 
0075 end
0076 
0077 % Read three lines (transformation matrix)
0078 xfm = zeros(4,4); 
0079 for i=1:3, xfm(i,:) = str2num(fgetl(fid)); end;
0080 xfm(4,:) = [0 0 0 1];
0081 
0082 fclose(fid); 
0083

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