Home > bioelectromagnetism > freesurfer_labels2annotation.m

freesurfer_labels2annotation

PURPOSE ^

freesurfer_labels2annotation(sname,hemi,label_file_list,annot_file)

SYNOPSIS ^

function freesurfer_labels2annotation(sname,hemi,label_file_list,annot_file)

DESCRIPTION ^

 freesurfer_labels2annotation(sname,hemi,label_file_list,annot_file)

 sname = subject name
 hemi = 'lh'  or 'rh'
 label_file_list = a cell array of strings naming the labels, without the
                   .label suffix
 annot_file = the name of the output annotation file

 see also freesurfer_read_label, freesurfer_read_annotation

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function freesurfer_labels2annotation(sname,hemi,label_file_list,annot_file)
0002 
0003 % freesurfer_labels2annotation(sname,hemi,label_file_list,annot_file)
0004 %
0005 % sname = subject name
0006 % hemi = 'lh'  or 'rh'
0007 % label_file_list = a cell array of strings naming the labels, without the
0008 %                   .label suffix
0009 % annot_file = the name of the output annotation file
0010 %
0011 % see also freesurfer_read_label, freesurfer_read_annotation
0012 %
0013 
0014 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:34 $
0015 
0016 % Licence:  GNU GPL, no implied or express warranties
0017 % History:  08/2004, Daniel Goldenholz at NMR MGH HARVARD
0018 %           08/2004, Darren Weber, adapted to eeg_toolbox
0019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0020 
0021 ver = '$Revision: 1.1 $';
0022 fprintf('FREESURFER_LABELS2ANNOTATION [v %s]\n',ver(11:15));
0023 
0024 sdir = getenv('SUBJECTS_DIR');
0025 if isempty(sname),
0026     sname = getenv('SUBJECT');
0027 end
0028 
0029 % step 1: establish number of vertices by loading a surface file
0030 surfname = sprintf('%s/%s/surf/%s.inflated',sdir,sname,hemi);
0031 vertices = freesurfer_read_surf(surfname);
0032 nverts = size(vertices,1);
0033 clear vertices;
0034 
0035 % step 2: generate annotation vector
0036 vnums = 0:(nverts-1);
0037 inds = 1:2:nverts*2;
0038 annot_vec = zeros(1,nverts*2);
0039 annot_vec(inds) = vnums;
0040 cnums = zeros(1,nverts);
0041 
0042 % step 3: color in the annotation
0043 for i=1:length(label_file_list)
0044     fname = label_file_list{i} ;
0045     label_mat = freesurfer_read_label(sname,fname);
0046     verts = label_mat(:,1);
0047     thiscolor = ceil(2^24 * i / length(label_file_list)); 
0048     cnums(verts+1) = thiscolor;
0049 end
0050 
0051 % step 4: fill in colors
0052 inds = 2:2:nverts*2;
0053 annot_vec(inds) = cnums;
0054 
0055 % step 5: save annotation
0056 % open it as a big-endian file
0057 fid = fopen(annot_file, 'wb', 'b');
0058 if (fid < 0)
0059     str = sprintf('could not open annotation file %s.', fname);
0060     error(str);
0061 end
0062 fwrite(fid, nverts, 'int32');
0063 fwrite(fid, annot_vec, 'int');
0064 fclose(fid);
0065 
0066 return

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