Home > vbmeg > external > mne > mne_morph_data.m

mne_morph_data

PURPOSE ^

MNE_MORPH_DATA Returns data morphed to a new subject.

SYNOPSIS ^

function [stcs] = mne_morph_data(from,to,stcs,grade)

DESCRIPTION ^

 MNE_MORPH_DATA   Returns data morphed to a new subject.

   SYNTAX
       [STCS] = MNE_MORPH_DATA(FROM, TO, STCS, GRADE)

   from : name of origin subject
   to : name of destination subject
   stcs : stc data to morph
   grade : (optional) resolution of the icosahedral mesh (typically 5)

 Note : The functions requires to set MNE_ROOT and SUBJECTS_DIR variables.

 Example:
  from = 'sample';
  to = 'fsaverage';
  stcs_morph = mne_morph_data(from,to,stcs,5);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [stcs] = mne_morph_data(from,to,stcs,grade)
0002 % MNE_MORPH_DATA   Returns data morphed to a new subject.
0003 %
0004 %   SYNTAX
0005 %       [STCS] = MNE_MORPH_DATA(FROM, TO, STCS, GRADE)
0006 %
0007 %   from : name of origin subject
0008 %   to : name of destination subject
0009 %   stcs : stc data to morph
0010 %   grade : (optional) resolution of the icosahedral mesh (typically 5)
0011 %
0012 % Note : The functions requires to set MNE_ROOT and SUBJECTS_DIR variables.
0013 %
0014 % Example:
0015 %  from = 'sample';
0016 %  to = 'fsaverage';
0017 %  stcs_morph = mne_morph_data(from,to,stcs,5);
0018 %
0019 %
0020 
0021 %
0022 %   Author : Alexandre Gramfort, MGH Martinos Center
0023 %            Matti Hamalainen
0024 %   License : BSD 3-clause
0025 %
0026 
0027 if nargin < 5
0028     grade = 5;
0029 end
0030 
0031 sphere_from = [getenv('SUBJECTS_DIR'),'/',from,'/surf/lh.sphere.reg'];
0032 [tmp, tris{1}] = mne_read_surface(sphere_from);
0033 sphere_from = [getenv('SUBJECTS_DIR'),'/',from,'/surf/rh.sphere.reg'];
0034 [tmp, tris{2}] = mne_read_surface(sphere_from);
0035 
0036 [map{1}, map{2}] = mne_read_morph_map(from,to);
0037 
0038 for hemi = 1:2
0039     e = mne_mesh_edges(tris{hemi});
0040     e = e==2;
0041     n_vertices = length(e);
0042     e = e + speye(n_vertices, n_vertices);
0043     idx_use = stcs{hemi}.vertices + 1;
0044     n_iter = 100; % nb of smoothing iterations
0045     for k = 1:n_iter
0046         data1 = e(:,idx_use) * ones(length(idx_use),1);
0047         stcs{hemi}.data  = e(:,idx_use)*stcs{hemi}.data;
0048         idx_use = find(data1);
0049         fprintf(1,'%d/%d ',k,length(idx_use));
0050         if ( k == n_iter ) || ( length(idx_use) >= n_vertices )
0051             stcs{hemi}.data(idx_use,:) = bsxfun(@rdivide, stcs{hemi}.data(idx_use,:), data1(idx_use));
0052             break;
0053         else
0054             stcs{hemi}.data = bsxfun(@rdivide, stcs{hemi}.data(idx_use,:), data1(idx_use));
0055         end
0056     end
0057     fprintf(1,'\n');
0058     stcs{hemi}.data = map{hemi}*stcs{hemi}.data;
0059 end
0060 
0061 ico_file_name = [getenv('MNE_ROOT'),'/share/mne/icos.fif'];
0062 
0063 s = mne_read_bem_surfaces(ico_file_name);
0064 
0065 for k = 1:length(s)
0066     if (s(k).id == 9000 + grade)
0067         ico = s(k);
0068         break;
0069     end
0070 end
0071 
0072 sphere = [getenv('SUBJECTS_DIR'),'/',to,'/surf/lh.sphere.reg'];
0073 lhs = mne_read_surface(sphere);
0074 sphere = [getenv('SUBJECTS_DIR'),'/',to,'/surf/rh.sphere.reg'];
0075 rhs = mne_read_surface(sphere);
0076 
0077 nearest{1} = zeros(ico.np, 1);
0078 nearest{2} = zeros(ico.np, 1);
0079 
0080 lhs =  bsxfun(@rdivide, lhs, sqrt(sum(lhs.^2, 2)));
0081 rhs =  bsxfun(@rdivide, rhs, sqrt(sum(rhs.^2, 2)));
0082 
0083 for k = 1:size(ico.rr,1)
0084     dots = ico.rr(k,:)*lhs';
0085     [tmp, nearest{1}(k)] = max(dots);
0086     dots = ico.rr(k,:)*rhs';
0087     [tmp, nearest{2}(k)] = max(dots);
0088 end
0089 
0090 stcs{1}.data = stcs{1}.data(nearest{1},:);
0091 stcs{2}.data = stcs{2}.data(nearest{2},:);
0092 stcs{1}.vertices = nearest{1}-1;
0093 stcs{2}.vertices = nearest{2}-1;
0094 
0095 fprintf(1, '\n');

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005