 # Unexpected Behavior of LinearInterpolateImageFunction

Here is an example of using the LineageInterpolateImageFunction from the ITKSphinxExamples repository:
https://itk.org/ITKExamples/src/Core/ImageFunction/LinearlyInterpolatePositionInImage/Documentation.html

In this example, a continuous value of 1.3 is located between index1 and index2 and at a distance of 0.3. Since the pixel values are 10 and 20 at these two indices, you get an output of 13.

However, if we change the image spacing to 0.5, the continuous position of 1.3 would be one would expect a different output of (0.7 x 20 + 0.3 x 30) = 23. But it appears that the interpolate function does not take into account image spacing. This is a problem because if we have different spacings in X, Y and Z (as is the case in microscopy modalities), the interpolation result wont be accurate.

Kishore

Linear interpolation works fine. ITK uses convention that pixel’s location designates its center, not a corner. See ITKSoftwareGuide-Book1, section 4.1.4 (Defining Origin and Spacing) and possibly ITKSoftwareGuide-Book2, chapter 3.

That example should be remade to have non-unit spacing to better demonstrate the math.

P.S. Now I see that you made an error in your math. With pixel spacing of 0.5, location 1.3 no longer falls 30% into a pixel.

Unit spacing:

• pixel 0 has extent -0.5, 0.5
• pixel 1 has extent 0.5, 1.5
• pixel 2 has extent 1.5, 2.5

Physical location 1.3 is 30% of spacing away from center of pixel 1 and 70% of spacing away from center of pixel 2.

Spacing 0.5:

• pixel 0 has extent -0.25, 0.25
• pixel 1 has extent 0.25, 0.75
• pixel 2 has extent 0.75, 1.25
• pixel 3 has extent 1.25, 1.75

Physical location 1.3 is 40% of spacing away from center of pixel 3 and 60% of spacing away from center of pixel 2.

@krm15 do you want to propose a PR to update that example with the above math?

@dzenanz : Yes, I got the convention correct now – thank you!

But even then, going by your calculation for the spacing of 0.5, the pixel value is 0.6 x 30 (pixel 3) + 0.4 x 20 (pixel 2) = 26. The answer we get from the code block is 13 irrespective of what the image spacing is set to.

How do I propose a PR?