# Ordering of BSplineTransform Parameters

**URL:** <https://discourse.itk.org/t/ordering-of-bsplinetransform-parameters/5989>\
**Category:** Beginner Questions\
**Created:** [June 13, 2023, 3:24pm UTC](https://discourse.itk.org/t/ordering-of-bsplinetransform-parameters/5989 "2023-06-13T15:24:41Z")\
**Posts on this page:** 3\
**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:** [June 13, 2023, 3:24pm UTC](https://discourse.itk.org/t/ordering-of-bsplinetransform-parameters/5989/1 "2023-06-13T15:24:41Z")

</div>

I got myself confused with the ordering of the parameters of the BSplineTransform. At some point I wrote it down but cannot find that anymore, and now I’m looking at some code that I have written some years ago and don’t know how that worked 😅

I know for sure that the flattened array of the parameters is `[x0 x1 .. xn y0 y1 .. yn z0 z1 .. zn]` but what is the order of the coordinates of the control points? I.e., is the x coordinate the fast coordinate or the z coordinate?

[ITK: itk::BSplineTransform\< TParametersValueType, VDimension, VSplineOrder \> Class Template Reference](https://itk.org/Doxygen/html/classitk_1_1BSplineTransform.html) says that

> The user specifies the parameters as one flat array: each N-D grid is represented by an array in the same way an N-D image is represented in the buffer; the N arrays are then concatenated together to form a single array.

and from [C order or F order？ - #2 by dzenanz](https://discourse.itk.org/t/c-order-or-f-order/5287/2) I read, that the order of N-D images is C - thus the z-coordinate is the fastest, correct?

Thus, if I use this code:

```auto
import numpy as np
import SimpleITK as sitk

s = sitk.BSplineTransform(3, 3)
# np.array(s.GetParameters()).reshape(-1, 3, order='C') # edit: no, not like that!
np.vstack(np.split(np.array(tx.GetParameters()), tx.GetDimension())).T

```

I would get the control point displacements in the following order of control points indices of the grid:

```auto
x, y, z
-------
0, 0, 0
0, 0, 1
0, 0, 2
0, 0, 3
0, 1, 0
0, 1, 1
...
0, 3, 3
1, 0, 0
1, 0, 1
...
3, 3, 3

```

Is that correct?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [June 13, 2023, 6:21pm UTC](https://discourse.itk.org/t/ordering-of-bsplinetransform-parameters/5989/2 "2023-06-13T18:21:12Z")

</div>

ITK’s usual layout means that X index varies the fastest in memory - which is the same for most (all?) the libraries.

---

<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:** [June 13, 2023, 7:10pm UTC](https://discourse.itk.org/t/ordering-of-bsplinetransform-parameters/5989/3 "2023-06-13T19:10:09Z")

</div>

okay, thanks! So if I do it like that, the ordering is not like I wrote initially but

```auto
0, 0, 0
1, 0, 0
...
3, 0, 0
3, 1, 0
...
3, 3, 3

```

I did some tests in between by reshaping the individual x, y, and z arrays to the respective grid sizes and then selecting the elements manually and it seems to be indeed that the x coordinate is the fastest - if I did no mistake in between 😅

Thanks again for untangling the knot in my brain 🙂
