[Insight-users] Python Wrapping: Return an itkImage Object
Glen Lehmann
glehmann at imaging . robarts . ca
Mon, 27 Oct 2003 12:01:53 -0500
Hi Hua,
I avoid this when converting from itk::Image to vtkImageData by doing
the following;
def ITK2VTK(self, itkImage):
# this will form the end-point of the ITK pipeline segment
itkExporter = itk.itkVTKImageExportF2_New()
itkExporter.SetInput( itkImage )
# the vtkImageImport will bring our data back into VTK-land
vtkImporter = vtk.vtkImageImport()
# do the magic connection call (once again: only available if
you built
# ITK with ITK_CSWIG_CONNECTVTKITK set to ON)
CVIPy.ConnectITKF2ToVTK(itkExporter.GetPointer(), vtkImporter)
imageData = vtk.vtkImageData()
imageData.DeepCopy( vtkImporter.GetOutput() )
return imageData
However, when converting from vtkImageData to itk::Image I get the same
seg. faults that you do because I can't preform a deep copy operation on
the itk::Image. Is there an equivilant operation in itk?
Glen
Hua Qian wrote:
> Hello,
>
> Here are two little python classes to test returning an
> itkImage object. One class works and the other gives
> segmentation fault. Could someone confirm that and
> explain why?
>
> Regards,
> Hua
>
> from InsightToolkit import *
>
> class testReturnImage1:
> def __init__(self):
> self._reader = itkImageFileReaderF2_New()
> self._reader.SetFileName("../../Testing/Data/Input/cthead1.png")
> self._image = self._reader.GetOutput()
>
> def GetImage(self):
> return self._image
>
> class testReturnImage2:
> def __init__(self):
> reader = itkImageFileReaderF2_New()
> reader.SetFileName("../../Testing/Data/Input/cthead1.png")
> self._image = reader.GetOutput()
> def GetImage(self):
> return self._image
>
> app1 = testReturnImage1()
> image = app1.GetImage()
> print "app1: updating image ... "
> image.Update()
> print " Done."
>
> app2 = testReturnImage2()
> image2 = app2.GetImage()
> print "app2: updating image ... "
> image2.Update()
> print " Done."
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>