[ITK Community] Problem about conversion between itk and SimpleITK image in Python

Guo Hengkai guohengkaighk at gmail.com
Mon Jan 27 08:35:17 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.

-- 

Guo Hengkai (Undergraduate)

郭亨凯        (本科生)
Dept. of Biomedical Engineering
School of Medicine,Tsinghua Univ.

清华大学,医学院,生物医学工程系
Beijing, China              中国,北京
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140127/6cf48e8d/attachment-0002.html>


More information about the Community mailing list