plot_intensity_slice
Note
This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.
- plot_intensity_slice(image: object, *, before: object | None = None, roi_mask: object | None = None, axis: int | None = None, index: int | None = None, cmap: str = 'gray', title: str | None = None, image_label: str = 'Processed', before_label: str = 'Original', direction: Sequence[float] | None = None, spacing: Sequence[float] | None = None, display_convention: DisplayConvention = 'radiological', roi_contour: bool = False, colorbar: ColorbarSpec = True, colorbar_label: str = 'Intensity', before_colorbar_label: str = 'Intensity', before_cmap: str | None = None, symmetric_clim: bool = False, crop_to: str = 'none', crop_pad: int = 6) Figure[source]
Display a whole-FOV greyscale anatomy / intensity slice.
Use this for image-preprocessing teaching figures. Do not use
plot_voxel_texture_slice()for MR/CT intensities: that plotter is a voxel-texture map viewer (sequential colormap, ROI crop).Pass
before=for a two-panel original | processed figure when both volumes share a grid (z-score, N4, histogram, CLAHE). After resample / reorient the grid often changes — omitbeforeand show the processed volume alone.Each panel is windowed independently in native units: drop a dominant low-end histogram mode (air / padding), then the 2nd–90th percentiles of the remaining tissue. The colorbar shows those same limits, so a z-score (approximately \(N(0,1)\)) is distinguishable from raw MR/CT intensity even when
cmap='gray'greyscale contrast looks similar. Do not sharevmin/vmaxacross a z-score before/after pair: that would hide the affine change again.roi_maskis drawn only whenroi_contour=True, and then only as a cyan outline on the anatomy. Outside-ROI voxels stay visible. Whole-image steps should omit the mask.- Parameters:
image – Processed (or only) intensity volume. Array or
ImageVolume.before – Optional original volume, same shape as
image.roi_mask – Optional ROI (
> 0inside). Contour overlay only; never used to crop the display.axis – If set, draw only this NumPy axis (
0,1, or2). Default for 3D is a single axial-like panel (axis=0).index – Slice index along
axis; auto (anatomy mass / densest ROI) when omitted.cmap – Matplotlib colormap. Default
"gray"for MR/CT anatomy.title – Optional figure title (ASCII-sanitised).
image_label – Right-hand (or only) panel title.
before_label – Left-hand panel title when
beforeis set.direction – Optional SimpleITK direction cosines (9 floats).
spacing – Optional SimpleITK voxel spacing
(x, y[, z])in mm.display_convention –
"radiological"(default),"neurological", or"native".roi_contour – When
Trueandroi_maskis set, outline the ROI on every anatomy panel.colorbar – Draw an independent colorbar per panel (default
True). PassFalseto hide it, or a mapping of colorbar style kwargs (shrink,pad,fraction,aspect,ticks,label, …) to override the short default bar.colorbar_label – Colorbar label for the processed (or only) panel.
before_colorbar_label – Colorbar label for the original panel when
beforeis set.before_cmap – Colormap for the original panel. Defaults to
cmap. Use"gray"withcmap="RdBu_r"so a z-score panel can show signed values while anatomy stays greyscale.symmetric_clim – When
True, the processed (or only) panel is windowed symmetrically about zero. Use this for z-score so the colorbar reads as[-a, a]rather than an asymmetric percentile window that hides the signed scale.crop_to –
"none"(default) keeps the full field of view, as whole-image preprocessing teaching requires."roi"zooms every panel to the bounding box ofroi_maskso a small lesion fills the frame. Display-only zoom: values, spacing and orientation are unchanged.crop_pad – Voxels of anatomical context kept around the bounding box when
crop_to="roi"(default6).
- Returns:
A matplotlib
Figure. The caller owns persistence / display.- Raises:
HABITAPIError – On shape / parameter errors.
OptionalDependencyError – When matplotlib is not installed.