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

**URL:** https://discourse.itk.org/t/systematic-kernel-crash-when-using-interpolator-evaluate-inside-loop-python/4121
**Category:** Beginner Questions
**Tags:** python
**Created:** [May 12, 2021, 8:24am UTC](https://discourse.itk.org/t/systematic-kernel-crash-when-using-interpolator-evaluate-inside-loop-python/4121 "2021-05-12T08:24:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Benjamin-Fouquet](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/b77776/32.png) [@Benjamin-Fouquet](https://discourse.itk.org/u/Benjamin-Fouquet)
#### Post date: [May 12, 2021, 8:24am UTC](https://discourse.itk.org/t/systematic-kernel-crash-when-using-interpolator-evaluate-inside-loop-python/4121/1 "2021-05-12T08:24:44Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 12, 2021, 9:36pm UTC](https://discourse.itk.org/t/systematic-kernel-crash-when-using-interpolator-evaluate-inside-loop-python/4121/2 "2021-05-12T21:36:23Z")

</div>

What is the error/exception message?

---

<div class="post-metadata">

### Author: ![Benjamin-Fouquet](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/b77776/32.png) [@Benjamin-Fouquet](https://discourse.itk.org/u/Benjamin-Fouquet)
#### Post date: [May 17, 2021, 8:34am UTC](https://discourse.itk.org/t/systematic-kernel-crash-when-using-interpolator-evaluate-inside-loop-python/4121/3 "2021-05-17T08:34:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 19, 2021, 5:44pm UTC](https://discourse.itk.org/t/systematic-kernel-crash-when-using-interpolator-evaluate-inside-loop-python/4121/4 "2021-05-19T17:44:38Z")

</div>

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.
