Bilinear interpolation behavior SimpleITK

Hi,

This code bilinear_inter.py · GitHub compares how linear interpolation is implemented in opencv, pytorch and simpleitk libraries.

The input array is:
[[1, 2],
[3, 4]]

The output of this script is the following:

cv2:
[[1. 1.25 1.75 2. ]
[1.5 1.75 2.25 2.5 ]
[2.5 2.75 3.25 3.5 ]
[3. 3.25 3.75 4. ]]

torch (no align corners):
tensor([[[[1.0000, 1.2500, 1.7500, 2.0000],
[1.5000, 1.7500, 2.2500, 2.5000],
[2.5000, 2.7500, 3.2500, 3.5000],
[3.0000, 3.2500, 3.7500, 4.0000]]]])

torch (align corners):
tensor([[[[1.0000, 1.3333, 1.6667, 2.0000],
[1.6667, 2.0000, 2.3333, 2.6667],
[2.3333, 2.6667, 3.0000, 3.3333],
[3.0000, 3.3333, 3.6667, 4.0000]]]])

sitk:
[[1. 1.5 2. 0. ]
[2. 2.5 3. 0. ]
[3. 3.5 4. 0. ]
[0. 0. 0. 0. ]]

cv2 does not align corners while pytorch gives the choice (align_corners parameter).

However, I don’t understand why SimpleITK gives such an output… I’d like to know what’s wrong in my code (bilinear_inter.py · GitHub).

Thanks

Hello,

Please review SimpleITK’s Fundamental Concepts on the Image:
https://simpleitk.readthedocs.io/en/master/fundamentalConcepts.html#images

I’d recommend drawing the original input image, including its origin, and identifying the locations of the corners of the image. Then doing the same for the output image you are requesting from the ResampleImageFilter.

resample.SetOutputOrigin((-0.25, -0.25))

thanks @blowekamp