External Email - Use Caution
Hello freesurfer experts,
I wrote some matlab functions for merging surfaces, overlays, curvature, annotations, and curvature across hemispheres for easier viewing in Freeview and in preparation for multiple comparisons correction. It all works with the exception of merging the labels.
It is odd, because out of 4 labels I've tried, 1 worked perfectly, and the others did not work at all. I cannot see any reasons why this would be the case. I wanted to see if anybody might have some insight as to what's going wrong. The function is below. x_shift is so that the hemispheres do not overlap (not sure why its necessary since when plotted separately the hemispheres do not overlap, but it is).
I also attached two output merged label files, one working (mh.STS.label), and one not working (mh.FFA.label), along with a surface to view on (apologies if it is too big and doesn't send; it is just a merged partially inflated fsaverage with x_shift = 90 applied to right hemisphere).
When the label function is fixed, I'd be happy to share the collection of functions with others who are interested.
thanks for any help, Nick
function merge_fs_hemi_labels( exp, subname, labname) %MERGE_FS_HEMI_LABELS( exp, subname, labname) % % merge freesurfer labels across hemispheres % requires freesurfer % % inputs: % % exp: experiment name under bids/ directory % subname: subject name % labname: base label name, e.g., 'OFA'. hemis will be preprended to this % using standard format, e.g. 'lh.OFA', 'rh.OFA', 'mh.OFA' % %
x_shift = 90;
bids_dir = get_bids_dir(exp); setenv('SUBJECTS_DIR',[bids_dir,'/derivatives/freesurfer']) fs_sub_dir = [bids_dir,'/derivatives/freesurfer/',subname];
surf_L = read_surf([fs_sub_dir,'/surf/lh.white']); n_nodes_L = length(surf_L);
%check for which hemispheres label exists try lab_L = read_label(subname, ['lh.',labname]); use_L = 1; catch use_L = 0; end try lab_R = read_label(subname, ['rh.',labname]); use_R = 1; catch use_R = 0; end
% determine how to create lab_M and do it if use_L && use_R lab_R(:,1) = lab_R(:,1) + n_nodes_L; lab_R(:,2) = lab_R(:,2) + x_shift; lab_M = [lab_L;lab_R]; elseif use_L && ~use_R lab_M = lab_L; elseif ~use_L && use_R lab_M = lab_R; lab_M(:,1) = lab_R(:,1) + n_nodes_L; lab_M(:,2) = lab_R(:,2) + x_shift; end
%first two lines standard for FS label files line_1 = ['#!ascii label , from subject ',subname,' vox2ras=TkReg coords=white']; line_2 = num2str(length(lab_M));
%create file, write first two lines fname_M = [fs_sub_dir,'/label/mh.',labname,'.label']; if exist(fname_M) delete(fname_M) end fid = fopen(fname_M,'w'); fprintf(fid,'%s\n%s\n', line_1, line_2); fclose(fid);
%write the tab delimited data dlmwrite(fname_M,lab_M,'-append','delimiter','\t','precision','%10.5f','newline','unix');
end
freesurfer@nmr.mgh.harvard.edu