Affine transform between torchio.ScalarImage and nibabel.load do not match
See original GitHub issue🐛Bug
I am using the following NIfTI volume that is part of a dataset that I am using (don’t worry, this is public data and not confidential). When you use torchio.ScalarImage
and examine the affine transform after it has been loaded, it is not the same as if you were to use nibabel.load
. This causes havoc when I use the ToCanonical
transform because the volume is not oriented correctly.
To reproduce
Please download the file from the link above. Once you do, do the following:
import torchio as tio
import nibabel as nib
vol_path = 'img0009.nii.gz'
img_s = tio.ScalarImage(vol_path)
print(img_s.affine)
# array([[-0.97656202, 0. , 0. , 0. ],
# [ 0. , -0.97656202, 0. , 0. ],
# [ 0. , 0. , 2.5 , 0. ],
# [ 0. , 0. , 0. , 1. ]])
img_n = nib.load(vol_path)
print(img_n.affine)
# array([[ -0.97656202, 0. , 0. , 249.51159692],
# [ 0. , 0.97656202, 0. , -249.51159692],
# [ 0. , 0. , 2.5 , -185. ],
# [ 0. , 0. , 0. , 1. ]])
I am using Nibabel version 3.2.1 and torchio version 0.18.29.
Expected behavior
I would expect the affine transforms between the calls to torchio.ScalarImage
and nib.load
to be exactly the same. Why is the affine transform modified?
Actual behavior
The affine transforms are different.
System info
Platform: Linux-4.15.0-91-generic-x86_64-with-debian-buster-sid
TorchIO: 0.18.29
PyTorch: 1.7.1
NumPy: 1.19.2
Python: 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0]
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
I got it! Thank you so much! I shall close this.
No worries! Actually, TorchIO uses NiBabel only if SimpleITK fails to read the file.