# sitkBSpline vs sitkBSplineResampler

**URL:** https://discourse.itk.org/t/sitkbspline-vs-sitkbsplineresampler/3390
**Category:** Beginner Questions
**Tags:** simpleitk
**Created:** [August 13, 2020, 7:38am UTC](https://discourse.itk.org/t/sitkbspline-vs-sitkbsplineresampler/3390 "2020-08-13T07:38:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![reox](https://discourse.itk.org/user_avatar/discourse.itk.org/reox/32/4490_2.png) [@reox](https://discourse.itk.org/u/reox)
#### Post date: [August 13, 2020, 7:38am UTC](https://discourse.itk.org/t/sitkbspline-vs-sitkbsplineresampler/3390/1 "2020-08-13T07:38:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [August 13, 2020, 1:29pm UTC](https://discourse.itk.org/t/sitkbspline-vs-sitkbsplineresampler/3390/2 "2020-08-13T13:29:21Z")

</div>

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:

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

```

Possibly @blowekamp has additional insights.

---

<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: [August 13, 2020, 1:54pm UTC](https://discourse.itk.org/t/sitkbspline-vs-sitkbsplineresampler/3390/3 "2020-08-13T13:54:16Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![reox](https://discourse.itk.org/user_avatar/discourse.itk.org/reox/32/4490_2.png) [@reox](https://discourse.itk.org/u/reox)
#### Post date: [August 13, 2020, 4:45pm UTC](https://discourse.itk.org/t/sitkbspline-vs-sitkbsplineresampler/3390/4 "2020-08-13T16:45:11Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![warfield](https://discourse.itk.org/letter_avatar_proxy/v4/letter/w/8edcca/32.png) [@warfield](https://discourse.itk.org/u/warfield)
#### Post date: [August 13, 2020, 5:48pm UTC](https://discourse.itk.org/t/sitkbspline-vs-sitkbsplineresampler/3390/5 "2020-08-13T17:48:23Z")

</div>

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](http://bigwww.epfl.ch/publications/thevenaz9901.pdf)

Especially the discussion around Equation 4 is interesting.

---

<div class="post-metadata">

### Author: ![reox](https://discourse.itk.org/user_avatar/discourse.itk.org/reox/32/4490_2.png) [@reox](https://discourse.itk.org/u/reox)
#### Post date: [August 14, 2020, 5:23am UTC](https://discourse.itk.org/t/sitkbspline-vs-sitkbsplineresampler/3390/6 "2020-08-14T05:23:03Z")

</div>

ah okay, _those_ coefficients 🙂

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