bartorch.affine_transform#
- bartorch.affine_transform(input, matrix, axes, oshape=None, *, order=1)#
Resample
inputon 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: voxelpof a grid ofnsits at(p - n // 2) / n(motion/affine.c:25, 152, 466). A translation ofttherefore moves the content by-t * nvoxels, and the identity with anoshapeother than the input’s rescales the whole field of view onto the new grid. The grid is zero outside[0, n - 1]. BART’sinterpolate -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 entryiis the position alongaxes[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
kaxes, in C order (-x); by default the input’s.
- Returns:
input.shapewith its lastkaxes of sizeoshape.- 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))