ANTsX / ANTs

Advanced Normalization Tools (ANTs)
Apache License 2.0
1.21k stars 381 forks source link

Can't extract brain from skull on T1-weighed MRI images #1724

Closed ValeriePineauNoel closed 6 months ago

ValeriePineauNoel commented 6 months ago

Describe the problem I have a T1-weighed image sequence from a human head and I want to extract, on each image, the brain and get rid of the skull for registration. I tried this tutorial (Brain extraction in ANTs) with the Kirby brain template provided here (ANTs brain templates). I had an ERROR: command exited with nonzero status 139. From the console, I can see that the error is from the command antsApplyTransforms (0x10f91f6a5 int ants::antsApplyTransforms<double, 3u, double>(itk::SmartPointer&, unsigned int) + 7909), I'm guessing from the file antsBrainExtraction.sh.

To Reproduce I basically followed this : ANTs brain templates However, instead of putting this command

antsBrainExtraction.sh -d 3 -a t1.nii.gz -e T_template0.nii.gz \
-m T_template0_BrainCerebellumProbabilityMask.nii.gz -o output

I put this :

antsBrainExtraction.sh -d 3 -a Ax_3D_postt1_Mprage_8.nrrd -e <path>/Kirby/S_template3.nii.gz -o T1_brain_without_skull.nii.gz

System information (please complete the following information)

ANTs version information

Additional information

ntustison commented 6 months ago

At minimum, please post the entire error output. Even better, though, would be to post the data so that we can try to reproduce the error on our end.

Alternatively, I would recommend using ANTsPy/ANTsPyNet or ANTsR/ANTsRNet (brain extraction tutorial here.

cookpa commented 6 months ago

Yes I would need to see more context from the complete logs. They are often too long to paste but you can do

antsBrainExtraction.sh -d 3 -a Ax_3D_postt1_Mprage_8.nrrd -e <path>/Kirby/S_template3.nii.gz \
  -o T1_brain_without_skull.nii.gz 2>&1 | tee abe_command_output.txt

and then upload the text file here.

ValeriePineauNoel commented 6 months ago

Hi! Thanks for your quick answers. Indeed I didn't put the logs because it was quite long. Here is the command_output.txt : abe_command_output.txt

Sadly, because I am working with human brain scans, I cannot share my data for ethical reasons. However, I can tell you that my image sequence looks like this, but with a skull : CIT MRI brain.

cookpa commented 6 months ago

Thanks! Can you try

antsBrainExtraction.sh -d 3 -a Ax_3D_postt1_Mprage_8.nrrd -e <path>/Kirby/S_template3.nii.gz -o T1_brain_without_skull

It's possible that the extra extensions in the output are causing the problem.

cookpa commented 6 months ago

I just tried to reproduce and the extension mangling does not cause a problem for me (ants 2.5.1), neither does using a .nrrd reference image.

Is it possible that you are running out of memory? Is the reference image very large?

ValeriePineauNoel commented 6 months ago

My reference image sequence is a .nrrd and has 176 slices. The images are 16-bit and are of dimension 220 X 320 pixels. In total, the file is 24.8 MB. I didn't think the file is too big. Do you know how I could verify if I run out of memory on my MacOS?

ValeriePineauNoel commented 6 months ago

I had the same error after trying this : antsBrainExtraction.sh -d 3 -a Ax_3D_postt1_Mprage_8.nrrd -e <path>/Kirby/S_template3.nii.gz -o T1_brain_without_skull abe_command_output2.txt

cookpa commented 6 months ago

OH, I think I see it now

    Using antsBrainExtraction with the following arguments:
      image dimension         = 3
      anatomical image        = Ax_3D_postt1_Mprage_8.nrrd
      extraction template     = /Users/dcclab/Documents/Marc/shavasana_registration/T1-CIT168onpost/BrainTemplates/Kirby/S_template3.nii.gz
      extraction reg. mask    = 
      extraction prior        = 
      output prefix           = T1_brain_without_skull.nii.gz
      output image suffix     = nii.gz

You have specified the extraction template, but not the prior probability mask to go with it. Is there a brain mask or brain probability mask to go with S_template3.nii.gz? You need to have that and pass it to the script with -m

ValeriePineauNoel commented 6 months ago

Oh I see! But there are no probability mask with the Kirby brain template. Oasis has a file "...ProbabilityMask.nii.gz" but not the Kirby.

Screenshot 2024-04-15 at 4 07 24 PM
ValeriePineauNoel commented 6 months ago

I will try with NKI.

cookpa commented 6 months ago

Sorry about that, you can make a mask with

ThresholdImage 3 S_template3_BrainCerebellum.nii.gz S_template3_BrainCerebellumMask.nii.gz 0.01 Inf

cookpa commented 6 months ago

Or another template will work also. Note that -m is where you pass the brain outline, while the optional -f is for a mask to constrain registration.

Example here for NKI, the brain mask -m is in red ie (T_template_BrainCerebellumProbabilityMask.nii.gz)

image
ValeriePineauNoel commented 6 months ago

Oh ok I see! So I could really get any brain template then. I tried it with the NKI and it worked very well. Thank you both for you help! The problem came from the fact that I didn't select a probability mask. abe_command_output3.txt