[Insight-users] Passing ITK objects from Python to C code of a
Python extension
Sven Prevrhal
sven.prevrhal at radiology.ucsf.edu
Tue Jun 19 22:32:25 EDT 2007
Since there are apparently some issues with converting strings and vectors
of strings to/from Python and ITK and I have not figured out how to, from
Python,
- use DICOMSeriesFileNames to get a set of file names pertaining to
one SeriesUID
- read it with ImageSeriesReader
- Use ConnectITKToVTK to transfer the images over to VTK for
visualization
I thought I would write a Python extension that would accept a SeriesUID,
execute those steps and return a vtkImageData object to Python for further
processing. But I fail to figure out how to pass an ITK object to my
Python/C code.
I was thinking something like this for Python extension .cxx file -
static PyObject *
PyITKHelloWorld_ITKHelloWorld(PyObject *self, PyObject *args)
{
ImageType::Pointer argImage;
PyObject * arg1;
if (!PyArg_ParseTuple(args, "O", &arg1))
return NULL;
// THIS LINE DOES NOT COMPILE
argImage= (itk::Image< unsigned short, 3 >::Pointer) arg1;
...
and in Python,
im = itkImageUS3_New()
PyITKHelloWorld.ITKHelloWorld(im.GetPointer())
...
Needless to say, the code does not compile (can import my extension though,
and I have a very simple method without passing an ITK object that works
just fine, so the basics are OK). Am I completely off? Or what do I need to
do?
Thanks!
Sven
More information about the Insight-users
mailing list