代码之家  ›  专栏  ›  技术社区  ›  arthur.sw

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

  •  0
  • arthur.sw  · 技术社区  · 4 年前

    我想将DisplacementFieldTransform另存为SimpleITK中的图像。

    The documentation 说:

    位移场,例如存储在DisplacementFieldTransform对象中的位移场,也可以保存为图像(.nrd、.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保存为图像?

    0 回复  |  直到 4 年前
        1
  •  1
  •   Dave Chen    4 年前

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

    以下是DisplacementFieldTransform类的文档: https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1DisplacementFieldTransform.html

    推荐文章