[FieldTrip] volume conduction model missing .mat

Akiko Ikkai akiko.ikkai at gmail.com
Tue Feb 21 18:52:27 CET 2012


Hi Gio,

Thank you for sharing your script. cfg.output = 'tpm' for ft_volumesegment
seems to make a big difference, and now I could go all the way to actually
running beamformer on my data! Of course, I had to add a few things. For
example, in order to clean up segmented images, I added lines as

seg2.brain(:,:,1:4)=0;

seg2.skull(:,:,1:2)=0;

to make sure scalp, skull and brain do not intersept at neck. Also did
something like below for each tissue type (otherwise the resulting
beamformer was too small on the brain)

newsbrain = imdilate(seg2.brain,strel_bol(1));

seg2.brain = newsbrain;


Fieldtrip developers, are there documentations for "cfg.output = 'tpm' "
for segmentation? ft_segmentation help page simply says it's a default
option.

Thanks for your help! Akiko

On Thu, Feb 16, 2012 at 5:52 AM, Gio Piantoni <g.piantoni at nin.knaw.nl>wrote:

> Hi Akiko,
>
> What do you mean "problematic" exactly? From my understanding, there
> are 4 steps to get from the MRI to the forward model.
> 1. from MRI to segmentation
> 2. from segmentation to mesh (bnd)
> 3. from mesh to headmodel
> 4. from headmodel to forward model
>
> Here is the code I use. It seems to work fine, but experts might want
> to chip in and improve it.
> 1. from MRI to segmentation
>
> %-----------------%
> %-read MRI
> mrifile = '/path/to/your/mri.nii.gz';
> mri = ft_read_mri(mrifile);
> %-----------------%
>
> %-----------------%
> %-segmenting the volume, Tissue Probability Maps
> % It takes time to run 'tpm'
> cfg1 = [];
> cfg1.threshold = [];
> cfg1.output = 'tpm';
> cfg1.coordsys = 'spm';
> tpm = ft_volumesegment(cfg1, mri);
> tpm.anatomy = mri.anatomy;
> %-----------------%
>
> %-----------------%
> %-segmenting the volume
> % this is faster after tpm
> cfg1 = [];
> cfg1.threshold = 1; % 1 is default, my MRI scalps were noisy, so I had
> to make it lower.
> cfg1.output = 'scalp';
> cfg1.coordsys = 'spm';
> segscalp = ft_volumesegment(cfg1, tpm);
>
> cfg1 = [];
> cfg1.threshold = [];
> cfg1.output = {'skull' 'brain'};
> cfg1.coordsys = 'spm';
> segment = ft_volumesegment(cfg1, tpm);
> segment.scalp = segscalp.scalp;
> %-----------------%
>
> Check the output with ft_sourceplot
>
> 2. from segmentation to mesh (bnd)
>
> %-----------------%
> %-prepare mesh for skull and brain (easy)
> cfg2 = [];
> cfg2.tissue = {'skull', 'brain'};
> cfg2.numvertices = [1200 1000];
> cfg2.transform = segment.transform;
> bnd = ft_prepare_mesh_new(cfg2, segment);
> %-----------------%
>
> %-----------------%
> %-prepare mesh for scalp (we need to be more liberal with threshold,
> bc of poor quality of MRI)
> cfg2 = [];
> cfg2.tissue = {'scalp'};
> cfg2.numvertices = 2500;
> cfg2.thresholdseg = 0.1;
> cfg2.transform = segment.transform;
> scalp = ft_prepare_mesh_new(cfg2, segment);
> %-----------------%
>
> %-----------------%
> %-combine scalp and bnd
> bnd = [scalp bnd];
> ft_plot_mesh(bnd(1), 'facealpha', .5)
> hold on
> ft_plot_mesh(bnd(2), 'facecolor', 'red')
> %-----------------%
>
> If bnd is good, no intersection between meshes and the outline looks
> nice, the following should run without problems. Please, do check your
> bnd.
> Segmentation and ft_prepare_mesh_new work really well. Another
> approach to get nice meshes is to skip step 1 and 2 and use
> Freesurfer/MNE. You can read the meshes in fieldtrip
> (ft_read_headshape, I think). The meshes are in the "bem" folder of
> Freesurfer, but I don't remember off the top of my head which files
> you should read ("outer_skull, inner_skull", I think).
> These meshes have a very very high resolution, you can scale them down
> with "reducepatch" in Matlab.
>
> 3. from mesh to headmodel
> %-----------------%
> %-headmodel
> cfg3 = [];
> cfg3.method = 'bem_dipoli';
> cfg3.conductivity = [0.33 0.0042 0.33];
> vol = ft_prepare_headmodel(cfg3, bnd);
> %-----------------%
>
> You can really pick your favorite here: dipoli, openmeeg, bemcp. This
> will take time (the more time, the more points on your meshes).
>
> 4. from headmodel to forward model
> You last problem is to get electrodes and headmodel in the same space.
> The template in SPM is already in MNI space, your individual MRIs
> probably not. You can realign them to MNI space before step 1 using
> SPM or FSL.
>
> elec = ft_read_sens(sensfile);
> elec = ft_convert_units(elec, 'mm');
>
> %-------%
> %-simple transformation (based on visual realignment)
> % elecM is an affine matrix that you can get from ft_electroderealign
> % electrodes do not need to match the scalp perfectly, but they should
> be pretty close by.
> elec.chanpos = warp_apply(elecM, elec.chanpos);
> elec.elecpos = warp_apply(elecM, elec.elecpos);
> %-------%
>
> [vol, elec] = ft_prepare_vol_sens(vol, elec);
> % now you should check that the electrodes are on the scalp.
> %-----------------%
>
> %-----------------%
> %-prepare leadfield
> cfg4 = [];
> cfg4.elec = elec;
> cfg4.vol = vol;
> cfg4.grid.xgrid = -70:10:70;
> cfg4.grid.ygrid = -110:10:80;
> cfg4.grid.zgrid = -60:10:90;
> cfg4.inwardshift = 1; % to avoid dipoles on the border of bnd(3),
> which are very instable
> cfg4.grid.tight = 'no';
> cfg4.feedback = 'none';
> lead = ft_prepare_leadfield(cfg4, []);
> % use ft_plot_topo3d and ft_plot_dipole to check whether the
> projection of your dipole onto the scalp makes sense.
> %-----------------%
>
> "lead" should be your subject-specific, electrode-specific leadfield.
> There are quite a few parameters that you can change, but a clean
> segmentation and non-intersecting, smooth and realistic-looking meshes
> are a must.
> Then, using dipoli, openmeeg or bemcp should not change your forward
> model too much.
> Sorry if some points are not clear, but you should really look at your
> MRI/segmentation/meshes/electrodes/forward model as much as possible.
>
> Hope this will get you started. I appreciate any feedback on improving
> the code, this is just my personal attempt.
>
> Cheers
>
> Gio
>
> On Wed, Feb 15, 2012 at 17:45, Akiko Ikkai <akiko.ikkai at gmail.com> wrote:
> > Dear Fieldtrip users,
> >
> > Thank you Patrick, Nathan & Gio for your inputs. My MRI anatomical images
> > need extensive cleaning (enhance contrasts, get rid of non-zero voxels
> > outside the brain, etc...) before segmentation, as well as adjusting
> > cfg.threshold for each tissue type during segmentation and each subject.
> At
> > least testing with SPM standard MRI, segmentation and forward modeling
> works
> > OK now.
> >
> > Individual subject's MRI, though, is still problematic, and I have a
> > question for Fieldtrip developers: could you let me know whether "Create
> BEM
> > headmodel for EEG (
> >  http://fieldtrip.fcdonders.nl/example/create_bem_headmodel_for_eeg )"
> > routine is what you recommend, or it's integrated into a newer function
> with
> > newer cfg options? Is there a page I missed on the web?
> >
> > Thank you so much for your time!
> > Akiko
> >
> > On Fri, Feb 10, 2012 at 4:36 AM, Gio Piantoni <g.piantoni at nin.knaw.nl>
> > wrote:
> >>
> >> Hi Akiki and Patrick,
> >>
> >> I agree with Nathan about segmentation problems. I had the same
> >> problem when two of the three meshes intersected each other. Before
> >> you run the forward model, you should check the segmentation (bnd)
> >> using ft_plot_mesh.
> >> ft_plot_mesh(bnd(1), 'facealpha', .5)
> >> hold on
> >> ft_plot_mesh(bnd(2), 'facecolor', 'r')
> >> You will see that the two meshes intersect with each other. Depending
> >> on how you created the meshes, you should fix the parameters in such a
> >> way that they don't intersect. For example, ft_volumesegment has a
> >> cfg.threshold option (you can check how the segmentation went with
> >> ft_sourceplot) and ft_prepare_mesh_new has cfg.thresholdseg and
> >> cfg.smoothseg.
> >>
> >> I think that the meshes in SPM are computed on an (affine-transformed)
> >> template and not on the anatomically derived meshes. The template is
> >> more robust and that's why the two surfaces do not intersect.
> >>
> >> In general, the segmentation depends on the quality of your MRIs and
> >> you should really visually check the segmentation and meshes. When
> >> those look ok, the BEM forward model usually works. Hope this helps.
> >>
> >> Cheers,
> >>
> >> Gio
> >>
> >> On Fri, Feb 10, 2012 at 09:00, Nathan Weisz <nathanweisz at mac.com>
> wrote:
> >> > Hi Akiki,
> >> >
> >> > I am not a headmodel expert.
> >> > but looking at the output message, it seems your segementation did not
> >> > go
> >> > too well (see the "intersect" message). my intuition is then then the
> >> > next
> >> > temporary file *.ama is not created and ft_prepare_bemmodel then
> simply
> >> > says
> >> > ciao.
> >> >
> >> > perhaps you want to check / redo the segmentation?
> >> >
> >> > good luck,
> >> > nathan
> >> >
> >> >
> >> > On 09.02.2012, at 23:04, Akiko Ikkai wrote:
> >> >
> >> > Hi,
> >> >
> >> > I'm trying to create a volume conduction model for my EEG study based
> on
> >> > anatomical MRI, and having trouble with ft_prepare_bemmodel
> >> >
> >> > when I run
> >> > cfg                = [];
> >> > cfg.tissue         = [7 4 1]; % value for brain, skull, and scalp
> >> > cfg.conductivity   = [1 1/80 1]*.33; % after standard_BEM.zip data
> >> > cfg.isolatedsource = true;
> >> > cfg.method         = 'dipoli';
> >> > cfg.sourceunits = 'mm';
> >> > cfg.mriunits = 'mm';
> >> > vol = ft_prepare_bemmodel(cfg, seg4bem);
> >> >
> >> > I get the following error message while ft_prepare_bemmodel is
> running:
> >> >
> >> > Fatal error in dipoli:  interface
> >> > /private/tmp/tpd8a04422_e19e_4978_9b9b_56d1f2696492.tri and
> >> > /private/tmp/tp313c9a32_1991_4df6_a404_8efc41b6302e.tri intersect
> >> >  at vertex 1402 of
> >> > /private/tmp/tpd8a04422_e19e_4978_9b9b_56d1f2696492.tri
> >> >
> >> > Warning: an error ocurred while running dipoli
> >> >> In dipoli at 94
> >> >   In ft_prepare_bemmodel at 112
> >> > Error using ==> fread
> >> > Invalid file identifier.  Use fopen to generate a valid file
> identifier.
> >> > Warning: File
> '/private/tmp/tp0c0779e3_a657_4ca5_b9e1_845f41e9574a.ama'
> >> > not
> >> > found.
> >> >> In dipoli at 102
> >> >   In ft_prepare_bemmodel at 112
> >> >
> >> >
> >> > and the output vol is missing .mat, which causes an error
> >> > during ft_sourceanalysis.
> >> >>> vol
> >> > vol =
> >> >             cond: [0.3300 0.0041 0.3300]
> >> >              bnd: [1x3 struct]
> >> >           source: 3
> >> >     skin_surface: 3
> >> >             skin: 1
> >> >             type: 'dipoli'
> >> >
> >> > Does anyone know how to correct for "fatal error" so
> >> > that ft_prepare_bemmodel creates the correct volume conduction model?
> I
> >> > opened .tri file and removed line 1402, but got the same results.
> >> >
> >> > Thanks in advance! Akiko
> >> >
> >> > --
> >> > Akiko Ikkai, Ph.D.
> >> > Postdoctoral Fellow
> >> > Department of Psychological and Brain Sciences
> >> > Johns Hopkins University
> >> > Ames Hall, 3400 N. Charles St.
> >> > Baltimore, MD 21218
> >> >
> >> >
> >> > _______________________________________________
> >> > fieldtrip mailing list
> >> > fieldtrip at donders.ru.nl
> >> > http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
> >> >
> >> >
> >> >
> >> > _______________________________________________
> >> > fieldtrip mailing list
> >> > fieldtrip at donders.ru.nl
> >> > http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
> >>
> >> _______________________________________________
> >> fieldtrip mailing list
> >> fieldtrip at donders.ru.nl
> >> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
> >
> >
> >
> >
> > --
> > Akiko Ikkai, Ph.D.
> > Postdoctoral Fellow
> > Department of Psychological and Brain Sciences
> > Johns Hopkins University
> > Ames Hall, 3400 N. Charles St.
> > Baltimore, MD 21218
> >
> >
> >
> > _______________________________________________
> > fieldtrip mailing list
> > fieldtrip at donders.ru.nl
> > http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>



-- 
Akiko Ikkai, Ph.D.
Postdoctoral Fellow
Department of Psychological and Brain Sciences
Johns Hopkins University
Ames Hall, 3400 N. Charles St.
Baltimore, MD 21218
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20120221/e68fa851/attachment-0002.html>


More information about the fieldtrip mailing list