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 can i get deformation field? #1642

Closed
domadaaaa opened this issue Dec 24, 2023 · 7 comments
Closed

How can i get deformation field? #1642

domadaaaa opened this issue Dec 24, 2023 · 7 comments

Comments

@domadaaaa
Copy link

HI,I want to save deformation field to NIFTY format, what should i do?

@ntustison
Copy link
Member

How did you produce the deformation field?

@domadaaaa
Copy link
Author

How did you produce the deformation field?

That's exactly what I want to know too LOL

@cookpa
Copy link
Member

cookpa commented Dec 26, 2023

Are you asking how to do image registration? Start with the script antsRegistrationSyNQuick.sh

@domadaaaa
Copy link
Author

Are you asking how to do image registration? Start with the script antsRegistrationSyNQuick.sh
No... I would like to obtain a deformation field file generated during the registration process

@cookpa
Copy link
Member

cookpa commented Dec 26, 2023

I'm a little confused, running the registration script with its default parameters will produce a deformation field in NIFTI format.

@domadaaaa
Copy link
Author

I'm a little confused, running the registration script with its default parameters will produce a deformation field in NIFTI format.

sry,there is something wrong with my expression. I registrat with python package antspy running in linux
my code is as follows, can i modify code to obtain the deformation field?
`
import ants
from scipy.ndimage import zoom
import nibabel as nib
import numpy as np

fixed = ants.image_read("MRI.nii.gz")

img = nib.load('CT.nii.gz')
moving = img.get_fdata()

scale = (0.9375, 0.9375, 0.6)
moving = zoom(moving, scale)

moving = nib.Nifti1Image(moving, img.affine, img.header)
nib.save(moving, 're_CT.nii.gz')

moving = ants.image_read("re_CT.nii.gz")

SyN = ants.registration(fixed=fixed, moving=moving, save_state=True)
result = ants.apply_transforms(fixed=fixed, moving=moving, transformlist=SyN['fwdtransforms'])

ants.image_write(result, 'moved.nii.gz')
`

@cookpa
Copy link
Member

cookpa commented Dec 26, 2023

Ok I think I understand now

SyN['fwdtransforms']

This should be a list of strings, they are file names. The first one will be the deformation field, in NIFTI format.

They can be read with the read_transform function

@cookpa cookpa closed this as completed Jan 7, 2024
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

3 participants