0

我正在寻求有关 simpleITK 的帮助,我正在使用 NII 文件来计算变形场。我使用 Python 和 simpleITK(simpleitk 1.2.0rc2.dev1167+gd4cf2)。我可以轻松注册我的图像或卷,但我无法获得变形场!

当我在控制台中打印它时,simpleITK 告诉我该向量是预测的图像,但是当我尝试使用作为 sitk 成员函数的“WriteImage”保存它时,写入的图像充满了空值

用于执行此操作的代码:

def RegistrationGel(pathImage1,pathImage2):

elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetFixedImage(sitk.ReadImage(pathImage1))
elastixImageFilter.SetMovingImage(sitk.ReadImage(pathImage2))

parameterMapVector = sitk.VectorOfParameterMap()
parameterMapVector.append(sitk.GetDefaultParameterMap("affine"))
#parameterMapVector.append(sitk.GetDefaultParameterMap("bspline"))
elastixImageFilter.SetParameterMap(parameterMapVector)
elastixImageFilter.Execute()
sitk.WriteImage(elastixImageFilter.GetResultImage(),"C:/Users/Armand/Desktop/RecalageGel/Output/resultImageGel.nii")

transformixImageFilter = sitk.TransformixImageFilter()
transformixImageFilter.SetMovingImage(sitk.ReadImage(pathImage2))
transformixImageFilter.ComputeDeformationFieldOn()
#transformixImageFilter.SetOutputDirectory("C:/Users/Armand/Desktop/RecalageGel/Output/DeformationFIELD.nii")
transformixImageFilter.SetTransformParameterMap(elastixImageFilter.GetTransformParameterMap())
transformixImageFilter.Execute()
sitk.WriteImage(transformixImageFilter.GetDeformationField(),"C:/Users/Armand/Desktop/RecalageGel/Output/OutputDef.nii")

我也尝试设置 transformixImageFilter 的输出目录,但也没有成功。我真的不明白这里发生了什么......有没有人有解决方案或同样的问题?我已经阅读了一些相关主题,但没有任何成功

4

1 回答 1

0

我有同样的问题,但奇怪的是现在它似乎工作了..这是我的代码:

moving = sitk.ReadImage("path_to_my_moving_image")
fixed = sitk.ReadImage("path_to_my_fixed_image")

elastixImageFilter = sitk.ElastixImageFilter()
parameterMapVector = sitk.VectorOfParameterMap()
    
elastixImageFilter.SetFixedImage(fixed)
elastixImageFilter.SetMovingImage(moving)
parameterMapVector = sitk.VectorOfParameterMap()
parameterMapVector.append(sitk.GetDefaultParameterMap("rigid"))
parameterMapVector.append(sitk.GetDefaultParameterMap("affine"))
parameterMapVector.append(sitk.GetDefaultParameterMap("bspline"))
elastixImageFilter.SetParameterMap(parameterMapVector)
elastixImageFilter.Execute()

   
transformixImageFilter = sitk.TransformixImageFilter()
transformixImageFilter.SetMovingImage(moving)  
    transformixImageFilter.SetTransformParameterMap(elastixImageFilter.GetTransformParameterMap())
transformixImageFilter.ComputeDeformationFieldOn()
transformixImageFilter.LogToConsoleOn()
transformixImageFilter.SetOutputDirectory("path_to_my_outputfolder/")
transformixImageFilter.Execute()
sitk.WriteImage(transformixImageFilter.GetDeformationField(), "path_to_my_outputfolder/transformix_rigid_affine_bspline.nii.gz")

transformix 部分的终端输出如下所示:

ELASTIX version: 5.000
Command line options from ElastixBase:
-out      path_to_my_outputfolder/
-threads  unspecified, so all available threads are used
-def      all
-jac      unspecified, so no det(dT/dx) computed
-jacmat   unspecified, so no dT/dx computed

Reading input image ...
  Reading input image took 0.000005 s
Calling all ReadFromFile()'s ...
WARNING: The parameter "UseBinaryFormatForTransformationParameters", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "UseBinaryFormatForTransformationParameters", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "UseBinaryFormatForTransformationParameters", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
  Calling all ReadFromFile()'s took 0.041007 s
Transforming points ...
  The transform is evaluated on all points. The result is a deformation field.
  Transforming points done, it took 8.95s
Compute determinant of spatial Jacobian ...
  The command-line option "-jac" is not used, so no det(dT/dx) computed.
  Computing determinant of spatial Jacobian done, it took 0.00s
Compute spatial Jacobian (full matrix) ...
  The command-line option "-jacmat" is not used, so no dT/dx computed.
  Computing spatial Jacobian done, it took 0.00s
Resampling image and writing to disk ...
  Resampling took 25.14s
于 2021-07-19T14:26:10.523 回答