I have noticed that in some cases (not always) saving an image after being loaded using nib.as_closest_canonical and then re-loading it in the same way causes axis to be transposed. To illustrate this the attached image and the code below can be used.
import nibabel as nib
from pathlib import Path
f = Path("test.nii.gz")
image = nib.as_closest_canonical(nib.load(f))
nib.save(nib.Nifti1Image(image.get_fdata(), image.affine, image.header), "test-canonical.nii.gz")
image_reloaded = nib.as_closest_canonical(nib.load("test-canonical.nii.gz"))
print(image.shape, image_reloaded.shape)
# (1024, 1024, 33) (33, 1024, 1024)
Expected behavior:
The axis order should be consistent after saving an image and re-loading it.
Exemplary image:
test.nii.gz
I have noticed that in some cases (not always) saving an image after being loaded using
nib.as_closest_canonicaland then re-loading it in the same way causes axis to be transposed. To illustrate this the attached image and the code below can be used.Expected behavior:
The axis order should be consistent after saving an image and re-loading it.
Exemplary image:
test.nii.gz