我知道在C++中实现itk图像和SimpleITK图像之间转换的方法,这是SimpleITK中的一个示例(Examples / ITKIntegration.cxx)。

  //
  // Extract the itk image from the SimpleITK image
  //
  InternalImageType::Pointer itkImage =
    dynamic_cast <InternalImageType*>( image.GetITKBase() );
  ...
  //
  // Return to the simpleITK setting by making a SimpleITK image using the
  // output of the blur filter.
  //
  sitk::Image blurredImage = sitk::Image( blurFilter->GetOutput() );

但是在Python中,当我使用itkImage是itkImage的“sitk.Image(itkImage)”时,出现错误“this = _SimpleITK.new_Image(* args)”
NotImplementedError:重载函数“new_Image”的参数数量或类型错误。在python中,无法在C++中转换“dynamic_cast”类型。

有一个可能的解决方案,它使用PyBuffer将itkImage转换为numpy数组,然后最终使用SimpleITK将数组转换为SimpleITK图像。但是我无法构建itkPyBuffer。而且我认为这种方法不能直接解决这个问题。

您能帮我将C++代码转换为可用的python代码吗?谢谢。

最佳答案

我可以复制一个说明,即不能从Python的itk镜像中实例化SimpleITK镜像。我没有找到解决PyBuffer的方法,因此您可能毕竟必须进行编译。以下是有关可能会帮助您的小错误的说明:https://pypi.python.org/pypi/MedPy/0.1.0

10-07 15:02