Skip to content

nifti dim_info transformation after orientation #716

Closed
@constracti

Description

@constracti

Running the test

import numpy as np
import nibabel as nib

data = np.arange(24).reshape((2,3,4))
img = nib.Nifti1Image(data, np.eye(4))
img.header.set_dim_info(1, 0, 2)

ornt = np.array([[2, 1], [0, 1], [1, 1]])
img_ornt = img.as_reoriented(ornt)
print(ornt[:,0])
print(img.shape)
print(img_ornt.shape)
print(img.header.get_dim_info())
print(img_ornt.header.get_dim_info())

we get

[2 0 1]
(2, 3, 4)
(3, 4, 2)
(1, 0, 2)
(1, 2, 0)

although (if I'm not wrong) the correct output should look like

[2 0 1]
(2, 3, 4)
(3, 4, 2)
(1, 0, 2)
(0, 2, 1)

(note the difference in the last line).

Shouldn't the following

new_dim[idx] = np.where(ornt[:, 0] == idx)[0]

be new_dim[idx] = ornt[value, 0]?

[In which case, it would be better to ensure that value has an integer data type; however, io_orienatation returns a float array.]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions