# Parameters in BSplineTransform

**URL:** <https://discourse.itk.org/t/parameters-in-bsplinetransform/3395>\
**Category:** Algorithms\
**Tags:** bspline, parameters, registration, python\
**Created:** [August 17, 2020, 4:16am UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395 "2020-08-17T04:16:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![prms](https://discourse.itk.org/user_avatar/discourse.itk.org/prms/32/1526_2.png) [@prms](https://discourse.itk.org/u/prms)\
**Post date:** [August 17, 2020, 4:16am UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/1 "2020-08-17T04:16:08Z")

</div>

I’m trying to register images using BSplineTransform. I’m not clear about the total number of parameters in case of BSplineTransform. In the case of AffineTransform, for 3D images, there are 12 parameters and I can count them as the parameters from translation and affine matrix. Can the number of parameters in BSplineTransform be understood in the same way? For a `BSplineTransform` consisting of cubic spline for the 2D image, the number of parameters is 32. Can someone guide me to some relevant literature regarding the parameters of BSplineTransform or provide some intuition. I have some understanding of BSpline curves, control points and their formation. However, I am not able to get the reasoning behind the total number of parameters while using `BSplineTransform` in sitk. Thanks in advance 🙂

---

<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 17, 2020, 1:25pm UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/2 "2020-08-17T13:25:17Z")

</div>

Hello @prms,

The number of parameters of your BSpline transform depends on your settings, it isn’t a constant as with the 3D Affine. It is defined by the grid mesh size `SetTransformDomainMeshSize` and the spline order specified in the `BSplineTransform` constructor.

For example if we set the mesh size for a 2D `BSplineTransform` to `[4,3]` and use a cubic spline order then the actual mesh size used becomes `[4+3, 3+3]`, and as we are in 2D the total number of parameters is `7*6*2`. The parameters denote the delta/motion of the control points from their original positions. The more complex the deformation you need, the more control points and thus more parameters. For additional details, please take a look at the [original ITK documentation](https://itk.org/Doxygen/html/classitk_1_1BSplineTransform.html), section titled “Detailed Description”.

---

<div class="post-metadata">

**Author:** ![prms](https://discourse.itk.org/user_avatar/discourse.itk.org/prms/32/1526_2.png) [@prms](https://discourse.itk.org/u/prms)\
**Post date:** [August 20, 2020, 6:30am UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/3 "2020-08-20T06:30:07Z")

</div>

Thanks @zivy :). You’ve been of great help.

---

<div class="post-metadata">

**Author:** ![fepegar](https://discourse.itk.org/user_avatar/discourse.itk.org/fepegar/32/1664_2.png) [@fepegar](https://discourse.itk.org/u/fepegar)\
**Post date:** [August 21, 2020, 11:46pm UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/4 "2020-08-21T23:46:04Z")

</div>

Hey, @prms. You can play with this gist I made some months ago to understand this myself: [https://gist.github.com/fepegar/b723d15de620cd2a3a4dbd71e491b59d](https://gist.github.com/fepegar/b723d15de620cd2a3a4dbd71e491b59d)

---

<div class="post-metadata">

**Author:** ![prms](https://discourse.itk.org/user_avatar/discourse.itk.org/prms/32/1526_2.png) [@prms](https://discourse.itk.org/u/prms)\
**Post date:** [September 12, 2020, 3:37pm UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/5 "2020-09-12T15:37:35Z")

</div>

Thanks…great resource

---

<div class="post-metadata">

**Author:** ![ibr](https://discourse.itk.org/user_avatar/discourse.itk.org/ibr/32/468_2.png) [@ibr](https://discourse.itk.org/u/ibr)\
**Post date:** [September 13, 2020, 7:06pm UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/6 "2020-09-13T19:06:39Z")

</div>

The parameters of the B-spline transform are the control points ( B-spline coefficients). ITK implementation is based on Unser paper. EPFL website offers nice presentations like [this](http://bigwww.epfl.ch/tutorials/unser_icip_05.pdf), and also an [open-source](http://bigwww.epfl.ch/thevenaz/interpolation/) for the implementation as well.

---

<div class="post-metadata">

**Author:** ![prms](https://discourse.itk.org/user_avatar/discourse.itk.org/prms/32/1526_2.png) [@prms](https://discourse.itk.org/u/prms)\
**Post date:** [September 17, 2020, 5:05pm UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/7 "2020-09-17T17:05:15Z")

</div>

Hi @zivy, what is the reason behind adding spline order to mesh size? Can you point me to any reference/paper/maths that is used in SITK implementation of BSplineTransform?

Thanks,

---

<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:** [September 17, 2020, 5:46pm UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/8 "2020-09-17T17:46:33Z")

</div>

Hi @prms,

This has to do with the treatment of the endpoints of the BSpline knot sequence, so that they have full support. For a brief overview [see wikipedia](https://en.wikipedia.org/wiki/B-spline). If you are really interested in the mathematics underlying BSplines I suggest reading the [B(asic)-Spline Basics](https://www.cs.unc.edu/~dm/UNC/COMP258/Papers/bsplbasic.pdf) by Carl de Boor.

---

<div class="post-metadata">

**Author:** ![prms](https://discourse.itk.org/user_avatar/discourse.itk.org/prms/32/1526_2.png) [@prms](https://discourse.itk.org/u/prms)\
**Post date:** [November 6, 2020, 11:45am UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/9 "2020-11-06T11:45:59Z")

</div>

Hi @zivy. Thank you very much for your help. I have a question regarding the fixed parameters of BSplineTransform. I am able to figure out only the direction information and physical dimensions. What are other values besides them?  
`(4.0, 4.0, 4.0, -103.73715145372455, -202.6718723955285, -141.98029754218416, 111.20492252847637, 111.20492553856869, 125.05145394429641, 0.7835580706596375, 0.26198989152908325, -0.5633809566497803, 0.03123663179576397, 0.888992965221405, 0.45685410499572754, 0.6205328702926636, -0.3755699396133423, 0.6883939504623413)`

For this set of fixed parameters, last 9 are direction cosines, values from position 7 to 9 are physical dimensions. What do the first 6 values denote? This might be a basic question. I looked for this in the doc but couldn’t get the answer.

---

<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:** [November 6, 2020, 2:55pm UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/10 "2020-11-06T14:55:27Z")

</div>

Hello @prms,

Most people aren’t interested in this as it has to do with the inner workings of the transformation, good to see someone interested in the details:

1. First three or two parameters, depending on dimensionality, are the number of control points used by the BSpline, this depends on the mesh size you specify and the spline order (number\_of\_control\_points = mesh\_size + spline\_order). The default spline order is three.
2. The second three/two parameters are the physical coordinates of the first control point. This is dependent on the user selected mesh\_size, origin and spline order. For instance if your spline order is three, there is one control point added before your original specified mesh (two added at the other end). Using the origin as the location of the user specified mesh, the first control point is located at origin-mesh\_spacing.

For further details please see the [ITK documentation](https://itk.org/Doxygen/html/classitk_1_1BSplineTransform.html).

---

<div class="post-metadata">

**Author:** ![Ray\_Jian](https://discourse.itk.org/user_avatar/discourse.itk.org/ray_jian/32/1799_2.png) [@Ray\_Jian](https://discourse.itk.org/u/Ray_Jian)\
**Post date:** [December 20, 2022, 2:19pm UTC](https://discourse.itk.org/t/parameters-in-bsplinetransform/3395/11 "2022-12-20T14:19:34Z")

</div>

Hi @zivy ,

could you also elaborate what is the meaning of DomainPhysicalDimensions? I looked into the ITK documentation but it didn’t have a detailed explanation.

I am trying to load a control point grid .nii image obtained from NiftyReg in SimpleITK as BSplineTransform and use TransformToDisplacementFieldFilter to get the dense displacement field.

```auto
ctrl_grid = sitk.ReadImage("grid_file.nii")
bspline_transform = sitk.BSplineTransform(dimensions=3,order=3)
bspline_transform.SetTransformDomainOrigin(ctrl_grid.GetOrigin())
bspline_transform.SetTransformDomainDirection(ctrl_grid.GetDirection())
bspline_transform.SetTransformDomainMeshSize((55-3,55-3,55-3))
bspline_transform.SetTransformDomainPhysicalDimensions( **figuring out what to put here** )
bspline_transform.SetParameters(sitk.GetArrayFromImage(ctrl_grid)

```

Image meta information:  
size:(256,256,256)  
spacing:(1mm,1mm,1mm)  
Control point grid:  
size:(55,55,55)  
spacing:(5mm,5mm,5mm)

Thanks a lot!
