Home > bioelectromagnetism > freesurfer_read_subject.m

freesurfer_read_subject

PURPOSE ^

freesurfer_read_subject - Call functions to read subject surface data

SYNOPSIS ^

function [subject] = freesurfer_read_subject(subjectPath,filetype)

DESCRIPTION ^

 freesurfer_read_subject - Call functions to read subject surface data

 [subject] = freesurfer_read_subject(subjectPath,filetype)

 This a general wrapper for reading lh/rh surface data.  It calls other
 input functions, such as freesurfer_read_surf.  The main purpose of this
 function is to integrate the surface data into a coherent, consistent
 data structure.

 subjectPath is a full path to the subject folder, which contains all the
 freesurfer subdirectories, such as mri, surf, label etc.

 filetype is a cell array of strings to indicate what files to read, such
 as 'orig', 'smoothwm', 'inflated', 'white', 'pial', 'curv', 'thickness',
 etc.  The default 'all' will read surfaces and their curvature/thickness'
 that is:

 filetype = {'brain','orig','smoothwm','white','pial','inflated',...
             'curv','thickness','aparc','xfm'}

 subject is a data structure with fields for the '.file' paths and the
 data, including .brain and cortical surfaces, the latter are separated
 into .lh and .rh fields and subfields for each file type read.  If the
 talairach.xfm file exists in the <subject>/mri/transforms, the matrix is
 returned into subject.TalairachXFM; to get the Talairach coordinates, use
 freesurfer_surf2tal

 See also freesurfer_read_surf, freesurfer_read_curv

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [subject] = freesurfer_read_subject(subjectPath,filetype)
0002 
0003 % freesurfer_read_subject - Call functions to read subject surface data
0004 %
0005 % [subject] = freesurfer_read_subject(subjectPath,filetype)
0006 %
0007 % This a general wrapper for reading lh/rh surface data.  It calls other
0008 % input functions, such as freesurfer_read_surf.  The main purpose of this
0009 % function is to integrate the surface data into a coherent, consistent
0010 % data structure.
0011 %
0012 % subjectPath is a full path to the subject folder, which contains all the
0013 % freesurfer subdirectories, such as mri, surf, label etc.
0014 %
0015 % filetype is a cell array of strings to indicate what files to read, such
0016 % as 'orig', 'smoothwm', 'inflated', 'white', 'pial', 'curv', 'thickness',
0017 % etc.  The default 'all' will read surfaces and their curvature/thickness'
0018 % that is:
0019 %
0020 % filetype = {'brain','orig','smoothwm','white','pial','inflated',...
0021 %             'curv','thickness','aparc','xfm'}
0022 %
0023 % subject is a data structure with fields for the '.file' paths and the
0024 % data, including .brain and cortical surfaces, the latter are separated
0025 % into .lh and .rh fields and subfields for each file type read.  If the
0026 % talairach.xfm file exists in the <subject>/mri/transforms, the matrix is
0027 % returned into subject.TalairachXFM; to get the Talairach coordinates, use
0028 % freesurfer_surf2tal
0029 %
0030 % See also freesurfer_read_surf, freesurfer_read_curv
0031 %
0032 
0033 % $Revision: 1.3 $ $Date: 2005/08/14 21:22:42 $
0034 
0035 % Copyright (C) 2000  Darren L. Weber
0036 %
0037 % This program is free software; you can redistribute it and/or
0038 % modify it under the terms of the GNU General Public License
0039 % as published by the Free Software Foundation; either version 2
0040 % of the License, or (at your option) any later version.
0041 %
0042 % This program is distributed in the hope that it will be useful,
0043 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0044 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0045 % GNU General Public License for more details.
0046 %
0047 % You should have received a copy of the GNU General Public License
0048 % along with this program; if not, write to the Free Software
0049 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
0050 % USA.
0051 
0052 % History:  04/2005, Darren.Weber_at_radiology.ucsf.edu
0053 %
0054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0055 
0056 ver = '$Revision: 1.3 $ $Date: 2005/08/14 21:22:42 $';
0057 fprintf('FREESURFER_READ_SUBJECT [v %s]\n',ver(11:15));
0058 
0059 if ~exist('subjectPath','var'),
0060     error('no subjectPath specified');
0061 end
0062 if isempty(subjectPath),
0063     error('empty subjectPath specified');
0064 end
0065 if exist(subjectPath) ~= 7,
0066     error('subjectPath specified is not a directory');
0067 end
0068 
0069 surfPath = fullfile(subjectPath,'surf','');
0070 labelPath = fullfile(subjectPath,'label','');
0071 mriPath = fullfile(subjectPath,'mri','');
0072 xfmPath = fullfile(mriPath,'transforms','');
0073 brainPath = fullfile(subjectPath,'bem','');
0074 
0075 %subject.avwPath = fullfile(mriPath,'analyze','');
0076 
0077 
0078 if ~exist('filetype','var'),
0079     filetype = 'all';
0080 end
0081 if isempty(filetype),
0082     filetype = 'all';
0083 end
0084 
0085 filetype = lower(filetype);
0086 if strmatch('all',filetype),
0087     filetype = {'brain','orig','smoothwm','white','pial','inflated','curv','thickness','aparc','xfm'};
0088 end
0089 
0090 for f = filetype,
0091     f = f{:};
0092     switch f,
0093 
0094         case {'brain'},
0095 
0096             % load brain surface
0097             file.brain = fullfile(brainPath,'brain.tri');
0098             if exist(file.brain) == 2,
0099                 [brain.vertices, brain.faces] = freesurfer_read_tri(file.brain);
0100                 subject.brain = brain;
0101             else
0102                 msg = sprintf('file does not exist: %s',file.brain);
0103                 warning(msg);
0104             end
0105 
0106         case {'orig'},
0107 
0108             % load orig surfaces
0109             file.lh.orig = fullfile(surfPath,'lh.orig');
0110             if exist(file.lh.orig) == 2,
0111                 [lh.orig.vertices, lh.orig.faces] = freesurfer_read_surf(file.lh.orig);
0112             else
0113                 msg = sprintf('file does not exist: %s',file.lh.orig);
0114                 warning(msg);
0115             end
0116 
0117             file.rh.orig = fullfile(surfPath,'rh.orig');
0118             if exist(file.rh.orig) == 2,
0119                 [rh.orig.vertices, rh.orig.faces] = freesurfer_read_surf(file.rh.orig);
0120             else
0121                 msg = sprintf('file does not exist: %s',file.rh.orig);
0122                 warning(msg);
0123             end
0124 
0125         case {'smoothwm'},
0126 
0127             % load smoothwm surfaces
0128             file.lh.smoothwm = fullfile(surfPath,'lh.smoothwm');
0129             if exist(file.lh.smoothwm) == 2,
0130                 [lh.smoothwm.vertices, lh.smoothwm.faces] = freesurfer_read_surf(file.lh.smoothwm);
0131             else
0132                 msg = sprintf('file does not exist: %s',file.lh.smoothwm);
0133                 warning(msg);
0134             end
0135 
0136             file.rh.smoothwm = fullfile(surfPath,'rh.smoothwm');
0137             if exist(file.rh.smoothwm) == 2,
0138                 [rh.smoothwm.vertices, rh.smoothwm.faces] = freesurfer_read_surf(file.rh.smoothwm);
0139             else
0140                 msg = sprintf('file does not exist: %s',file.rh.smoothwm);
0141                 warning(msg);
0142             end
0143 
0144         case {'white'},
0145 
0146             % load white surfaces
0147             file.lh.white = fullfile(surfPath,'lh.white');
0148             if exist(file.lh.white) == 2,
0149                 [lh.white.vertices, lh.white.faces] = freesurfer_read_surf(file.lh.white);
0150             else
0151                 msg = sprintf('file does not exist: %s',file.lh.white);
0152                 warning(msg);
0153             end
0154 
0155             file.rh.white = fullfile(surfPath,'rh.white');
0156             if exist(file.rh.white) == 2,
0157                 [rh.white.vertices, rh.white.faces] = freesurfer_read_surf(file.rh.white);
0158             else
0159                 msg = sprintf('file does not exist: %s',file.rh.white);
0160                 warning(msg);
0161             end
0162 
0163         case {'pial'},
0164 
0165             % load pial surfaces
0166             file.lh.pial = fullfile(surfPath,'lh.pial');
0167             if exist(file.lh.pial) == 2,
0168                 [lh.pial.vertices, lh.pial.faces] = freesurfer_read_surf(file.lh.pial);
0169             else
0170                 msg = sprintf('file does not exist: %s',file.lh.pial);
0171                 warning(msg);
0172             end
0173 
0174             file.rh.pial = fullfile(surfPath,'rh.pial');
0175             if exist(file.rh.pial) == 2,
0176                 [rh.pial.vertices, rh.pial.faces] = freesurfer_read_surf(file.rh.pial);
0177             else
0178                 msg = sprintf('file does not exist: %s',file.rh.pial);
0179                 warning(msg);
0180             end
0181 
0182         case {'inflated'},
0183 
0184             % load inflated surfaces
0185             file.lh.inflated = fullfile(surfPath,'lh.inflated');
0186             if exist(file.lh.inflated) == 2,
0187                 [lh.inflated.vertices, lh.inflated.faces] = freesurfer_read_surf(file.lh.inflated);
0188             else
0189                 msg = sprintf('file does not exist: %s',file.lh.inflated);
0190                 warning(msg);
0191             end
0192 
0193             file.rh.inflated = fullfile(surfPath,'rh.inflated');
0194             if exist(file.rh.inflated) == 2,
0195                 [rh.inflated.vertices, rh.inflated.faces] = freesurfer_read_surf(file.rh.inflated);
0196             else
0197                 msg = sprintf('file does not exist: %s',file.rh.inflated);
0198                 warning(msg);
0199             end
0200 
0201         case {'curv'},
0202 
0203             % load curvature
0204             file.lh.curv = fullfile(surfPath,'lh.curv');
0205             if exist(file.lh.curv) == 2,
0206                 lh.curv = freesurfer_read_curv(file.lh.curv);
0207             else
0208                 msg = sprintf('file does not exist: %s',file.lh.curv);
0209                 warning(msg);
0210             end
0211             
0212             file.rh.curv = fullfile(surfPath,'rh.curv');
0213             if exist(file.rh.curv) == 2,
0214                 rh.curv = freesurfer_read_curv(file.rh.curv);
0215             else
0216                 msg = sprintf('file does not exist: %s',file.rh.curv);
0217                 warning(msg);
0218             end
0219 
0220         case {'thickness'},
0221 
0222             % load thickness
0223             file.lh.thickness = fullfile(surfPath,'lh.thickness');
0224             if exist(file.lh.thickness) == 2,
0225                 lh.thickness = freesurfer_read_thickness(file.lh.thickness);
0226             else
0227                 msg = sprintf('file does not exist: %s',file.lh.thickness);
0228                 warning(msg);
0229             end
0230             
0231             file.rh.thickness = fullfile(surfPath,'rh.thickness');
0232             if exist(file.rh.thickness) == 2,
0233                 rh.thickness = freesurfer_read_thickness(file.rh.thickness);
0234             else
0235                 msg = sprintf('file does not exist: %s',file.rh.thickness);
0236                 warning(msg);
0237             end
0238 
0239         case {'aparc'},
0240 
0241             % load parcellation
0242             file.lh.aparc = fullfile(labelPath,'lh.aparc.annot');
0243             if exist(file.lh.aparc) == 2,
0244                 lh.aparc = freesurfer_read_annotation(file.lh.aparc);
0245             else
0246                 msg = sprintf('file does not exist: %s',file.lh.aparc);
0247                 warning(msg);
0248             end
0249             
0250             file.rh.aparc = fullfile(labelPath,'rh.aparc.annot');
0251             if exist(file.rh.aparc) == 2,
0252                 rh.aparc = freesurfer_read_annotation(file.rh.aparc);
0253             else
0254                 msg = sprintf('file does not exist: %s',file.rh.aparc);
0255                 warning(msg);
0256             end
0257 
0258         case {'xfm'},
0259 
0260             % load Talairach transform
0261             file.xfm = fullfile(xfmPath,'talairach.xfm');
0262             if exist(file.xfm) == 2,
0263                 subject.TalairachXFM = freesurfer_read_talxfm(file.xfm);
0264             else
0265                 msg = sprintf('file does not exist: %s',file.xfm);
0266                 warning(msg);
0267             end
0268     end
0269 end
0270 
0271 subject.file = file;
0272 subject.lh = lh;
0273 subject.rh = rh;
0274 
0275 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003