如何在 SimpleITK 中将位移场变换保存为图像?

How to save a Displacement Field Transform as an image in SimpleITK?

我想在 SimpleITK 中将 DisplacementFieldTransform 保存为图像。

The documentation 说:

A displacement field, such as one stored in a DisplacementFieldTransform object, can also be saved as an image (.nrrd, .nhdr, .mha, .mhd, .nii, .nii.gz).

但是当我这样做的时候

demons = sitk.FastSymmetricForcesDemonsRegistrationFilter()
demons.SetNumberOfIterations(15)
# Standard deviation for Gaussian smoothing of displacement field
demons.SetStandardDeviations(1.0)

demons.AddCommand( sitk.sitkIterationEvent, lambda: command_iteration(demons) )

displacementField = demons.Execute(followup, baseline)

deformation_field = sitk.DisplacementFieldTransform(displacementField)

deformationFieldPath = os.path.join(destinationDataPath, str(patientId) + '_deformationField.nrrd')

sitk.WriteTransform(deformation_field, deformationFieldPath)

我收到以下错误:

RuntimeError: Exception thrown in SimpleITK WriteTransform: /tmp/SimpleITK-build/ITK/Modules/IO/TransformBase/include/itkTransformFileWriter.hxx:167:
itk::ERROR: TransformFileWriterTemplate(0x555a72b3e700): Could not create Transform IO object for writing file /home/amasson/fastai/EMISEP-differences/6_deformationField.nrrd
  Tried to create one of the following:
    HDF5TransformIOTemplate
    HDF5TransformIOTemplate
    MatlabTransformIOTemplate
    MatlabTransformIOTemplate
    TxtTransformIOTemplate
    TxtTransformIOTemplate
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.

如何将 DisplacementFieldTransform 保存为图像?

DisplacementFieldTransform 有一个 GetDisplacementField(和 GetInverseDisplacementField)方法,returns 一个图像。使用该 Image 对象,您可以调用 WriteImage 并将其导出为您喜欢的任何图像格式。

这是 DisplacementFieldTransform 的文档 class:https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1DisplacementFieldTransform.html