# Improper wrapping of ImageFunction::IsInsideBuffer?

**URL:** https://discourse.itk.org/t/improper-wrapping-of-imagefunction-isinsidebuffer/7495
**Category:** Engineering
**Created:** [April 15, 2025, 7:29am UTC](https://discourse.itk.org/t/improper-wrapping-of-imagefunction-isinsidebuffer/7495 "2025-04-15T07:29:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![acoussat](https://discourse.itk.org/user_avatar/discourse.itk.org/acoussat/32/699_2.png) [@acoussat](https://discourse.itk.org/u/acoussat)
#### Post date: [April 15, 2025, 7:29am UTC](https://discourse.itk.org/t/improper-wrapping-of-imagefunction-isinsidebuffer/7495/1 "2025-04-15T07:29:57Z")

</div>

Dear ITK community,

I am currently trying to use `ImageFunction::IsInsideBuffer` from within a Python script. My environment runs Python 3.12.0 and ITK 5.4.3 installed directly from Pypi.

[As can be seen from the documentation](https://docs.itk.org/projects/doxygen/en/stable/classitk_1_1ImageFunction.html#abd294da99d2c10d49baa0c9fb52132a3), `ImageFunction::IsInsideBuffer` can accept three kinds of input: a continuous index, an index or a point. However, only the “point version” seems to be callable from Python in my case.

My problems boils down to the following script:

```python
import itk
import numpy as np

image = itk.GetImageFromArray(np.full((200, 200, 200), 1.))
interp = itk.LinearInterpolateImageFunction.New(image) # concrete subclass of ImageFunction

# From the doc, the three versions of IsInsideBuffer appear
print(interp.IsInsideBuffer. __doc__ )

# The following line calls the "point version" of IsInsideBuffer and works correctly
print(interp.IsInsideBuffer([1, 2, 3]))

# The line below fails, as IsInsideBuffer excepts ints or longs
print(interp.IsInsideBuffer([1.5, 2.5, 3.5]))

# To force the function to be called with a continuous index instead, I manually create one
cindex = itk.ContinuousIndex[itk.D, 3]()
cindex[0] = 1.5
cindex[1] = 2.5
cindex[2] = 3.5
# …but IsInsideBuffer still fails
print(interp.IsInsideBuffer(cindex)) # error

# The same happens with points instead of continuous index
point = itk.Point[itk.D, 3]()
point[0] = 1.5
point[1] = 2.5
point[2] = 3.5
print(interp.IsInsideBuffer(point)) # error

```

The error is the following:

```auto
ValueError: Expecting a sequence of int (or long)

```

Is there a trick to call the proper version of `IsInsideBuffer` from Python? Or is it a bug in the way this function is wrapped? Sorry if this is a silly question, but I could not find a way to call the function as I need.

Thank you very much!

---

<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: [April 16, 2025, 1:51pm UTC](https://discourse.itk.org/t/improper-wrapping-of-imagefunction-isinsidebuffer/7495/2 "2025-04-16T13:51:20Z")

</div>

I was able to reproduce this with a recent master version:

```log
C:\Users\Dzenan>"C:\Program Files\Python311\python.exe"
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import itk
>>> import itk
>>> import numpy as np
>>>
>>> image = itk.GetImageFromArray(np.full((200, 200, 200), 1.))
>>> interp = itk.LinearInterpolateImageFunction.New(image) # concrete subclass of ImageFunction
>>>
>>> # From the doc, the three versions of IsInsideBuffer appear
>>> print(interp.IsInsideBuffer. __doc__ )

        IsInsideBuffer(self, index) -> bool

        Parameters
        ----------
        index: itkIndex3 const &

        IsInsideBuffer(self, index) -> bool

        Parameters
        ----------
        index: itkContinuousIndexD3 const &

        IsInsideBuffer(self, point) -> bool

        Parameters
        ----------
        point: itkPointD3 const &

>>>
>>> # The following line calls the "point version" of IsInsideBuffer and works correctly
>>> print(interp.IsInsideBuffer([1, 2, 3]))
True
>>>
>>> # The line below fails, as IsInsideBuffer excepts ints or longs
>>> print(interp.IsInsideBuffer([1.5, 2.5, 3.5]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\itkImageFunctionBasePython.py", line 1259, in IsInsideBuffer
    return _itkImageFunctionBasePython.itkImageFunctionID3DD_IsInsideBuffer(self, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Expecting a sequence of int (or long)
>>>
>>> # To force the function to be called with a continuous index instead, I manually create one
>>> cindex = itk.ContinuousIndex[itk.D, 3]()
>>> cindex[0] = 1.5
>>> cindex[1] = 2.5
>>> cindex[2] = 3.5
>>> # …but IsInsideBuffer still fails
>>> print(interp.IsInsideBuffer(cindex)) # error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\itkImageFunctionBasePython.py", line 1259, in IsInsideBuffer
    return _itkImageFunctionBasePython.itkImageFunctionID3DD_IsInsideBuffer(self, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Expecting a sequence of int (or long)
>>>
>>> # The same happens with points instead of continuous index
>>> point = itk.Point[itk.D, 3]()
>>> point[0] = 1.5
>>> point[1] = 2.5
>>> point[2] = 3.5
>>> print(interp.IsInsideBuffer(point)) # error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\itkImageFunctionBasePython.py", line 1259, in IsInsideBuffer
    return _itkImageFunctionBasePython.itkImageFunctionID3DD_IsInsideBuffer(self, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Expecting a sequence of int (or long)
>>> itk. __version__'6.0.0'
>>> itk. __file__'C:\\Dev\\ITK-py11\\Wrapping\\Generators\\Python\\itk\\ __init__.py'
>>>

```

I turned your code into a unit test via this (currently draft) PR:

> <https://github.com/InsightSoftwareConsortium/ITK/pull/5310>
>
> Based on code provided on the forum: https://discourse.itk.org/t/improper-wrappi…ng-of-imagefunction-isinsidebuffer/7495
> 
> 
> \## PR Checklist
> \- \[x\] No \[API changes\](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md#breaking-changes) were made (or the changes have been approved)
> \- \[x\] No \[major design changes\](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md#design-changes) were made (or the changes have been approved)
> \- \[x\] Added test (or behavior not changed)
> \- \[x \] Added Python wrapping to new files (if any) as described in \[ITK Software Guide\](https://itk.org/ItkSoftwareGuide.pdf) Section 9.5

@matt.mccormick Can you figure out what is going on here?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 16, 2025, 2:47pm UTC](https://discourse.itk.org/t/improper-wrapping-of-imagefunction-isinsidebuffer/7495/3 "2025-04-16T14:47:03Z")

</div>

@dzenanz go for it.

---

<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: [April 16, 2025, 3:23pm UTC](https://discourse.itk.org/t/improper-wrapping-of-imagefunction-isinsidebuffer/7495/4 "2025-04-16T15:23:42Z")

</div>

I meant, I took a look and nothing stood out to me. Can you take a look too?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 16, 2025, 4:05pm UTC](https://discourse.itk.org/t/improper-wrapping-of-imagefunction-isinsidebuffer/7495/5 "2025-04-16T16:05:34Z")

</div>

Nothing stands out to me.
