fangq / brain2mesh

Brain2Mesh - a one-liner for high-quality brain mesh generation
http://mcx.space/brain2mesh
Other
34 stars 14 forks source link

Integration of brain2mesh with brainstorm #10

Closed ftadel closed 2 years ago

ftadel commented 4 years ago

@fangq Following your suggestion, I'm checking how we could interface brain2mesh and brainstorm.

First few questions: 1) Could you share the SPM12 scripts you used in your article for generating the segmentation needed by brain2mesh? 2) Brain2mesh.m: if v2m is missing you ask for downloading brain2mesh, but you should ask for downloading iso2mesh 3) imfill/imdilate: Lots of people do not have access to the Image Processing toolbox (outside of North American universities), it would be good to provide alternatives. The Matlab functions imfill and imdilate are probably much more generic than the basic b/w morphological operations you need there. We try to have everything in Brainstorm working without any extra toolbox, for these ones I recoded only what I needed: mri_dilate.m, mri_fillholes.m

@tmedani @juangpc If you have solutions for this, feel free to share.

fangq commented 4 years ago
  1. Could you share the SPM12 scripts you used in your article for generating the segmentation needed by brain2mesh?

We used the SPM GUI for segmenting the brains, nothing special. here are a couple of slides used in our training workshop back in 2017

spm_seg_with_brain2mesh.pdf

Again, brain2mesh is not a segmentation tool, but a mesh generator processing pre-generated segmentations, so whatever best pipeline/parameters people use SPM or other segmentation tools, brain2mesh is expected to work with the output without any issue.

  1. Brain2mesh.m: if v2m is missing you ask for downloading brain2mesh, but you should ask for downloading iso2mesh

agreed and fixed https://github.com/fangq/brain2mesh/commit/de9d22edb782a60a9cabaaa8137de53679db5527

imfill/imdilate: Lots of people do not have access to the Image Processing toolbox (outside of North American universities), it would be good to provide alternatives. The Matlab functions imfill and imdilate are probably much more generic than the basic b/w morphological operations you need there. We try to have everything in Brainstorm working without any extra toolbox, for these ones I recoded only what I needed: mri_dilate.m, mri_fillholes.m

agreed again. replacing these dependencies is helpful for portability. In iso2mesh, I had implemented something like thinbinvol.m and thickenbinvol.m for similar purposes, but those only work for binary images (for replacing bwmorph). I do need something fast because I call those multiple times.

For my purposes, I bet convn() is enough for replacing imdilate, but I just did a quick comparison between convn(A, ones(3,3,3)) and imdilate(A, ones(3,3,3)), but I could not understand the difference. let me take a further look.

For imfill, I will do some test for the function you cited, with a quick look, I am not sure if it is capable of detecting holes.

ftadel commented 4 years ago

We used the SPM GUI for segmenting the brains, nothing special. here are a couple of slides used in our training workshop back in 2017

Thanks! It could be very useful to include your segmentation scripts with the different environments in the brain2mesh documentation (or even code base) for various reasons:

For imfill, I will do some test for the function you cited, with a quick look, I am not sure if it is capable of detecting holes.

This function mri_fillholes.m does not detect holes in the same way as imfill, indeed. Along one of the three axes of the volume, it fills the "0" voxels that have at least one "1" voxel on each side along the same line of voxels. I wrote this to put a cap on the cavities that are connected with the background on the head surface (ear canals, nostrils, weird things where the head or neck is cut).

fangq commented 4 years ago

It could be very useful to include your segmentation scripts with the different environments in the brain2mesh documentation (or even code base) for various reasons:

we have the script to load SPM segmentations

https://github.com/fangq/brain2mesh/blob/master/examples/SPM_example_brain.m#L10-L25

(loadjnifti can load .nii files as well - iso2mesh has my jnifti toolbox built-in)

but if you need scripts to convert T1/T2 .nii files to SPM12 segmentation .nii files, we need the scripts from SPM, happy to look into it, I can also ask @gllmflndn for help.

ftadel commented 4 years ago

Done for SPM12: https://github.com/brainstorm-tools/brainstorm3/commit/33d708dc8640f62a87ea35851bcd770a6092bd13#diff-7c3a114ee98415cadd8af55c3c3b262eR438

For the proof of concept, I have uploaded a temporary release of brain2mesh on our server: https://neuroimage.usc.edu/bst/getupdate.php?d=brain2mesh_alpha.zip Let us know when you are ready to release a first version of brain2mesh, so I can update the download link.

All you need is to import a T1 (and T2) to the Brainstorm database, select the images and right-click > Generate FEM mesh > Brain2Mesh. It just requires to have set up SPM12 on the computer first.

image image

ftadel commented 4 years ago

Second part: debugging brain2mesh.

It returns an empty list of elements with the SPM12 segmentation I obtained: https://www.dropbox.com/s/q5pn54e06603ddv/seg_m46wap.mat?dl=0

fangq commented 4 years ago

@ftadel, the reason brain2mesh returned an empty list was because your seg inputs were not normalized between 0-1. brain2mesh assumes the seg.{wm,gm,csf,scalp,skull} are probability maps between 0-1.

you can fix this by running

seg=structfun(@(x) double(x)*(1./255), seg,'UniformOutput',false);

before passing to brain2mesh. After this conversion, I was able to get a mesh after about 2 min processing time. The mesh does look elongated along y-axis though. There is also noise at the bottom slices that can be removed by either a threshold or using a more aggressive truncation, see dotruncate in brain2mesh.m

https://github.com/fangq/brain2mesh/blob/v0.5/brain2mesh.m#L229-L236

Screenshot_2020-02-20_00-09-55

fangq commented 2 years ago

looks like this is completed. closing now