Make leadfields using different headmodels

Introduction

These scripts demonstrate how to compute and compare the different MEG headmodels that are available in FieldTrip.

For all functions used, you can type 'help function' in MATLAB for more information.

The MEG dataset that is used in this demo is available from ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/tutorial/ and is named Subject01.zip.

If you download this data into a folder named 'testdata' the directory should look like this:

>> cd testdata
>> ls
Subject01.ds   Subject01.mri    Subject01.shape_info
Subject01.hdm  Subject01.shape  

Single sphere model from CTF

%--------------------------------------------------------------------------------------
%making a leadfield using the singleSphere headmodel that is 
%produced with CTF software
%--------------------------------------------------------------------------------------
 
%read in the single sphere models produced with ctf software
%irene_wyy@hotmail.com updated this page on 7.21.2013
ctf_ss = ft_read_vol('Subject01.hdm');
vol = ctf_ss;
 
%read header
hdr = ft_read_header('Subject01.ds');
grad                    = hdr.grad;
 
%read headshape
shape               = ft_read_headshape('Subject01.shape');
shape               = rmfield(shape,'fid'); %remove the fiducials->these are stored in MRI-voxel
 
%plotting the headmodel
ft_plot_sens(grad);
ft_plot_vol(vol,'facecolor','cortex');
ft_plot_headshape(shape);
 
%prepare the leadfield for the single sphere model.
hdr = ft_read_header('Subject01.ds');
cfg                         = [];
cfg.grad                    = hdr.grad;
cfg.vol                     = ctf_ss;
cfg.grid.resolution         = 1;
cfg.grid.unit               = 'cm';
[grid_ctf_ss]=ft_prepare_leadfield(cfg);

CTF headmodel, single sphere:

Local spheres model from CTF

%--------------------------------------------------------------------------------------
%making a leadfield using the localSpheres headmodel that is 
%produced with CTF software
%--------------------------------------------------------------------------------------
 
%read in the local spheres model produced with ctf software
ctf_ls = ft_read_vol('Subject01.ds\default.hdm');
vol = ctf_ls;
 
%read header
hdr = ft_read_header('Subject01.ds');
grad                    = hdr.grad;
 
%read headshape
shape               = ft_read_headshape('Subject01.shape');
shape               = rmfield(shape,'fid'); %remove the fiducials->these are stored in MRI-voxel
 
%plotting the headmodel
ft_plot_sens(grad);
ft_plot_vol(vol,'facecolor','cortex');
ft_plot_headshape(shape);
 
%prepare_leadfield; 
hdr = ft_read_header('Subject01.ds');
cfg                       = [];
cfg.grad                  = hdr.grad;
cfg.vol                   = ctf_ls;
cfg.grid.resolution            = 1;
[grid_ctf_ls]=ft_prepare_leadfield(cfg);

CTF headmodel, local spheres:

Local spheres model from FieldTrip, using the CTF headshape

%--------------------------------------------------------------------------------------
%making a leadfield using ft_prepare_headmodel implemented in FieldTrip 
%using the headshape produced with CTF software
%--------------------------------------------------------------------------------------
 
%ft_prepare_headmodel using localspheres (for information type 'help ft_prepare_headmodel')
hdr = ft_read_header('Subject01.ds');
grad                   = hdr.grad;
 
%read headshape
shape = ft_read_headshape('Subject01.shape');
shape = rmfield(shape,'fid');
 
%headmodel
cfg                        = [];
cfg.method                 = 'localspheres';
cfg.geom                   = shape;
cfg.grad                   = grad;
cfg.feedback               = false;
vol                        = ft_prepare_headmodel(cfg);
 
%plotting the headmodel
ft_plot_sens(grad);
ft_plot_vol(vol,'facecolor','cortex');
ft_plot_headshape(shape);
 
% prepare_leadfield for local spheres headmodel with ctf headshape
cfg                        = [];
cfg.grad                   = hdr.grad;
cfg.vol                    = vol;
cfg.grid.resolution             = 1;
[grid_ft_headshape]        = ft_prepare_leadfield(cfg);

Fieldtrip headmodel, local spheres with ctf headshape:

Local spheres model from FieldTrip, using brain surface from segmented mri

%--------------------------------------------------------------------------------------
%making a leadfield using prepare_localspheres implemented in fieldtrip 
%using a segmented mri produced with volume_segment in fieldtrip
%(see the bottom of this page for how to make a segmented mri and check it for flipped
%dimensions)
%--------------------------------------------------------------------------------------
 
%ft_prepare_localspheres (for information type 'help ft_prepare_localspheres' in matlab)
hdr = ft_read_header('Subject01.ds');
grad = hdr.grad;
 
%read mri
mri = ft_read_mri('Subject01.mri');
cfg = [];
cfg.dim = mri.dim;
mri = ft_volumereslice(cfg,mri);
 
%plot mri
cfg = [];
ft_sourceplot(cfg,mri);
 
%save mri for future use
save mri mri
 
%segmentation
cfg = [];
cfg.output = {'gray','white','csf','skull','scalp'};
segmentedmri = ft_volumesegment(cfg,mri);
save segmentedmri segmentedmri
 
%headmodel
cfg                       = [];
cfg.grad                  = hdr.grad;
cfg.feedback              = false;
cfg.method                = 'localspheres';
vol                       = ft_prepare_headmodel(cfg,segmentedmri);
 
%plotting the headmodel
ft_plot_sens(grad);
ft_plot_vol(vol,'facecolor','cortex');
 
%ft_prepare_leadfield for the local spheres headmodel produced using a segmented mri
cfg                       = [];
cfg.grad                  = hdr.grad;
cfg.vol                   = vol;
cfg.grid.resolution            = 1;
[grid_ft_segment]=ft_prepare_leadfield(cfg);

FieldTrip headmodel, local spheres based on segmented mri:

Realistic single-shell model, using brain surface from segmented mri

%--------------------------------------------------------------------------------------
%making a leadfield using ft_prepare_singleshell (developed by Nolte) implemented in FieldTrip 
%using a segmented mri produced with ft_volumesegment in FieldTrip
%(see the bottom of this page for how to make a segmented mri and check it for flipped
%dimensions)
%--------------------------------------------------------------------------------------
 
%ft_prepare_singleshell (for information type 'help ft_prepare_singleshell' in matlab)
hdr = ft_read_header('Subject01.ds');
cfg                       = [];
cfg.grad                  = hdr.grad;
ft_singleshell=ft_prepare_singleshell(cfg,segmentedmri);
 
%plotting the headmodel
figure;
hdr = ft_read_header('Subject01.ds');
cfg                       = [];
cfg.grad                  = hdr.grad;
cfg.headshape             = 'Subject01.shape';
cfg.vol                   = ft_singleshell;
ft_headmodelplot(cfg);
title('fieldtrip: headmodel by Nolte with segmented mri');
cfg=rmfield(cfg,'headshape');
figure;
ft_headmodelplot(cfg);
title('fieldtrip: headmodel by Nolte with segmented mri');
 
%ft_prepare_leadfield for the Nolte headmodel, created using FieldTrip
hdr = ft_read_header('Subject01.ds');
cfg                       = [];
cfg.grad                  = hdr.grad;
cfg.vol                   = ft_singleshell;
cfg.resolution            = 1;
[grid_singleshell]=ft_prepare_leadfield(cfg);

Single-shell headmodel, realistic geometry:

Single-shell headmodel, displayed without headshape and rotated:

Comparing the forward models

%----------------------------------------------------------------------------------------------------------
%compute the amplitudes of the leadfields 
%----------------------------------------------------------------------------------------------------------
grid = {};
grid{1} = grid_ctf_ss;
grid{2} = grid_ctf_ls;
grid{3} = grid_ft_headshape;
grid{4} = grid_ft_segment;
grid{5} = grid_singleshell;
 
ampl = {};
for i=1:5
  a = grid{i};
  ampl{i} = [];
  ampl{i}.norm = zeros(grid{i}.dim) * nan;
  for k=a.inside(:)'
    ampl{i}.norm(k) = sqrt(sum(a.leadfield{k}(:).^2));
  end
end
 
%interpolating the data to the mri for plotting
mri=ft_read_mri('Subject01.mri');
cfg                        = [];
cfg.parameter              = 'avg.pow';
source                     = grid{1};
source.dim                 = grid{1}.dim;
sourceinterp               = {};
for i=1:5
    source.avg.pow=ampl{i}.norm;
    sourceinterp{i}=ft_sourceinterpolate(cfg,source,mri);
end
 
%plotting the correlations
cfg                        = [];
cfg.funparameter           = 'avg.pow';
cfg.nslices                = 12;
cfg.colmax                 = 1;
cfg.colmin                 = 0.8;
cfg.spacemin               = 75;
cfg.spacemax               = 150;
figure;
ft_sliceinterp(cfg,sourceinterp{1});
figure;
ft_sliceinterp(cfg,sourceinterp{2});% etcetera...
%--------------------------------------------------------------------------------------------
%compute the correlations between the different leadfields
%NOTE:to be able to compare them you should recalculate the leadfields with the grid
%specifications for the single-shell model to make the leadfields of comparable sizes: 
%in the cfg for prepare_leadfield the input should contain:
%cfg.grid.xgrid = grid_singleshell.xgrid;
%cfg.grid.ygrid = grid_singleshell.ygrid;
%cfg.grid.zgrid = grid_singleshell.zgrid;
%cfg.grid.pos = grid_singleshell.pos;
%cfg.grid.inside = grid_singleshell.inside;
%cfg.grid.outside = grid_singleshell.outside;
%cfg.resolution=[];
%--------------------------------------------------------------------------------------------
comp = {};
for i=1:5
for j=(i+1):5
  disp([i j]);
  a = grid{i};
  b = grid{j};
  comp{i,j} = [];
  comp{i,j}.corrcoef = zeros(grid{5}.dim) * nan;
  for k=a.inside(:)'
    dum = corrcoef(a.leadfield{k}(:), b.leadfield{k}(:));
    comp{i,j}.corrcoef(k) = dum(1,2);
  end
end
end
 
%interpolate the data on an mri for plotting the correlations between the leadfields
mri=ft_read_mri('Subject01.mri');
cfg                 = [];
source              = grid{1};
source.dim          = grid{5}.dim;
sourceinterp        = {};
for i=1:5
  for j=(i+1):5
    source.avg.pow=comp{i,j}.corrcoef;
    sourceinterp{i,j}=ft_sourceinterpolate(cfg,source,mri);
  end
end
 
%plotting the correlations
cfg                 = [];
cfg.funparameter    = 'avg.pow';
cfg.nslices         = 12;
cfg.colmax          = 1;
cfg.colmin          = 0.8;
cfg.spacemin        = 75;
cfg.spacemax        = 150;
figure;
ft_sliceinterp(cfg,sourceinterp{1,2});
figure;
ft_sliceinterp(cfg,sourceinterp{2,3});% etcetera...

Correlations between the leadfields computed based on the FieldTrip localspheres model based on the CTF headshape and the realistic single-shell headmodel

Appendix: creating a segmentation of the mri

%-------------------------------------------------------------------------------
%make segmented mri with volumesegment
%-------------------------------------------------------------------------------
 
mri          = ft_read_mri('Subject01.mri');
cfg          = [];
cfg.name     = 'segment';
segmentedmri = ft_volumesegment(cfg, mri)
 
%check segmented volume against mri
mri.brainmask = segmentedmri.gray+segmentedmri.white+segmentedmri.csf;
 
cfg              = [];
cfg.interactive  = 'yes';
cfg.funparameter = 'brainmask';
figure;
ft_sourceplot(cfg, mri);
example/make_leadfields_using_different_headmodels.txt · Last modified: 2015/03/19 16:24 (external edit)

You are here: startexamplemake_leadfields_using_different_headmodels
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0
This DokuWiki features an Anymorphic Webdesign theme, customised by Eelke Spaak and Stephen Whitmarsh.
Mobile Analytics Website Security Test