tools.reslice

Contents

tools.reslice#

bartorch.tools.reslice()#

Resample an image onto the grid of another prescription from header geometry.

No registration is performed: the transform between the grids is the one the two geometries define in patient coordinates. The leading axes of image and the real and imaginary parts are resampled in one pass, as components of one vector image.

Parameters:
  • image (torch.Tensor or numpy.ndarray) – Real or complex image of shape (..., z, y, x), with x the readout, y the phase-encode and z the slice axis.

  • source (object, or list or tuple of object) – Geometry of image (source) and of the grid wanted (target): one geometry for the volume, or one per z index; see Notes.

  • target (object, or list or tuple of object) – Geometry of image (source) and of the grid wanted (target): one geometry for the volume, or one per z index; see Notes.

  • interpolation ({"linear", "nearest"}, default="linear") – Interpolation of the source samples.

  • fill (float, default=0.0) – Value of target voxels whose centre lies outside the source volume.

Returns:

Image of shape (..., tz, ty, tx) on the target grid, in the container type of image; a tensor stays on its device. Complex input gives complex64 output; real input keeps its floating dtype, and other dtypes give float32.

Return type:

torch.Tensor or numpy.ndarray

Raises:

ValueError – If the shape of image does not match source, the planes of a sequence are not equally spaced to 1e-3 relative or not collinear to 1e-4, or interpolation is unknown.

Notes

A geometry has the fields of an MRD ImageHeader (position, read_dir, phase_dir, slice_dir, field_of_view, matrix_size), read as attributes or, failing that, as mapping keys. Positions and field of view are in millimetres; directions are unit vectors in patient coordinates. Along an axis of n voxels the spacing is field_of_view / matrix_size and position is the centre of voxel n // 2.

One geometry for the volume has matrix_size[2] slices of spacing field_of_view[2] / matrix_size[2] along slice_dir. In a sequence of per-plane geometries, plane k is centred on its own position; the slice spacing is the distance between consecutive positions and the slice direction runs from the first position to the second. A single plane takes slice_dir and field_of_view[2]. The in-plane geometry is the first plane’s.