Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRI image to mesh (based on fsaverage?) #27

Open
mdovgialo opened this issue Aug 1, 2024 · 7 comments · Fixed by #28
Open

MRI image to mesh (based on fsaverage?) #27

mdovgialo opened this issue Aug 1, 2024 · 7 comments · Fixed by #28
Assignees

Comments

@mdovgialo
Copy link

mdovgialo commented Aug 1, 2024

Use FSSurface with parcelation to create material segmentation of FSAverage scan to white matter, grey matter, CSF, skull, skin, air

FSaverage has brain segmentation, but it seems skin and skull surfaces are only available as .surf files. Faces were scrambled, there is also no cavities.

.surf files can be read by MNE and converted to .obj. Pyvista can read .obj and has filters to select points which are inside of the surface.

Image

create scripts to convert such segmented MRI into a mesh made out of cubes with properly assigned materials, and try to simulate something?

Try to create a cube mesh using the 4 spheres sampled materials, and compare 4 spheres conforming mesh and the cube mesh solutions?

Additional information and tools to segment MRI scans into tissues:

https://link.springer.com/article/10.1007/s12021-020-09504-5#rightslink

https://github.com/gtaberna/mrtim/wiki

TODO:
Add far boundary mesh option

@mdovgialo mdovgialo linked a pull request Aug 5, 2024 that will close this issue
@mdovgialo
Copy link
Author

First try of decomposing the FSAVERAGE into materials:
image

@mdovgialo
Copy link
Author

Made a first prototype of converting MRI to a 3D mesh with appropriate format conversions of materials and boundary elements grounding plate definition. Untested yet.

image

Some hacks still to be fixed, also MFEM complains about

Elements with wrong orientation: 16777216 / 16777216 (NOT FIXED)

Not sure what it's about, need to see how it will simulate...

@mdovgialo
Copy link
Author

Fixed elements with wrong orientation by first resampling MRI segmentation to RAS instead of weird skewed/inverted thing

First results of forward modeling! First try on lower resolution with 2mm voxels (around 2 million cubes), 1 mm is 16 million...

Head in air with ground plate:

Image

Volume colors - materials
Boundary - yellow grounding plate, green just a border

GT:

Image

Simulated potential:

Image

Higher contrast:

Image

Seems to be working?

@mdovgialo
Copy link
Author

Comparison of kCSD vs kESI

Solution parameters

grid step: 5 mm
R_init: 12 mm

1 mm mesh used to simulate potential to electrodes, fsaverage
Electrodes 3 layers of 10-05

image

brain mask (nodes to place sources at)

image

ground truth

image

forward solved potential

image

kCSD solution

image

kESI solution using 2mm mesh corrections

image

difference between kCSD and kESI

image

Conclusion

kESI and kCSD solutions are remarkably similar, differences are on the order of 0.001%!!!! Maybe worth trying computing a higher resolution solution?

@mdovgialo
Copy link
Author

test of high and low resolution, with brain mask and without

high resolution brain mask

image

low resolution brain mask

image

GT CSD!!!

Colors changed for easier readability when showing CSD solution and GT

image

High resolution With brain mask

solution grid step: 1mm
solution basis source radius: 1.2 mm

lambda chosen by CV

kESI

image

kCSD

image

kCSD-kESI

image

ZERO!!! WHAT???

High resolution without brain mask

solution grid step: 1mm
solution basis source radius: 1.2 mm

lambda chosen by CV

kESI

image

kCSD

image

kCSD - kESI

image

ZERO!!! WHAT???

low resolution without brain mask

solution grid step: 5mm
solution basis source radius: 12 mm

lambda chosen by CV

kESI

image

kCSD

image

kCSD - kESI

image

Very low differences!

low resolution with brain mask

solution grid step: 5mm
solution basis source radius: 12 mm

lambda chosen by CV

kESI

image

kCSD

image

kCSD - kESI

image

Very low differences!

@mdovgialo
Copy link
Author

The differences between kESI and kCSD are minimal!

Maybe something is wrong with corrections? How corrections are used? Maybe they need normalisation?

@mdovgialo
Copy link
Author

mdovgialo commented Sep 3, 2024

Just in case looking at electrode corrections.

Theoretical Potential (no FEM)

Theoretical potential of a point current source at electrode position, with sigma=0.33, without FEM mesh influence

image

image

FEM potential

Potential of a point current source at electrode position, calculated over 2mm mesh with realistic materials

image

image

Image

FEM correction for kESI

FEM potential minus theoretical

image

image

Image

@mdovgialo mdovgialo self-assigned this Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant