snapshots#

voxel.snapshot(volume=None, label=None, view='axial', num_slices=1, coord=None, res=256, square=False, resample='nearest', label_colors=None, alpha=0.5, outline=False, pool=4) → Tensor | list[Tensor]#

Render a volume (or stack of overlaid volumes) into one or more 2D RGB snapshot images, optionally blending label masks on top.

Slices are taken along the view direction and returned as channels-last \((H, W, 3)\) uint8 image tensors: a single tensor for one slice, else a list.

Parameters:
  • volume (Volume or list[Volume]) – Volume(s) to render, each with 1 (grayscale) or 3 (RGB) channels. The first defines the base geometry; the rest are composited on top wherever they have in-bounds data. Grayscale channels are contrast-normalized to \([0, 1]\). RGB values must already lie within \([0, 1]\).

  • label (Volume or list[Volume], optional) – Label overlay(s). A volume with values greater than one is treated as a discrete labelmap: values are conformed to integers, each unique nonzero value becomes a class, resampled with nearest-neighbor interpolation and colored from the volume’s labels lookup when it defines a color. A volume within \([0, 1]\) holds soft mask(s), blending softly for fractional values, with each channel a separate class.

  • view (str, optional) – View plane: ‘axial’, ‘coronal’, or ‘sagittal’ (or their first letters). Defaults to ‘axial’.

  • num_slices (int, optional) – Number of evenly spaced slices along the view direction. Ignored when coord is given. Defaults to 1.

  • coord (Tensor, optional) – World-space (x, y, z) coordinate. If given, a single slice through this point is rendered and num_slices ignored.

  • res (int, optional) – Pixel height of the rendered images. Slices are resampled to the isotropic in-plane spacing that yields this height, preserving the physical aspect ratio. Defaults to 256.

  • square (bool, optional) – If True, center-crop or pad the image width to match its height, yielding square (res, res) images. Defaults to False.

  • resample (str, optional) – Interpolation mode used when resampling volumes and labels onto the snapshot grid, either ‘linear’ or ‘nearest’. Defaults to ‘nearest’.

  • label_colors (Tensor or list, optional) – RGB color(s) in \([0, 1]\) for the labels, cycled to match the number of label classes. Overrides any lookup-defined colors. Defaults to a categorical palette.

  • alpha (float, optional) – Opacity of the label overlays. Defaults to 0.5.

  • outline (bool, optional) – If True, draw a fully opaque one-pixel outline just inside the boundary of each label in its color, unaffected by alpha. Defaults to False.

  • pool (int, optional) – Pooling window used to make grayscale normalization robust to outlier voxels. Set to 1 or None to disable. Defaults to 4.

Returns:

Tensor or list[Tensor] –

A single \((H, W, 3)\) uint8 RGB image, or a

list of them.