tkerwin
tkerwin

Reputation: 9759

Going from numpy array to itk Image

I have a numpy array and want to convert it into an ITK image for further processing. How do I do this without using the PyBuffer extension to WrapITK. I can't use that because I get a bunch of errors when compiling:

.../ExternalProjects/PyBuffer/itkPyBuffer.txx: In static member function ‘static PyObject* itk::PyBuffer<TImage>::GetArrayFromImage(TImage*) [with TImage = itk::Image<float, 2u>]’:
.../ExternalProjects/PyBuffer/wrap_itkPyBufferPython.cxx:1397:   instantiated from here
.../ExternalProjects/PyBuffer/itkPyBuffer.txx:64: error: cannot convert ‘int*’ to ‘npy_intp*’ in argument passing

I could use an idea about either how to fix the compilation errors or another way to convert my python objects.

Upvotes: 3

Views: 2784

Answers (3)

Matt McCormick
Matt McCormick

Reputation: 314

Clone the PyBuffer repository in your ITK source tree at Modules/External. Then enable it in your CMake configuration.

Upvotes: 0

Hans
Hans

Reputation: 471

You may be very interested in the recent SimpleITK work that is occuring.

There is much information at www.simpleitk.org.

The source code and much documentation can be found at http://www.github.com/SimpleITK.

Upvotes: 1

tkerwin
tkerwin

Reputation: 9759

Just change

int dimensions[ ImageDimension ];

to

npy_intp dimensions[ ImageDimension ];

and recompile.

Upvotes: 2

Related Questions