You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: Use something other than FreeSurfer for BEM extraction #7232
I am working with a EEG dataset and I wish to run source on that. Unfortunately the T1w are not FLASH and I know that in the absence of FLASH images, MNE offers a somewhat less accurate
solution based on the watershed algorithm (see Jas et al., 2018).
Indeed for some subjects in my dataset (see attached 1) I got the following error when I am going to run make_bem_model.
RuntimeError: Surface inner skull is not completely inside surface outer skull
For other subject instead the surfaces are simply wrong (see attached 2), even though make_bem_model hadn't give me any error
I was wondering whether if you have some tips on how to fix them.
@Davi1990 it's better to report these in the mailing list. Unless you are sure it's a bug, I recommend asking there. You can also search the archives and find that similar issues were already answered:
Thanks for your reply. Unfortunately I already saw the question that you posted.
I have done some work on the surfaces trying to get the best result possible.
This looks reasonable to me but I would like to listen your opinion on that. I don't understand why the surfaces are not registered with the main T1w though.
Moreover, when I am reconstructing the bem model in MNE I got the following error:
"Cannot decimate to requested ico grade 4. The provided BEM surface has 78784 triangles, which cannot be isomorphic with a subdivided icosahedron. Consider manually decimating the surface to a suitable density and then use ico=None in make_bem_model"
Maybe the meshes have too many triangles so I need to down sample the vertices to below 10000....
This looks reasonable to me but I would like to listen your opinion on that. I don't understand why the surfaces are not registered with the main T1w though.
How did you make this plot? If you aren't using mne.viz.plot_bem or freeview in Freesurfer, it's likely that the plotting is wrong because of MRI surface RAS coordinates versus standard RAS/affine that other software might use.
Your surfaces in the first post are properly coregistered. How are they different from the ones in your more recent post? Differences in processing these surfaces probably gave rise to the alignment mismatch.
For ideas on how to fix meshes, the ideas we have were recently consolidated here:
I have worked in putting down a script that use different tools and in the end the surfaces right now are nicely coregistered with the T1w (see attached). Even though the outer skin is going a little bit outside but it should not be a big deal.
Anyway now I was trying to import them in MNE reconstructing the bem model in MNE I got the same error than before:
"Cannot decimate to requested ico grade 4. The provided BEM surface has 78784 triangles, which cannot be isomorphic with a subdivided icosahedron. Consider manually decimating the surface to a suitable density and then use ico=None in make_bem_model"
@larsoner I saw your suggestions but I wasn't able to find a solution and any other idea would be highly appreciated
Regarding the number of vertices, #7259 will probably / hopefully have some solutions for suitable decimation
In particular this comment has some code you could use to decimate your surface. Soon it will be adapted to mne.decimate_surface because it seems to be a necessary use case.
@christian-oreilly this issue makes me think that we might want to make the BEM mesh extraction we discussed more publicly available. If it takes hours then just some description in our FAQ would be good. If it takes about a minute then we should turn it into an example.
Would you be able to make a PR for this? If you don't have time but have a notebook / some code to share with the marching cubes plus smoothing approach, I can see if either of these of these documentation ideas make sense
@larsoner You mean to document the cube marching + laplacian smoothing + decimation approach and the FS tessellation approach? I should be able at least to provide an initial PR. What often ends up taking longer for me is debugging the CI stuff and editing to adjust for project specific standards on naming and format that I am not familiar with. I will be happy to provide the PR, but will be happy to have a bit of help to push it through if it drags on these latter topics. Hopefully, these things will get smoother as I gain a bit of experience with contributing code to MNE...
@larsoner yes I saw your comment above. I've run mne.decimate_surface so that the new surfaces have the same number of faces and vertices of the original. However I still get the same error.
Moreover if I run the make_bem_model command with ico=None I got the following error instead:
@christian-oreilly any chance to make a WIP PR with the Python solution for creating BEM surfaces? I'm happy to take over once there is something that more or less works.
changed the title [-]Inconsistent surfaces extracted using watershed[/-][+]ENH: Use something other than FreeSurfer for BEM extraction[/+]on Jan 7, 2021
@Davi1990 in your image above how did you get those three surfaces? From @christian-oreilly's code it's clear that we can go from a binarized/labeled MRI to usable suitably smooth surfaces, but he started from MRI data that was already labeled with each compartment. I'm curious how you got your compartment definitions and (of secondary importance) then turned them into surfaces.
Some exploration so far -- I've had decent luck with FieldTrip + SPM (worked on 157/158 subjects), but this requires MATLAB so it's a bit of a no-go.
I then tried brainsuite and fsl using this gist. brainsuite skullfinder is very fast (1-2 sec) but produces a questionable output, whereas fsl seems to work well in about a minute of run-time.
FieldTrip + SPM could not process this subject because it couldn't determine the orientation (the head is tilted about the Z axis is probably the issue?).
Overall I think I like the idea of adding a mne fsl_bem function that uses fsl to generate BEM surfaces. It already puts out ones that are smoothed and 5120 triangles, writes to a standard format (vtk) that can by read by pyvista, etc. It even makes sure that the meshes don't intersect:
the mesh is self-intersecting
thus will rerun with higher smoothness constraint
Activity
jasmainak commentedon Jan 21, 2020
@Davi1990 it's better to report these in the mailing list. Unless you are sure it's a bug, I recommend asking there. You can also search the archives and find that similar issues were already answered:
https://mail.nmr.mgh.harvard.edu/pipermail//mne_analysis/2019-April/005805.html
https://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/2019-November/006317.html
hope that helps
Davi1990 commentedon Jan 21, 2020
Hi @jasmainak!! I posted few weeks ago but I haven't received any reply message. I am going to ask again right now. I am deadlocked!
Hope to receive some helps this time
Dave
Davi1990 commentedon Jan 28, 2020
Hi @jasmainak!!
Thanks for your reply. Unfortunately I already saw the question that you posted.
I have done some work on the surfaces trying to get the best result possible.
This looks reasonable to me but I would like to listen your opinion on that. I don't understand why the surfaces are not registered with the main T1w though.
Moreover, when I am reconstructing the bem model in MNE I got the following error:
"Cannot decimate to requested ico grade 4. The provided BEM surface has 78784 triangles, which cannot be isomorphic with a subdivided icosahedron. Consider manually decimating the surface to a suitable density and then use ico=None in make_bem_model"
Maybe the meshes have too many triangles so I need to down sample the vertices to below 10000....
Any tips would be highly appreciate
Thanks
larsoner commentedon Jan 28, 2020
How did you make this plot? If you aren't using
mne.viz.plot_bemorfreeviewin Freesurfer, it's likely that the plotting is wrong because of MRI surface RAS coordinates versus standard RAS/affine that other software might use.larsoner commentedon Jan 28, 2020
Regarding the number of vertices, #7259 will probably / hopefully have some solutions for suitable decimation
Davi1990 commentedon Jan 28, 2020
@larsoner thanks for your suggestions. As for the number of vertices I am gonna try this once I have all the surfaces registered and I'll let you know
As for the visualization, I've used freeview
larsoner commentedon Jan 28, 2020
Your surfaces in the first post are properly coregistered. How are they different from the ones in your more recent post? Differences in processing these surfaces probably gave rise to the alignment mismatch.
For ideas on how to fix meshes, the ideas we have were recently consolidated here:
https://mne.tools/dev/overview/faq.html#my-watershed-bem-meshes-look-incorrect
Davi1990 commentedon Jan 29, 2020
I have worked in putting down a script that use different tools and in the end the surfaces right now are nicely coregistered with the T1w (see attached). Even though the outer skin is going a little bit outside but it should not be a big deal.
Anyway now I was trying to import them in MNE reconstructing the bem model in MNE I got the same error than before:
"Cannot decimate to requested ico grade 4. The provided BEM surface has 78784 triangles, which cannot be isomorphic with a subdivided icosahedron. Consider manually decimating the surface to a suitable density and then use ico=None in make_bem_model"
@larsoner I saw your suggestions but I wasn't able to find a solution and any other idea would be highly appreciated
Thanks
larsoner commentedon Jan 29, 2020
Did you see this above?
In particular this comment has some code you could use to decimate your surface. Soon it will be adapted to
mne.decimate_surfacebecause it seems to be a necessary use case.larsoner commentedon Jan 30, 2020
@christian-oreilly this issue makes me think that we might want to make the BEM mesh extraction we discussed more publicly available. If it takes hours then just some description in our FAQ would be good. If it takes about a minute then we should turn it into an example.
Would you be able to make a PR for this? If you don't have time but have a notebook / some code to share with the marching cubes plus smoothing approach, I can see if either of these of these documentation ideas make sense
christian-oreilly commentedon Jan 30, 2020
@larsoner You mean to document the cube marching + laplacian smoothing + decimation approach and the FS tessellation approach? I should be able at least to provide an initial PR. What often ends up taking longer for me is debugging the CI stuff and editing to adjust for project specific standards on naming and format that I am not familiar with. I will be happy to provide the PR, but will be happy to have a bit of help to push it through if it drags on these latter topics. Hopefully, these things will get smoother as I gain a bit of experience with contributing code to MNE...
larsoner commentedon Jan 30, 2020
Sounds good, I can help with the pedantic parts
Davi1990 commentedon Jan 30, 2020
@larsoner yes I saw your comment above. I've run
mne.decimate_surfaceso that the new surfaces have the same number of faces and vertices of the original. However I still get the same error.Moreover if I run the
make_bem_modelcommand with ico=None I got the following error instead:Sorry but this issue is keeping me stuck
jasmainak commentedon Jan 30, 2020
@Davi1990 you have to play around with the Freesurfer commands until you get better surfaces. Alternatively you can also edit the surfaces manually. There are demos online: https://www.youtube.com/watch?v=AR83_Bt04VQ
larsoner commentedon Apr 7, 2020
@christian-oreilly any chance to make a WIP PR with the Python solution for creating BEM surfaces? I'm happy to take over once there is something that more or less works.
11 remaining items
[-]Inconsistent surfaces extracted using watershed[/-][+]ENH: Use something other than FreeSurfer for BEM extraction[/+]larsoner commentedon Jan 11, 2021
@Davi1990 in your image above how did you get those three surfaces? From @christian-oreilly's code it's clear that we can go from a binarized/labeled MRI to usable suitably smooth surfaces, but he started from MRI data that was already labeled with each compartment. I'm curious how you got your compartment definitions and (of secondary importance) then turned them into surfaces.
larsoner commentedon Feb 3, 2021
Some exploration so far -- I've had decent luck with FieldTrip + SPM (worked on 157/158 subjects), but this requires MATLAB so it's a bit of a no-go.
I then tried brainsuite and fsl using this gist. brainsuite
skullfinderis very fast (1-2 sec) but produces a questionable output, whereas fsl seems to work well in about a minute of run-time.Subject 1
brainsuite
skullfinder:fsl
bet:FieldTrip + SPM could not process this subject because it couldn't determine the orientation (the head is tilted about the Z axis is probably the issue?).
Subject 2
brainsuite:
fsl:
FieldTrip + SPM + Python mesh code to marching_cubes + smooth + decimate:
Overall I think I like the idea of adding a
mne fsl_bemfunction that usesfslto generate BEM surfaces. It already puts out ones that are smoothed and 5120 triangles, writes to a standard format (vtk) that can by read by pyvista, etc. It even makes sure that the meshes don't intersect:hoechenberger commentedon Feb 4, 2021
Amazing work, @larsoner!! Would very much love to see this added to MNE