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

How do I get the affine transform from a Nifti image? #57

Open
Karol-G opened this issue May 4, 2023 · 1 comment
Open

How do I get the affine transform from a Nifti image? #57

Karol-G opened this issue May 4, 2023 · 1 comment
Labels

Comments

@Karol-G
Copy link

Karol-G commented May 4, 2023

Hey,

I would like to get the affine transform from a Nifti image, but I am not quite sure how? There is a simple method to get the image as a numpy array or the spacing from a loaded sitk Image object, but not for the affine.

Here is example code that illustrates my problem:

import SimpleITK as sitk

image_data = sitk.ReadImage(filename)
image = sitk.GetArrayFromImage(image_data)  # Easy to get the numpy image
spacing = image_data.GetSpacing()  # Easy to get the image spacing
affine = ...  # ???

I hope someone can help me.

Best,
Karol

@zivy
Copy link
Member

zivy commented May 4, 2023

Hello @Karol-G,

affine = image_date.GetDirection()

For more details on the image structure see the toolkit's fundamental concepts and this Jupyter notebook.

For future reference, please use the ITK discourse forum for Q&A.

@zivy zivy added the question label May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants