Linear Transforms
Linear transforms.
- class nitransforms.linear.Affine(matrix=None, reference=None)[source]
Represents linear transforms on image data.
- classmethod from_filename(filename, fmt=None, reference=None, moving=None)[source]
Create an affine from a transform file.
- classmethod from_matvec(mat=None, vec=None, reference=None)[source]
Create an affine from a matrix and translation pair.
Example
>>> Affine.from_matvec(vec=(4, 0, 0)) array([[1., 0., 0., 4.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]])
- map(x, inverse=False)[source]
Apply \(y = f(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 = Affine([[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3], [0, 0, 0, 1]]) >>> xfm.map((0,0,0)) array([[1., 2., 3.]])
>>> xfm.map((0,0,0), inverse=True) array([[-1., -2., -3.]])
- property matrix
Access the internal representation of this affine.
- property ndim
Access the internal representation of this affine.
- class nitransforms.linear.LinearTransformsMapping(transforms, reference=None)[source]
Represents a series of linear transforms.
- map(x, inverse=False)[source]
Apply \(y = f(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 = LinearTransformsMapping([ ... [[1., 0, 0, 1.], [0, 1., 0, 2.], [0, 0, 1., 3.], [0, 0, 0, 1.]], ... [[1., 0, 0, -1.], [0, 1., 0, -2.], [0, 0, 1., -3.], [0, 0, 0, 1.]], ... ]) >>> xfm.matrix array([[[ 1., 0., 0., 1.], [ 0., 1., 0., 2.], [ 0., 0., 1., 3.], [ 0., 0., 0., 1.]], [[ 1., 0., 0., -1.], [ 0., 1., 0., -2.], [ 0., 0., 1., -3.], [ 0., 0., 0., 1.]]])
>>> y = xfm.map([(0, 0, 0), (-1, -1, -1), (1, 1, 1)]) >>> y[0, :, :3] array([[1., 2., 3.], [0., 1., 2.], [2., 3., 4.]])
>>> y = xfm.map([(0, 0, 0), (-1, -1, -1), (1, 1, 1)], inverse=True) >>> y[0, :, :3] array([[-1., -2., -3.], [-2., -3., -4.], [ 0., -1., -2.]])
- nitransforms.linear.load(filename, fmt=None, reference=None, moving=None)[source]
Load a linear transform file.
Examples
>>> xfm = load(regress_dir / "affine-LAS.itk.tfm") >>> isinstance(xfm, Affine) True
>>> xfm = load(regress_dir / "itktflist.tfm") >>> isinstance(xfm, LinearTransformsMapping) True