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

Integration of brain2mesh with brainstorm #10

Open
ftadel opened this issue Feb 17, 2020 · 6 comments
Open

Integration of brain2mesh with brainstorm #10

ftadel opened this issue Feb 17, 2020 · 6 comments

Comments

@ftadel
Copy link

@ftadel ftadel commented Feb 17, 2020

@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 added a commit that referenced this issue Feb 17, 2020
@fangq

This comment has been minimized.

Copy link
Owner

@fangq fangq commented Feb 17, 2020

  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
de9d22e

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

This comment has been minimized.

Copy link
Author

@ftadel ftadel commented Feb 19, 2020

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:

  • Practical: This function is not usable by itself starting from what users have, which is .nii files
  • Educational: Most people are not familiar with multiple environments (if their lab use SPM they may not know how to use FSL)
  • Cross-validation: having some documentation that shows how to run somewhat similar operations with different environments would be very useful
  • Reproducibility: to replicate the results in your article, making sure everybody uses the same parameters (eg. different updates of SPM12 may use different default values)
  • Improvements: if people start using brain2mesh with some default segmentation scripts, they could then refine them with tuning some of the input parameters that would work better with brain2mesh, and contribute these improvements to your github repo
    Since you have already written these scripts, it would not be too much added work, would it? :)

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

This comment has been minimized.

Copy link
Owner

@fangq fangq commented Feb 19, 2020

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

This comment has been minimized.

Copy link
Author

@ftadel ftadel commented Feb 19, 2020

Done for SPM12: brainstorm-tools/brainstorm3@33d708d#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 ftadel closed this Feb 19, 2020
@ftadel ftadel reopened this Feb 19, 2020
@ftadel

This comment has been minimized.

Copy link
Author

@ftadel ftadel commented Feb 19, 2020

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

This comment has been minimized.

Copy link
Owner

@fangq fangq commented Feb 20, 2020

@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 added a commit to fangq/brainstorm3 that referenced this issue Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.