[Insight-users] How can I implement the conversion between itk image and SimpleITK image in Python?
Hengkai Guo
guohengkaighk at gmail.com
Mon Jan 27 08:18:02 EST 2014
Dear all,
I'm now using SimpleITK in Python. When combining itk with it, I had a problem.
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.
I have tried my best to search in the Internet, but found nothing. Can you
help me to convert the C++ code into available python code? Thank you.
More information about the Insight-users
mailing list