Interpolating vector image with itk python

I am currently trying to get the interpolated vector at a subpixel location using the itk.LinearInterpolateImageFunction in python. It was my understanding that this function is supposed to support both vector and scalar images (as it seems itk.VectorLinearInterpolateImageFunction doesnt exist in the python wrapper?)

However, when I use this function, it returns a scalar, when I expect that it would return an interpolated vector at the given location.

If I create an example image as follows:

dim = 3
component = itk.ctype("float")
PixelType = itk.Vector[component, dim]
ImageType = itk.Image[PixelType, dim]
im = ImageType.New()

start = itk.Index[dim]()
start[0] = 0
start[1] = 0
start[2] = 0

size = itk.Size[dim]()
size[0] = 200
size[1] = 200
size[2] = 200

region = itk.ImageRegion[dim]()
region.SetSize(size)
region.SetIndex(start)

im.SetRegions(region)
im.Allocate()

vectorValue = PixelType()
vectorValue[0] = 10
vectorValue[1] = 10
vectorValue[2] = 10
im.FillBuffer(vectorValue)

then define the interpolator and evaluate

interpolator = itk.LinearInterpolateImageFunction.New(im)
interpolator.EvaluateAtContinuousIndex([0,0,0])

The result I get is

10.0

when I expect the result to be similar to

im.GetPixel([0,0,0])

itkVectorF3 ([10, 10, 10])

How can I achieve this result?

Trying to instantiate this: interpolator = itk.LinearInterpolateImageFunction[ImageType].New(im) results in a traceback with a useful error message:

Traceback (most recent call last):
  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\support\template_class.py", line 525, in __getitem__
    this_item = self.__template__[key]
                ~~~~~~~~~~~~~~~~~^^^^^
KeyError: (<class 'itk.itkImagePython.itkImageVF33'>,)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\support\template_class.py", line 529, in __getitem__
    raise itk.TemplateTypeError(self, key)
itk.support.extras.TemplateTypeError: itk.LinearInterpolateImageFunction is not wrapped for input type `itk.Image[itk.Vector[itk.F,3],3]`.

To limit the size of the package, only a limited number of
types are available in ITK Python. To print the supported
types, run the following command in your python environment:

    itk.LinearInterpolateImageFunction.GetTypes()

Possible solutions:
* If you are an application user:
** Convert your input image into a supported format (see below).
** Contact developer to report the issue.
* If you are an application developer, force input images to be
loaded in a supported pixel type.

    e.g.: instance = itk.LinearInterpolateImageFunction[itk.Image[itk.SS,2], itk.D].New(my_input)

* (Advanced) If you are an application developer, build ITK Python yourself and
turned to `ON` the corresponding CMake option to wrap the pixel type or image
dimension you need. When configuring ITK with CMake, you can set
`ITK_WRAP_${type}` (replace ${type} with appropriate pixel type such as
`double`). If you need to support images with 4 or 5 dimensions, you can add
these dimensions to the list of dimensions in the CMake variable
`ITK_WRAP_IMAGE_DIMS`.

Supported input types:

itk.Image[itk.SS,2]
itk.Image[itk.UC,2]
itk.Image[itk.F,2]
itk.Image[itk.Vector[itk.F,2],2]
itk.Image[itk.CovariantVector[itk.F,2],2]
itk.Image[itk.RGBPixel[itk.UC],2]
itk.Image[itk.RGBAPixel[itk.UC],2]
itk.Image[itk.SS,3]
itk.Image[itk.UC,3]
itk.Image[itk.F,3]
itk.Image[itk.Vector[itk.F,3],3]
itk.Image[itk.CovariantVector[itk.F,3],3]
itk.Image[itk.RGBPixel[itk.UC],3]
itk.Image[itk.RGBAPixel[itk.UC],3]
itk.PhasedArray3DSpecialCoordinatesImage[itk.F]
itk.PhasedArray3DSpecialCoordinatesImage[itk.UC]

>>> print(ImageType)
<class 'itk.itkImagePython.itkImageVF33'>

So try to construct ImageType as one of the types wrapped by LinearInterpolateImageFunction.

If I copy an image type from the error output

ImageType = itk.Image[itk.Vector[itk.F,3],3]

and try

interpolator = itk.LinearInterpolateImageFunction[ImageType].New(im)

(After assigning im to ImageType)

I still get

itk.LinearInterpolateImageFunction is not wrapped for input type itk.Image[itk.Vector[itk.F,3],3]

even though it seems it should be a supported type?

Also I am a bit surprised that itk.Image[itk.Vector[itk.F,3],3] is not equivalent to

dim = 3
component = itk.F
PixelType = itk.Vector[component, dim]
ImageType = itk.Image[PixelType, dim]

which gives me itk.itkImagePython.itkImageVF33

@matt.mccormick do you have some advice?

Actually, just to note, after assigning

ImageType = itk.Image[itk.Vector[itk.F,3],3]
im = ImageType.New()

‘type(im)’ still gives

itk.itkImagePython.itkImageVF33

and also just inspecting ImageType after assigning it itk.Image[itk.Vector[itk.F,3],3] also results in it being cast? to

itk.itkImagePython.itkImageVF33