Home > bioelectromagnetism > freesurfer_write_label.m

freesurfer_write_label

PURPOSE ^

freesurfer_write_label(, lname, label)

SYNOPSIS ^

function freesurfer_write_label(sname, lname, label)

DESCRIPTION ^

 freesurfer_write_label(<sname>, lname, label)

 writes the label file 'lname' from the subject 'sname' in the subject's
 label directory from the 'label' matrix, where 'label' will be
 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 in the label.
 Subsequent lines have 5 columns:
 
 1. Vertex number (0-based!)
 2-4. RAS of the vertex
 5. Statistic (which can be ignored)
 
 This function assumes the 'label' matrix was created with
 freesurfer_read_label, so it will subtract 1 from the first column.

 see also, freesurfer_label2annotation, freesurfer_read_surf

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function freesurfer_write_label(sname, lname, label)
0002 % freesurfer_write_label(<sname>, lname, label)
0003 %
0004 % writes the label file 'lname' from the subject 'sname' in the subject's
0005 % label directory from the 'label' matrix, where 'label' will be
0006 % nvertices-by-5 and each column means:
0007 %
0008 % (1) vertex number, (2-4) xyz at each vertex, (5) stat
0009 %
0010 % The Label file format (ascii):
0011 %
0012 % The first line is a comment (may have subject name).
0013 % The second line has the number of points in the label.
0014 % Subsequent lines have 5 columns:
0015 %
0016 % 1. Vertex number (0-based!)
0017 % 2-4. RAS of the vertex
0018 % 5. Statistic (which can be ignored)
0019 %
0020 % This function assumes the 'label' matrix was created with
0021 % freesurfer_read_label, so it will subtract 1 from the first column.
0022 %
0023 % see also, freesurfer_label2annotation, freesurfer_read_surf
0024 %
0025 
0026 % $Revision: 1.2 $ $Date: 2004/12/10 19:07:36 $
0027 
0028 % Licence:  GNU GPL, no implied or express warranties
0029 % History:  12/2004, Darren.Weber_at_radiology.ucsf.edu
0030 %                    adapted from freesurfer_read_label
0031 %
0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 
0034 ver = '$Revision: 1.2 $';
0035 fprintf('\nFREESURFER_WRITE_LABEL [v %s]\n',ver(11:15));
0036 
0037 if(nargin ~= 3)
0038   fprintf('freesurfer_write_label(<sname>, lname, label)\n');
0039   return;
0040 end
0041 
0042 if(~isempty(sname))
0043   sdir = getenv('SUBJECTS_DIR');
0044   fname = sprintf('%s/%s/label/%s.label', sdir, sname, lname);
0045 else
0046   fname = lname;
0047 end
0048 
0049 % open it as an ascii file
0050 fid = fopen(fname, 'w');
0051 if(fid == -1)
0052   fprintf('ERROR: could not open %s\n',fname);
0053   return;
0054 end
0055 
0056 fprintf('...writing %s\n',fname);
0057 
0058 % write the first comment line
0059 count = fprintf(fid, '#!ascii label, created by freesurfer_write_label.m [v %s]\n',ver(11:15));
0060 if count < 1,
0061   fprintf('ERROR: could not open %s\n',fname);
0062   return;
0063 end
0064 
0065 % write the number of vertices in the label
0066 nvertices = size(label,1);
0067 fprintf(fid,'%d\n',nvertices);
0068 
0069 fprintf('...subtracting 1 from vertex index column of label matrix\n');
0070 label(:,1) = label(:,1) - 1;
0071 
0072 fprintf('...writing %d label vertices\n',nvertices);
0073 fprintf(fid,'%8d %12.6f %12.6f %12.6f %12.6f\n',label');
0074 fclose(fid);
0075 
0076 return

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