rordenlab / niimath

niimath - a clone of fslmaths. Try the live demo:
https://niivue.github.io/niivue-niimath/
Other
53 stars 15 forks source link

Niimath usage for creating ventricle distancemap #22

Closed dilekozkan closed 10 months ago

dilekozkan commented 2 years ago

Hello, I generated a binary ventricle mask from T1 image. I need to create a distance map from the ventricles using FSL distancemap, it is too slow as you said. Can I use 'niimath vetnriclemask.nii.gz -edt dxInVM’ for this aim? Is my command true? (Otherwise; niimath vetnriclemask.niig.z -binv -edt dxFromVM mybinary ventricle mask : ventricles:1 the remaining area:0 FSLdistance map output’s definition is = where the intensity of each voxel represent its distance in mm from the ventricles mask

Best

ofgulban commented 1 year ago

Hi @dilekozkan ,

I happen to see this issue, and although I do not use FSL distancemap or its niimath equivalent, I happen to have distance computation program (see LayNii package LN2_GEODISTANCE program).

For instance, just to quickly test, I have grabbed a WM segmentation and computed distances to form the WM to the rest of the image. My image was a 512x512x512 voxels 0.5mm whole brain image. Here are the commands I have used (also attaching my file wm.nii.gz ):

niimath wm.nii.gz -binv -dilF wm_inv.nii.g

LN2_GEODISTANCE -init wm.nii.gz -domain wm_inv.nii.gz -output wm_distances.nii.gz

Picture below shows the distances and the wm and wm_inv images. This wm binary image should be similar to your ventricle binary mask. Screenshot_2023-04-21_14-39-20

Computation took ~4 minutes on 4 years old PC with a decent CPU. Distances are computed in the every voxel within the red areas (geodesically, not euclidean distances). I am not sure what is the size of your data or specifics of your hardware, but maybe this can help in some way.

NOTE: @neurolabusc , very cool extension of fslmaths. I am using niimath more and more, especially because it is so easy to install on different machines. Kudos.

neurolabusc commented 1 year ago

@ofgulban since we both use BSD licenses, you are free to adapt my euclidean distance transform nifti_edt() to your LN2_GEODISTANCE. Alternatively, afni_edt() will give identical results. It is unintuitive that this process is separable, . It is elegantly described here. Feel free to pick and copy niimath functions or just add it as a dependency. I do know that future versions of FSL are adopting this algorithm.

ofgulban commented 1 year ago

Cool, thanks for the pointers @neurolabusc :) !