Neuroinflab / kESI

GNU General Public License v3.0
2 stars 5 forks source link

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

Open mdovgialo opened 3 months ago

mdovgialo commented 3 months ago

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 commented 3 months ago

First try of decomposing the FSAVERAGE into materials: image

mdovgialo commented 3 months ago

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 commented 3 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

The differences between kESI and kCSD are minimal!

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

mdovgialo commented 2 months ago

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