[Insight-users] Garbage Collection Problem with Python WrapITK
Chapman, Brian
chapbe at pitt.edu
Sun Mar 2 07:59:29 EST 2008
I have run across a major difference with how WrapITK behaves on Mac OSX and
on Centos linux. I've primarily been developing on Mac OSX where the
behavior is as I would expect. I can create a function that creates an ITK
image and then returns the image to the calling function. Everything works
beautifully. However, in Centos any object created in a function fails to
persist when it is returned to the calling function. To test that this is a
WrapITK problem, I wrote a simple function which creates a numarrray object
and then returns the numarray object to the calling function. On both Mac
OSX and Centos this works correctly.
A simple function which creates an ITK image, however, behaves differently
in OSX than it does in Centos. Here is the program:
import numarray as na
import numarray.mlab as mlab
import numarray.random_array as ra
import itk
def test1(dim = [16,128,128]):
img = ra.normal(5,2,shape=dim)
return img
def test2(img):
sc = itk.ShiftScaleImageFilter.IF3IF3.New()
sc.SetInput(img)
sc.SetShift(0)
sc.SetScale(2)
sc.Update()
img = sc.GetOutput()
return img
def main():
img = test1()
print "min(img)=%f, max(img)=%f"%(mlab.min(img.flat),mlab.max(img.flat))
reader = itk.ImageFileReader.IF3.New(FileName='test.mha')
reader.Update()
img = reader.GetOutput()
print itk.range(img)
img2 = test2(img)
print itk.range(img2)
if __name__=='__main__':
main()
Here is the output on OSX:
cbmi01:~/Code/Python/Multispectral brian$ python testMem.py
min(img)=-4.767438, max(img)=14.360112
(0.0, 1895.0)
(0.0, 3790.0)
cbmi01:~/Code/Python/Multispectral brian$
Here is the output on Centos:
[brian at DBMI-MDT-044 Multispectral]$ python testMem.pymin(img)=-4.801929,
max(img)=14.282335
(0.0, 1895.0)
Segmentation fault
Any ideas about what is going on? I'd appreciate your help.
Brian
More information about the Insight-users
mailing list