Nonlinear Transforms

Nonlinear transforms.

class nitransforms.nonlinear.BSplineFieldTransform(coefficients, reference=None, order=3)[source]

Represent a nonlinear transform parameterized by BSpline basis.

apply(spatialimage, reference=None, order=3, mode='constant', cval=0.0, prefilter=True, output_dtype=None)[source]

Apply a B-Spline transform on input data.

map(x, inverse=False)[source]

Apply the transformation to a list of physical coordinate points.

\[\mathbf{y} = \mathbf{x} + \Psi^3(\mathbf{k}, \mathbf{x}), \label{eq:1}\tag{1}\]
Parameters
  • x (N x D numpy.ndarray) – Input RAS+ coordinates (i.e., physical coordinates).

  • inverse (bool) – If True, apply the inverse transform \(x = f^{-1}(y)\).

Returns

y – Transformed (mapped) RAS+ coordinates (i.e., physical coordinates).

Return type

N x D numpy.ndarray

Examples

>>> xfm = BSplineFieldTransform(test_dir / "someones_bspline_coefficients.nii.gz")
>>> xfm.reference = test_dir / "someones_anatomy.nii.gz"
>>> xfm.map([-6.5, -36., -19.5]).tolist()
[[-6.5, -31.476097418406784, -19.5]]
>>> xfm.map([[-6.5, -36., -19.5], [-1., -41.5, -11.25]]).tolist()
[[-6.5, -31.476097418406784, -19.5], [-1.0, -3.8072675377121996, -11.25]]
to_field(reference=None, dtype='float32')[source]

Generate a displacements deformation field from this B-Spline field.

class nitransforms.nonlinear.DisplacementsFieldTransform(field, reference=None)[source]

Represents a dense field of displacements (one vector per voxel).

map(x, inverse=False)[source]

Apply the transformation to a list of physical coordinate points.

\[\mathbf{y} = \mathbf{x} + D(\mathbf{x}), \label{eq:2}\tag{2}\]

where \(D(\mathbf{x})\) is the value of the discrete field of displacements \(D\) interpolated at the location \(\mathbf{x}\).

Parameters
  • x (N x D numpy.ndarray) – Input RAS+ coordinates (i.e., physical coordinates).

  • inverse (bool) – If True, apply the inverse transform \(x = f^{-1}(y)\).

Returns

y – Transformed (mapped) RAS+ coordinates (i.e., physical coordinates).

Return type

N x D numpy.ndarray

Examples

>>> xfm = DisplacementsFieldTransform(test_dir / "someones_displacement_field.nii.gz")
>>> xfm.map([-6.5, -36., -19.5]).tolist()
[[-6.5, -36.475167989730835, -19.5]]
>>> xfm.map([[-6.5, -36., -19.5], [-1., -41.5, -11.25]]).tolist()
[[-6.5, -36.475167989730835, -19.5], [-1.0, -42.038356602191925, -11.25]]