Nonlinear Transforms
Nonlinear transforms.
- class nitransforms.nonlinear.BSplineFieldTransform(coefficients, reference=None, order=3)[source]
Represent a nonlinear transform parameterized by BSpline basis.
- 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.476097418406..., -19.5]]
>>> xfm.map([[-6.5, -36., -19.5], [-1., -41.5, -11.25]]).tolist() [[-6.5, -31.4760974184..., -19.5], [-1.0, -3.807267537712..., -11.25]]
- property ndim
Get the dimensions of the transform.
- class nitransforms.nonlinear.DenseFieldTransform(field=None, is_deltas=True, reference=None)[source]
Represents dense field (voxel-wise) transforms.
- map(x, inverse=False)[source]
Apply the transformation to a list of physical coordinate points.
\[\mathbf{y} = \mathbf{x} + \Delta(\mathbf{x}), \label{eq:2}\tag{2}\]where \(\Delta(\mathbf{x})\) is the value of the discrete field of displacements \(\Delta\) interpolated at the location \(\mathbf{x}\).
- Parameters:
x (N x D
numpy.array_like
) – Input RAS+ coordinates (i.e., physical coordinates).inverse (
bool
) – IfTrue
, apply the inverse transform \(x = f^{-1}(y)\).
- Returns:
y – Transformed (mapped) RAS+ coordinates (i.e., physical coordinates).
- Return type:
N x D
numpy.array_like
Examples
>>> xfm = DenseFieldTransform( ... test_dir / "someones_displacement_field.nii.gz", ... is_deltas=False, ... ) >>> xfm.map([-6.5, -36., -19.5]).tolist() [[0.0, -0.47516798973083496, 0.0]]
>>> xfm.map([[-6.5, -36., -19.5], [-1., -41.5, -11.25]]).tolist() [[0.0, -0.47516798973083496, 0.0], [0.0, -0.538356602191925, 0.0]]
>>> np.array_str( ... xfm.map([[-6.7, -36.3, -19.2], [-1., -41.5, -11.25]]), ... precision=3, ... suppress_small=True, ... ) '[[ 0. -0.482 0. ]\n [ 0. -0.538 0. ]]'
>>> xfm = DenseFieldTransform( ... test_dir / "someones_displacement_field.nii.gz", ... is_deltas=True, ... ) >>> xfm.map([[-6.5, -36., -19.5], [-1., -41.5, -11.25]]).tolist() [[-6.5, -36.47516632080078, -19.5], [-1.0, -42.03835678100586, -11.25]]
>>> np.array_str( ... xfm.map([[-6.7, -36.3, -19.2], [-1., -41.5, -11.25]]), ... precision=3, ... suppress_small=True, ... ) '[[ -6.7 -36.782 -19.2 ]\n [ -1. -42.038 -11.25 ]]'
- property ndim
Get the dimensions of the transform.