Skip to content

nifti dim_info transformation after orientation #716

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

Closed
constracti opened this issue Jan 19, 2019 · 4 comments · Fixed by #741
Closed

nifti dim_info transformation after orientation #716

constracti opened this issue Jan 19, 2019 · 4 comments · Fixed by #741
Labels
Milestone

Comments

@constracti
Copy link
Contributor

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.]

@effigies
Copy link
Member

That looks correct... Would you be willing to submit a test that makes sure dim_info is correctly permuted, and then your proposed fix?

@effigies effigies added the bug label Mar 13, 2019
@constracti
Copy link
Contributor Author

I hope I'll be able to handle it in the following days.

@constracti
Copy link
Contributor Author

I haven't understood, do you agree with my point?
In my example, should img_ornt.header.get_dim_info() return (0, 2, 1)?
I'm asking to make sure that I have completely comprehended the definition (i.e. the operation) of ornt.

@effigies
Copy link
Member

Sorry, yes. I think you're right. I'm having some trouble thinking through the orientations, myself. I'll fix up the tests, and then test out your fix to make sure that it resolves them.

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

Successfully merging a pull request may close this issue.

2 participants