Ordering of BSplineTransform Parameters

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 :sweat_smile:

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 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 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:

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:

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?

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

1 Like

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

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 :sweat_smile:

Thanks again for untangling the knot in my brain :slight_smile:

1 Like