slices
tit.plotting.slices ¶
Slice figures that every report shares: one orientation convention, slices chosen by anatomy.
Convention (stated in every caption that uses it):
- volumes are reordered to the closest canonical RAS voxel order first (:func:
canonical), whatever the grid on disk (ernie's m2m grid is PSR, CHN's is RAS); - panels are neurological: subject left on image left, superior up; anterior up in axial panels and to the right in sagittal panels;
- slices are picked by coordinate, normally MNI through charm's
Conform2MNI_nonlwarp, and never where the brain is (nearly) absent, so a mosaic has no empty panels; - panels are never cropped: each shows its whole slice of the volume, framed by a black margin of
:data:
MARGINvoxels (a brain-mask crop cut the scalp, and the brain where it reached the grid edge).
Rendering needs matplotlib and Pillow (WebP); everything else is numpy.
canonical ¶
Reorder the first three axes of data to the closest RAS voxel order.
Only axis permutations and flips (nibabel.as_closest_canonical's rule), so values are
untouched; world-frame vectors and tensors stay valid. Extra trailing axes are kept.
Source code in tit/plotting/slices.py
pick_slice ¶
Index along axis whose mask voxels' mean coord is closest to target.
coord is one coordinate component per voxel (e.g. MNI y for a coronal slice). Slices with
fewer than :data:MIN_SLICE_VOXELS mask voxels are never chosen.
Source code in tit/plotting/slices.py
oriented ¶
The whole 2-D slice (rows top to bottom) of RAS vol at index i along axis, neurological.
Axial (axis 2): anterior up, left on the left. Coronal (1): superior up, left on the left. Sagittal (0): superior up, anterior on the right. Trailing channel axes are kept.
Source code in tit/plotting/slices.py
mosaic ¶
mosaic(tiles: list[ndarray], cols: int, gap: int = 4, margin: int = MARGIN) -> tuple[ndarray, tuple[int, int]]
Tiles on a grid, centred in equal cells at least margin larger on every side; returns
(image, (cell_h, cell_w)).
Source code in tit/plotting/slices.py
overlay ¶
overlay(grey: ndarray, field: ndarray, lo: float, hi: float, cmap: str = 'inferno', alpha: float = 0.85) -> ndarray
RGB panel: grey (0–1) under field coloured from lo to hi; voxels below lo stay grey.
Source code in tit/plotting/slices.py
colour_stops ¶
n evenly spaced colours of cmap as hex, for a CSS colour bar matching :func:overlay.
Source code in tit/plotting/slices.py
render ¶
Draw a grey (2-D) or RGB (H, W, 3) panel at 2 px per voxel, with outline contours, as WebP.
contours are (mask, colour, line width); every outline is drawn on the same grid as the
image.