Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resampling data changes its orientation #1374

Open
Kseniiakv opened this issue Oct 9, 2024 · 1 comment
Open

Resampling data changes its orientation #1374

Kseniiakv opened this issue Oct 9, 2024 · 1 comment

Comments

@Kseniiakv
Copy link

Hi!

Have a question regarding the behaviour of resample_to_output and resample_from_to functions.
After resampling of the data, the orientation changes to default RAS, even if it had other orientation previously:

vol = nib.load(path)
print("Orientation before: ", nib.orientations.aff2axcodes(vol.affine))
target_vox_dim = (1, 1, 1)
resampled = nib.processing.resample_to_output(vol, target_vox_dim, order=3, mode='nearest')
print("Orientation after: ", nib.orientations.aff2axcodes(resampled.affine))
Orientation before:  ('L', 'A', 'S')
Orientation after:  ('R', 'A', 'S')

Expected behaviour: orientation of the resampled data shouldn't change

Is this expected behaviour?
Now if I want LAS orientation, I need to reorient data additionally after resampling.

@effigies
Copy link
Member

effigies commented Oct 9, 2024

Yes, this is expected. Resampling requires choosing a number of parameters, and the functions are intended to be fairly simple. If you want full control over the field of view, specify a shape and an affine, and use nibabel.affines.rescale_affine to preserve the rotations and shears.

vol = nib.load(path)
target_zooms = (1, 1, 1)
target_shape = vol.shape  # Or you can set anything you like
target_aff = nib.affines.rescale_affine(vol.affine, vol.shape, target_zooms, target_shape)
resampled = nib.procesing.resample_from_to(vol, (target_shape, target_aff))

Note (see #1366) that if you go from an even number of voxels to odd (or vice versa) in any dimension, you might get an affine slightly different from what you want. The resampling will be valid, however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants