Skip to content

Instantly share code, notes, and snippets.

@koegl
Last active May 6, 2024 11:24
Show Gist options
  • Save koegl/96e79b4f7b6df568fa0eaa9c70e61c58 to your computer and use it in GitHub Desktop.
Save koegl/96e79b4f7b6df568fa0eaa9c70e61c58 to your computer and use it in GitHub Desktop.
Convert .h5 to .nii.gz
# this snippet shows how to convert a .h5 transformation to a .nii.gz displacement field using the ants python library
# based on this commend https://github.com/ANTsX/ANTs/issues/54#issuecomment-2085595485
# to do this, we need the reference/fixed image and the .h5 transformation
from ants import utils as utils_ants
args = ['-d', '3',
'-r', 'reference.nii.gz',
'-t', 'transform.h5',
'-o', '[ transform.nii.gz, 1 ]',
'--verbose']
libfn = utils_ants.get_lib_fn('antsApplyTransforms')
libfn(processed_args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment