Systematic kernel crash when using interpolator.Evaluate inside loop (python)

Hello there,

I just started to fiddle with itk at the lab. What I was trying to do is to fetch the texture of a nifti image and plug it to a corresponding mesh, interpolating a pixel intensity value as needed. Code looks as follow, and append the adequat texture for each node of the mesh.

texture = np.zeros (len(mesh.vertices))
lin_interpolator = itk.LinearInterpolateImageFunction.New (itkimage)
for i in range(len(mesh.vertices)):
    index = itkimage.TransformPhysicalPointToContinuousIndex(mesh.vertices[i])
    texture [i] = lin_interpolator.Evaluate (index)

However, the kernel systematically crashes when trying to run the code. did any of you already have such case? I am very much a beginner so it could be a very simple oversight from my part.

As a side note, a simpler version without the interpolator and with GetPixel works well.

What is the error/exception message?

Dear Dzenanz,

Thanks for your swift reply. I did not get any error message, just a kernel crash when I tried to run the script.

Replacing lin_interpolator.Evaluate (index) → lin_interpolator.EvaluateAtContinuousIndex (index) yielded the expected result though. I would expect some values where not correctly interpreted by Evaluate ().

Thanks again

1 Like

Since index is a continuous type, calling EvaluateAtContinuousIndex is right. If you used TransformPhysicalPointToIndex, Evaluate should work. But Python crashing instead giving an error message indicates that ITK’s Python wrapping is not catching/handling the C++ exception properly.