简体   繁体   中英

How can I implement the conversion between itk image and SimpleITK image in Python?

I know the way to implement the conversion between itk image and SimpleITK image in C++, which is an example in 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() );

But in Python, when I used "sitk.Image(itkImage)" in which itkImage is an itkImage, I got an error "this = _SimpleITK.new_Image(*args) NotImplementedError: Wrong number or type of arguments for overloaded function 'new_Image'". And in python it's impossible to convert the type like "dynamic_cast" in C++.

There's one possible solution for this, which use PyBuffer to convert itkImage into numpy array and then use SimpleITK to convert array into SimpleITK image finally. But I fail in building the itkPyBuffer. And I think this method isn't direct to solve this problem.

Can you help me to convert the C++ code into available python code? Thank you.

这是 ITK 和 SimpleITK 图像之间的转换器: https : //github.com/gregpost/itk-SimpleITK-Converter

I can replicate that a SimpleITK image cannot be instantiated in Python from an itk image. I didn't find a way around PyBuffer, so you might have to compile after all. Here is a description around a small bug that might help you: https://pypi.python.org/pypi/MedPy/0.1.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM