Home > bioelectromagnetism > freesurfer_read_label.m

freesurfer_read_label

PURPOSE ^

label = freesurfer_read_label(, lname)

SYNOPSIS ^

function [label] = freesurfer_read_label(sname, lname)

DESCRIPTION ^

 label = freesurfer_read_label(<sname>, lname)

 reads the label file 'lname' from the subject 'sname' in the subject's
 label directory.  'lname' is the label filename (with or without the
 .label extension).  If 'sname' is empty, the function reads
 lname from the current working directory.

 returns the 'label' matrix, nvertices-by-5, and each column means:

 (1) vertex number, (2-4) xyz at each vertex, (5) stat

 The Label file format (ascii):

 The first line is a comment (may have subject name).
 The second line has the number of points (vertices) in the label.
 Subsequent lines have 5 columns:

 1   - Vertex number (0-based!, this function adds 1 to this vector)
 2:4 - RAS of the vertex
 5   - Statistic (which can be ignored)

 see also, freesurfer_label2annotation, freesurfer_read_surf

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [label] = freesurfer_read_label(sname, lname)
0002 
0003 % label = freesurfer_read_label(<sname>, lname)
0004 %
0005 % reads the label file 'lname' from the subject 'sname' in the subject's
0006 % label directory.  'lname' is the label filename (with or without the
0007 % .label extension).  If 'sname' is empty, the function reads
0008 % lname from the current working directory.
0009 %
0010 % returns the 'label' matrix, nvertices-by-5, and each column means:
0011 %
0012 % (1) vertex number, (2-4) xyz at each vertex, (5) stat
0013 %
0014 % The Label file format (ascii):
0015 %
0016 % The first line is a comment (may have subject name).
0017 % The second line has the number of points (vertices) in the label.
0018 % Subsequent lines have 5 columns:
0019 %
0020 % 1   - Vertex number (0-based!, this function adds 1 to this vector)
0021 % 2:4 - RAS of the vertex
0022 % 5   - Statistic (which can be ignored)
0023 %
0024 % see also, freesurfer_label2annotation, freesurfer_read_surf
0025 %
0026 
0027 % $Revision: 1.4 $ $Date: 2005/07/05 23:37:47 $
0028 
0029 % Licence:  GNU GPL, no implied or express warranties
0030 % History:  08/2004, Darren.Weber_at_radiology.ucsf.edu
0031 %                    obtained matlab code from the MGH
0032 %           12/2004, Darren.Weber_at_radiology.ucsf.edu
0033 %                    added 1 to vertex index
0034 %           06/2005, Darren.Weber_at_radiology.ucsf.edu
0035 %                    modified help information and the definition of fname
0036 %                    when sname is empty, fname = [lname,'.label'].
0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0038 
0039 ver = '$Revision: 1.4 $';
0040 fprintf('FREESURFER_READ_LABEL [v %s]\n',ver(11:15));
0041 
0042 if(nargin ~= 2)
0043     fprintf('label = freesurfer_read_label(<sname>, lname)\n');
0044     return;
0045 end
0046 
0047 if(~isempty(sname))
0048     sdir = getenv('SUBJECTS_DIR');
0049     [path,file,ext] = fileparts(lname);
0050     fname = fullfile(sdir, sname,'label',[file,'.label']);
0051 else
0052     [path,file,ext] = fileparts(lname);
0053     fname = fullfile(path,[file,'.label']);
0054 end
0055 
0056 % open it as an ascii file
0057 fid = fopen(fname, 'r');
0058 if(fid == -1)
0059     fprintf('ERROR: could not open %s\n',fname);
0060     return;
0061 end
0062 
0063 fgets(fid);  % read the first comment line
0064 if(fid == -1)
0065     fprintf('ERROR: could not open %s\n',fname);
0066     return;
0067 end
0068 
0069 fprintf('...reading %s\n',fname);
0070 
0071 % read the number of vertices in the label
0072 line = fgets(fid);
0073 nvertices = sscanf(line, '%d');
0074 
0075 fprintf('...reading %d label vertices\n',nvertices);
0076 label = fscanf(fid, '%d %f %f %f %f\n');
0077 fclose(fid);
0078 
0079 label = reshape(label, 5, nvertices);
0080 label = label';
0081 
0082 fprintf('...adding 1 to vertex index for matlab compatibility\n\n');
0083 label(:,1) = label(:,1) + 1;
0084 
0085 return

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