ANTsX / ANTs

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

Brain Extraction problem 3D T1w input image - which template? #909

Closed Adam123-png closed 4 years ago

Adam123-png commented 4 years ago

Hello all,

I´m struggling with skull stripping on the input MR 3D T1w image: 3D_T1

So far I´ve tried to use many templates (MICCAI2012-Multi-Atlas-Challenge, Kirby, Oasis, NKI) to perform the brain extraction but still the skull stripping is still very bad. The first image is used the MICCAI2012-Multi-Atlas-Challenge and the second image is used the NKI template: skull_strip

NKI

I´m using this command: antsBrainExtraction.sh -d 3 -a t1.nii.gz -e T_template0.nii.gz \ -m T_template0_BrainCerebellumProbabilityMask.nii.gz -o output (I will just change the template (brain with skull) and brain probability mask (only the mask of a brain)). Please, could you advise me what I´m doing wrong? Which template should choose? I guess my input image is just a classic input MR image so I guess to extract the brain shouldn´t be any problem.

Many thanks Regards Adam

ntustison commented 4 years ago

Can you post your data?

gdevenyi commented 4 years ago

Sounds like completely different input orientation than available templates. A manual reorientation in ITKsnap would probably help here.

dorianps commented 4 years ago

Looks like the visualization is happening in MRIcron while the data is processed in ANTs. Maybe qform/sform mismatch? I would use itksnap to view the result.

On Tue, Nov 12, 2019 at 3:35 PM Gabriel A. Devenyi notifications@github.com wrote:

Sounds like completely different input orientation than available templates. A manual reorientation in ITKsnap would probably help here.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTs/issues/909?email_source=notifications&email_token=ACFJU7PWFPADQ6ED3VSUYNTQTMHQTA5CNFSM4JMIQMWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOED32ZGI#issuecomment-553102489, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACFJU7KDMNHBWZIX43PP2ZLQTMHQTANCNFSM4JMIQMWA .

Adam123-png commented 4 years ago

Thanks a lot for your inputs. You are right my data and the templates have completely different orientation. Check this photo - MICCAI2012 template overlaid by my data highlighted in a red color: reorient

As advised, I tried to manually reorient the images in ITK Snap. However, I wasn´t successfull - can just change the images´ deirection (left, right, anterior, posterior, superior, inferior) but the problem is a different position of all three planes (axial, sagittal and coronal). Please, could you help me how to change the order of planes in order the planes for each picture (my data and templates) would suit? I was looking at all the accessible templates I found and all of these templates are set in this position that is different than my data position.

Moreover, how could I modify the qform/sform? Could this modification help? Unfortunalety, I´m not sure if I can publish the patient´s data. I will ask my instructor if it´s possible.

Many thanks for your help

cookpa commented 4 years ago

You can try PermuteFlipImageOrientationAxes.

Modifying qform is what ITK-SNAP's re-orientation does. You'd want to change it so that the anatomical markers in ITK-SNAP (A, P, L, R, S, I) are correct for your input image.

ITK does not use sform, see

https://github.com/ANTsX/ANTs/wiki/How-does-ANTs-handle-qform-and-sform-in-NIFTI-1-images%3F

stnava commented 4 years ago

yes, use:

PermuteFlipImageOrientationAxes

followed by

CopyImageHeaderInformation

to copy back the original image header to the output of PermuteFlipImageOrientationAxes

brian

On Wed, Nov 13, 2019 at 10:35 AM Philip Cook notifications@github.com wrote:

You can try PermuteFlipImageOrientationAxes.

Modifying qform is what ITK-SNAP's re-orientation does. You'd want to change it so that the anatomical markers in ITK-SNAP (A, P, L, R, S, I) are correct for your input image.

ITK does not use sform, see

https://github.com/ANTsX/ANTs/wiki/How-does-ANTs-handle-qform-and-sform-in-NIFTI-1-images%3F

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTs/issues/909?email_source=notifications&email_token=AACPE7XXJIZ4XSAR2RLUHA3QTQNE5A5CNFSM4JMIQMWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOED6RHVA#issuecomment-553456596, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACPE7VSSFOZEDMZGP5A7UTQTQNE5ANCNFSM4JMIQMWA .

Adam123-png commented 4 years ago

Yeah, I tried successfully to do PermuteFlipImageOrientationAxes. It´s working perfect - I was able to adjust the template images on the right planes and direction.

However, when I check the "PrintHeader" of both images (the reference image - patient´s data and the template image) - there are some discrepancies in the direction and s_row_x,y,z.

Hence, I implemented CopyImageHeaderInformation "CopyImageHeaderInformation reference_patient_data.nii template.nii template_corrected.nii 1 1 1" . Is it OK? Here is the input of PrintHeader:

Direction (after CopyImageHeaderInformation for both images the same) 0.99864 -0.0504409 -0.0132136 0.0504453 0.998727 -7.70213e-09 0.0131967 -0.000666555 0.999913

,whereas s_row_x,y,z for both images are still different (should be the same I guess)

for template: srow_x = 0 0 0 0 srow_y = 0 0 0 0 srow_z = 0 0 0 0

for my input MR T1 data: srow_x = -0.487617 0.0246288 0.00726742 121.329 srow_y = -0.0246309 -0.48766 -1.96204e-11 138.252 srow_z = 0.00644372 -0.000325462 0.54995 -92.5169

Here is the visualization of 3D T1 input data and corrected template: Header

Please, how to address this issue? My issues is pretty similar to this: https://sourceforge.net/p/advants/discussion/840260/thread/bef52561/

Thanks a lot

Adam123-png commented 4 years ago

Please, if you need to provide my input image, let me know.

ntustison commented 4 years ago

Sure, go ahead and post the image and I'll take a look. By the way, I see you're not using ITK-SNAP for the latest visualization. Please use ITK-SNAP for any visualizations.

cookpa commented 4 years ago

The sform is not supported by ITK and is changed to zero in the output to reflect that fact. There’s more information on this at the link I posted above.

Adam123-png commented 4 years ago

Here is the Dropbox link to my input image: https://www.dropbox.com/home?preview=3D_T1.nii&fbclid=IwAR1T9ylc0ou0GQ9qtQpvd4FBtsgCfvSxd8wa6uTZ8maAbSOmeRGKlK_Dfp0 . Let me know if you have some problems with getting the image.

OK, I will be using ITK-SNAP for any visualiztion. Thanks a lot for this advice. Here is the visualization of 3D T1 input data and corrected template (red highlighted): finallll

Many thanks

ntustison commented 4 years ago

Thanks Adam. I couldn't download your image but the ITK-SNAP visualization demonstrates the orientation problem that you continue to have with your corrected template. You can see that the template is orientated opposite as it should be (A-P is flipped). You previously posted a visualization within ITK-SNAP of the MICCAI 2012 template. I don't believe that image to be the template that we've made available because its orientation is wrong (as visualized within ITK-SNAP). Where did you get your MICCAI 2012 template?

cookpa commented 4 years ago

You've got to be careful with overlays in ITK-SNAP because it will attempt to load the second image into the physical space of the first. If you are unsure about orientations you should load the images as separate ITK-SNAP windows.

I would also recommend correcting the input data to have the proper anatomical coordinates, rather than trying to make the template wrong. Otherwise if you want to do anything else in ITK besides brain extraction, you may end up having to solve the same problem again.

Adam123-png commented 4 years ago

I´m sorry I was quite confused so the template I visualized in ITK-SNAP is not your template you had made available. It´s your template I´ve already wrongly "corrected" :) Here is where I downloaded the templates: https://figshare.com/articles/ANTs_ANTsR_Brain_Templates/915436

I already know where I was making mistakes but still I have some things I don´t understand. Please, could you clarify it to me?

1: When I visualize your template in ITK-SNAP the planes and orientation are the same with my input image, whereas when visualizing your template in FSLEYES the planes and orientation are different from my image planes and visualization. How is it possible? That´s why it made me really confused cause I firstly opened the template in FSLEYES. Hence, I was making some adjustments that were useless.

2: The skull stripping of my input data by using MICCAI 2012 T_template0.nii is very "stringent" - it means much brain tissue has been removed. What would you advise me - to use another MICCAI 2012 template? Or is there any other way how to perform more accurate skull stripping?

I´m sorry for the troubles and really thanks a lot for your help! Adam

ntustison commented 4 years ago

@cookpa pointed to this earlier but please read this explanation for how and why FSL and ANTs treat images differently. This means that if you want to use ANTs, only use ITK-SNAP for visualization as that accurately reflects how ANTs tools are treating the image.

Regarding your second item---we would have to see the results to provide further guidance.

cookpa commented 4 years ago

Here's some background on fsleyes

https://users.fmrib.ox.ac.uk/~paulmc/fsleyes/userdoc/latest/display_space.html

There's a whole lot going on here but all visualization software makes its own decisions about how to display things and how to deal with overlays that don't have identical headers. See this section for example

https://users.fmrib.ox.ac.uk/~paulmc/fsleyes/userdoc/latest/display_space.html#reference-image-space

The DropBox link didn't work for me either, BTW.

Adam123-png commented 4 years ago

Thanks for your explanation, it´s more clear for me.

Please, download my input data "3D_T1.rar". Hope at least one download link will be working :) https://1drv.ms/u/s!Arwi-B8w_lxVhg-6UtZNt1tm9bS0?e=fMiJ44 http://mysharegadget.com/129543722

Unfortunately, the skull stripping of my input data is still not sufficient (used Oasis Miccai 2012 and NKI template). Used this command "antsBrainExtraction.sh -d 3 -a t1.nii.gz -e T_template0.nii.gz \ -m T_template0_BrainCerebellumProbabilityMask.nii.gz -o output" . Please, could you have a look at it? Thanks a lot.

ntustison commented 4 years ago

Try the Kirby template. https://figshare.com/articles/ANTs_ANTsR_Brain_Templates/915436

Adam123-png commented 4 years ago

I´m very sorry for my late response. I tried to run the Kirby template ("S_template3.nii as a template" and "S_template3_BrainCerebellum.nii" as a probability mask). Here is the result. There is no problem with aligning my input data with the final skull-stripped image. Moreover, the orientation for both images is the same in ITK-SNAP (Oblique, closest to RAI). When running "PrintHeader" the direction for both images is the same. However, the skull-stripped image is very poor (almost all brain tissue is completey removed).

No_correction_overlay

How is it possible? Which template can I choose that will perform good skull-stripping? Thanks a lot

ntustison commented 4 years ago

The Kirby template actually works---I tried it with your data and the results were as expected. However, you can't use the skull-stripped template as the probability mask. That doesn't make sense. You can generate the mask, though, doing:

$ ThresholdImage 3 S_template3_BrainCerebellum.nii S_template3_BrainCerebellumProbabilityMask.nii 0 0 0 1
$ SmoothImage 3 S_template3_BrainCerebellumProbabilityMask.nii 1.0 S_template3_BrainCerebellumProbabilityMask.nii 1
Adam123-png commented 4 years ago

Thanks a lot, it´s working perfectly! I finally know where I was making the same mistake.