tools.affine_transform#
- bartorch.tools.affine_transform()#
Resample
inputon an affinely mapped grid:out(u) = input(matrix @ [u, 1]).The matrix maps output positions to input positions, each in units of its own grid’s field of view with the origin at index
n // 2: voxelpof a grid ofnis at(p - n // 2) / n. A translationtmoves the content by-t * nvoxels, and the identity with anoshapeother than the input’s rescales the field of view onto the new grid. The grid is zero outside[0, n - 1]. BART’sinterpolate -A.- Parameters:
input (torch.Tensor) – Two or three spatial axes, after leading axes of size one only.
matrix (torch.Tensor) – Real
(k, k + 1)or homogeneous(k + 1, k + 1),k = len(axes), acting on column vectors[u_0, ..., u_{k-1}, 1]withu_ithe position alongaxes[i].axes (tuple of int) – The last two or three axes, in the order of the matrix’s rows and columns.
oshape (tuple of int, default=None) – Output size of the last
kaxes, C order; the input’s by default.order ({0, 1, 3}, default=1) – Nearest neighbour, linear, or Keys cubic; see
bartorch.interpolate().
- Returns:
input.shapewith its lastkaxes of sizeoshape.- Return type:
torch.Tensor
- Raises:
ValueError – If
axesare not the last two or three, a leading axis exceeds one, ormatrixhas the wrong shape or a homogeneous last row other than[0, ..., 0, 1].
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))