sitkBSpline vs sitkBSplineResampler

I noticed that when resampling an image using sitkBSpline, the background would not always be zero.
Here is an example:

import SimpleITK as sitk
import numpy as np
x = np.zeros((20,20))
x[5:15,5:15] = 1
img = sitk.GetImageFromArray(x)
tx = sitk.Euler2DTransform()
tx.SetAngle(np.deg2rad(30))
out = sitk.Resample(img, tx, sitk.sitkBSpline)
out2 = sitk.Resample(img, tx, sitk.sitkBSplineResampler)
plt.imshow(sitk.GetArrayFromImage(out)); plt.show()
plt.imshow(sitk.GetArrayFromImage(out2)); plt.show()

Interestingly, using sitkBSpline creates values less than 0 and greater than 1, which is not the case for sitkBSplineResampler.
The documentation says that the latter interpolator should only be used for ā€˜a BSpline coefficient imageā€™, however for me it looks like that it produces the better results? Especially as I would not suspect that the resampler introduces higher or lower values which were in the image before.

Is it save to use the sitkBSplineResampler as a default resampler instead of sitkBSpline, or is there any caveat Iā€™m not aware of?

Iā€™m using
SimpleITK Version: 2.0.0rc1.post287
Build Date: Jun 19 2020 02:53:28
ITK Version: 5.1

Hello @reox,

I think these are just variants of the same interpolation. You can probably use the sitkBSplineResampler.

Also, I suggest you set the default pixel value to something other than zero, you want to differentiate between pixels coming from interpolation and those from outside the image bounds:

out = sitk.Resample(img, tx, sitk.sitkBSpline, defaultPixelValue=-3)
out2 = sitk.Resample(img, tx, sitk.sitkBSplineResampler, defaultPixelValue=-3)

Possibly @blowekamp has additional insights.

These interpolators are different.

The regular sitkBSpline interpolates the image with constructed coefficients to represent the intensities. While the sitkBSplineResampler using the image as coefficients to interpolate the results.

I would recommend only using sitkBSplineResampler to resample coefficient images as per the documentaiton.

1 Like

Thank you for the answer!
Iā€™m not sure if I understand ā€œcoefficient imageā€ correctly, as I never heard that term before and can not make sense from it by looking at literatureā€¦ Could you hint me to some literature explaining that or is there a synonym for it?

The main point is that there is a distinction between the signal intensities estimated from the coefficients of the b-spline representation of an image, and the coefficients of the b-spline representation of an image.

Please see this very nice paper : http://bigwww.epfl.ch/publications/thevenaz9901.pdf

Especially the discussion around Equation 4 is interesting.

1 Like

ah okay, those coefficients :slight_smile:

Thank you all for the answers, they were very helpful!

1 Like