bartorch.affine_transform

bartorch.affine_transform#

bartorch.affine_transform(input, matrix, axes, oshape=None, *, order=1)#

Resample input on an affinely mapped grid: out(u) = input(matrix @ [u, 1]).

The matrix maps output positions to input positions. Positions are in units of each grid’s own field of view with the origin at index n // 2: voxel p of a grid of n sits at (p - n // 2) / n (motion/affine.c:25, 152, 466). A translation of t therefore moves the content by -t * n voxels, and the identity with an oshape other than the input’s rescales the whole field of view onto the new grid. The grid is zero outside [0, n - 1]. BART’s interpolate -A, which is limited to three dims.

Parameters:
  • input (torch.Tensor) – Two or three spatial axes, optionally after leading axes of size one.

  • matrix (torch.Tensor) – Real (k, k + 1) or homogeneous (k + 1, k + 1) matrix, k = len(axes), acting on column vectors [u_0, ..., u_{k-1}, 1] whose entry i is the position along axes[i].

  • axes (tuple of int) – The last two or three axes, in the order the matrix’s rows and columns refer to them.

  • oshape (tuple of int, optional) – Output size of the last k axes, in C order (-x); by default the input’s.

Returns:

input.shape with its last k axes of size oshape.

Return type:

torch.Tensor

Examples

Swap the two axes of a square image (its transpose):

>>> affine_transform(image, torch.tensor([[0.0, 1, 0], [1, 0, 0]]), axes=(-2, -1))