0001 function freesurfer_labels2annotation(sname,hemi,label_file_list,annot_file)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
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
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
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
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
0052 inds = 2:2:nverts*2;
0053 annot_vec(inds) = cnums;
0054
0055
0056
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