Skip to content

Coordinate x and z are inverted in minc 1 format #372

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
cdansereau opened this issue Nov 2, 2015 · 9 comments
Closed

Coordinate x and z are inverted in minc 1 format #372

cdansereau opened this issue Nov 2, 2015 · 9 comments

Comments

@cdansereau
Copy link

Hi,
The coordinate x and z are inverted in when we load minc 1 format
see the affine transformation it will make it clear

I notice that problem when I try to go from the voxel space to the world space using the following

This is the correct coordinates using the nii file :

nii_data = nib.load('/media/cdansereau/database1/data/template.nii.gz')
apply_affine(nii_data.get_affine(),[124,122,92])
[ 26. -12. 20.]
and the affine transformation
nii_data.get_affine()
[[ 1. 0. 0. -98.]
[ 0. 1. 0. -134.]
[ 0. 0. 1. -72.]
[ 0. 0. 0. 1.]]

This is the result with the same file in mnc1 format :

mnc_data = nib.load('/media/cdansereau/database1/data/template.mnc.gz')
apply_affine(mnc_data.get_affine(),[124,122,92])
[ -6. -12. 52.]
and the affine transformation
mnc_data.get_affine()
[[ 0. 0. 1. -98.]
[ 0. 1. 0. -134.]
[ 1. 0. 0. -72.]
[ 0. 0. 0. 1.]]

@matthew-brett
Copy link
Member

matthew-brett commented Nov 3, 2015 via email

@cdansereau
Copy link
Author

I agree the thing is that this is inconsistent with the way you present the data in other format that could lead to error e.g if we use affine transformation from different format. is there a method at leas to make a sanity check about the dimension order?

Thank you a lot for your great work!

@matthew-brett
Copy link
Member

matthew-brett commented Nov 3, 2015 via email

@cdansereau
Copy link
Author

Yes it is just that in order to prevent mistake loading a nii or a mnc file I would have expect to have the coordinate in the same order or a function that would provide if the dimensions are in xyz or zyx.

let's take an hypothetical example:
I have an anat file in nii and a fmri file in mnc1

I will have to specify the x,y,z coordinates for the nii file and the z,y,x coordinate for the mnc1 file.

@bcipolli
Copy link
Contributor

bcipolli commented Nov 4, 2015

@cdansereau I think the expectation is that users should know about the image formats of their data. My understanding is that nibabel simply exposes the underlying data; it's necessarily in the business of trying to convert amongst the formats.

With that said, #300 is probably along the lines of what you're looking for--a function that you can use to get data in a common format.

@effigies
Copy link
Member

effigies commented Nov 4, 2015

@bcipolli Not to get too far off-topic, but the goal of #300 is to create a new image from an old one, but with a new data array. Unless I'm missing something about the underlying new image creation, all a Nifti1Image.image_like(mincimage, dataobj) would give you is a Nifti1Image with an affine that looks like

[[ 0. 0. 1. -98.]
 [ 0. 1. 0. -134.]
 [ 1. 0. 0. -72.]
 [ 0. 0. 0. 1.]]

@bcipolli
Copy link
Contributor

bcipolli commented Nov 4, 2015

Cool, thanks for clarifying!

@effigies
Copy link
Member

effigies commented Nov 4, 2015

@cdansereau Here's a quick function that does what I think you're asking for:

def ordering(affine):
    labels = np.array(['x', 'y', 'z'])
    return labels[np.nonzero(affine[:3, :3])[1]]

@cdansereau
Copy link
Author

Thanks @effigies like what you mention in your last post on #300 you want to keep the axis order as unchanged as possible and and not reformat the image in a "preferred" axis order.

I will use Nifti1Image.from_image(mincimage, dataobj) to do so
Thanks

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

4 participants