WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Saving image after loading as_closest_canonical swaps axis #1449

@leoyala

Description

@leoyala

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions