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
imageand 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), withxthe readout,ythe phase-encode andzthe 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 perzindex; 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 perzindex; 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 ofimage; 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
imagedoes not matchsource, the planes of a sequence are not equally spaced to 1e-3 relative or not collinear to 1e-4, orinterpolationis 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 ofnvoxels the spacing isfield_of_view / matrix_sizeandpositionis the centre of voxeln // 2.One geometry for the volume has
matrix_size[2]slices of spacingfield_of_view[2] / matrix_size[2]alongslice_dir. In a sequence of per-plane geometries, planekis centred on its ownposition; the slice spacing is the distance between consecutive positions and the slice direction runs from the first position to the second. A single plane takesslice_dirandfield_of_view[2]. The in-plane geometry is the first plane’s.