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.
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
brain_box ¶
brain_box(brain: ndarray, z_coord: ndarray | None = None, z_min: float = -58.0, margin: tuple[int, int] = (5, 6)) -> list[tuple[int, int]]
Voxel bounding box of brain plus a margin; with z_coord (MNI z), drop what lies below z_min (the cord).
Source code in tit/plotting/slices.py
pick_slice ¶
pick_slice(axis: int, target: float, coord: ndarray, mask: ndarray, box: list[tuple[int, int]] | None = None) -> int
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 ¶
2-D panel (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 ¶
Tiles on a grid, centred in equal cells; returns (image, (tile_h, tile_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.