ANTsX / ANTs

Advanced Normalization Tools (ANTs)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can i get deformation field?

domadaaaa opened this issue · comments

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

How did you produce the deformation field?

How did you produce the deformation field?

That's exactly what I want to know too LOL

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

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

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

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')
`

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