Spatial transforms#

Spatial coordinate and input data transformation modules.

Hint

The spatial transforms defined by this library can be used to implement co-registration approaches based on traditional optimization as well as those based on machine learning (amortized optimization).

A spatial transformation maps points from a target domain defined with respect to the unit cube of a target sampling grid, to points defined with respect to the same domain, i.e., the domain and codomain of the spatial coordinate map are identical. In order to transform an image defined with respect to a different sampling grid, this transformation has to be followed by a mapping from target cube domain to source cube domain. This is done, for example, by the spatial transformer implemented by ImageTransformer.

The forward() method of a SpatialTransform can be used to spatially transform any set of points defined with respect to the grid domain of the spatial transformation, including in particular a tensor of shape (N, M, D), i.e., a batch of N point sets with cardinality M. It can also be applied to a tensor of grid points of shape (N, ..., X, D) regardless if the grid points are located at the undeformed grid positions or those of an already deformed grid. In case of a non-rigid deformation, the point displacements are by default sampled at the input points. The sampled flow vectors \(u\) are then added to the input points \(x\), producing the output \(y = x + u(x)\). If the boolean flag grid=True is passed to the SpatialTransform.forward() function, it is assumed that the coordinates correspond to the positions of undeformed spatial grid points with domain equal to the domain of the transformation. In this special case, a simple interpolation to resize the vector field to the size of the input tensor is used. In case of a linear transformation, \(y = Ax + t\).

The coordinate domain is Axes.CUBE_CORNERS if grid.align_corners() == True (default), and Axes.CUBE otherwise.