# InterpolateImageFunction of templated PixelType

**URL:** https://discourse.itk.org/t/interpolateimagefunction-of-templated-pixeltype/1729
**Category:** Algorithms
**Tags:** scalar, interpolator, pixeltype, vector
**Created:** [April 2, 2019, 9:22am UTC](https://discourse.itk.org/t/interpolateimagefunction-of-templated-pixeltype/1729 "2019-04-02T09:22:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Gordian](https://discourse.itk.org/user_avatar/discourse.itk.org/gordian/32/335_2.png) [@Gordian](https://discourse.itk.org/u/Gordian)
#### Post date: [April 2, 2019, 9:22am UTC](https://discourse.itk.org/t/interpolateimagefunction-of-templated-pixeltype/1729/1 "2019-04-02T09:22:45Z")

</div>

Hello,

if I want to use an ImageInterpolatorFunction (Linear or NearestNeighbor) for an image with PixelType that can be either scalar or a vector.  
The PixelType is determined at compile time because the function template get the PixelType. Using PixelType and known dimension I typedef an ImageType.

Based on the PixelType i would like to typedef the interpolator like this  
`using Interpolator = itk::SOMEInterpolateImageFunction< TInputImage, TCoordRep>`

for the [LinearInterpolateImageFunction](https://itk.org/Doxygen/html/classitk_1_1LinearInterpolateImageFunction.html) the documentation states: " This function works for images with scalar and vector pixel types, and for images of type [VectorImage](https://itk.org/Doxygen/html/classitk_1_1VectorImage.html)."

- Why does another class [VectorLinearInterpolateImageFunction](https://itk.org/Doxygen/html/classitk_1_1VectorLinearInterpolateImageFunction.html) exist?

For the [NearestNeighborInterpolateImageFunction](https://itk.org/Doxygen/html/classitk_1_1NearestNeighborInterpolateImageFunction.html) the documentation states: " [NearestNeighborInterpolateImageFunction](https://itk.org/Doxygen/html/classitk_1_1NearestNeighborInterpolateImageFunction.html) interpolates image intensity at a non-integer pixel position by copying the intensity for the nearest neighbor. This class is templated over the input image type and the coordinate representation type (e.g. float or double)."

- Why does this class do not have the abilities like [LinearInterpolateImageFunction](https://itk.org/Doxygen/html/classitk_1_1LinearInterpolateImageFunction.html) to be functional with vector pixel types?

---

<div class="post-metadata">

### Author: ![fbudin](https://discourse.itk.org/user_avatar/discourse.itk.org/fbudin/32/14_2.png) [@fbudin](https://discourse.itk.org/u/fbudin)
#### Post date: [April 2, 2019, 1:11pm UTC](https://discourse.itk.org/t/interpolateimagefunction-of-templated-pixeltype/1729/2 "2019-04-02T13:11:01Z")

</div>

Hello @Gordian,

My guess is that `LinearInterpolateImageFunction` did not support vector types at first. I looked through the history of the file and I saw a commit where `VectorImage` was added. I guess it was the same at some point for images with vector pixel type. So `VectorLinearInterpolateImageFunction` should probably be deprecated to avoid duplication and confusion.

`NearestNeighborInterpolateImageFunction` on the other hand may never have been improved to support images with vector pixels. I haven’t tried, maybe it already works. If not, I suspect that it would not be too difficult to add that support. `LinearInterpolateImageFunction` could serve as a model if necessary. Want to give it a try?

Thanks,  
Francois

---

<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 2, 2019, 4:17pm UTC](https://discourse.itk.org/t/interpolateimagefunction-of-templated-pixeltype/1729/3 "2019-04-02T16:17:48Z")

</div>

I think @blowekamp added vector support to `LinearInterpolateImageFunction`. Maybe he has more information?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [April 2, 2019, 4:26pm UTC](https://discourse.itk.org/t/interpolateimagefunction-of-templated-pixeltype/1729/4 "2019-04-02T16:26:34Z")

</div>

Usually operations like nearest neighbor just return the value at an index, so there was never a need for special handling for vector pixels types. I’d guess it always just worked with any pixel type.

Originally, Image of itk::Vector types has separate classes for many operations. As compilers improved and more advanced template programming could be used the basic classes became more robust with different pixel types.

Then with SimpleITK using the “VectorImage” type, many more filters and functions were improved to support this image class which supports a run time number of components per pixel.

We also still have the VectorResampleImageFilter and many other specialized tools that could be deprecated.
