[Insight-users] Python Wrapping: Return an itkImage Object

Hua Qian hqian at imaging . robarts . ca
Mon, 27 Oct 2003 10:59:46 -0500


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."