plot_habitat_label_compare

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_habitat_label_compare(image: np.ndarray, labels_a: np.ndarray, labels_b: np.ndarray, *, titles: Tuple[str, str] = ('Reference', 'Predict'), alpha: float = 1.0, axis: int = 0, index: int | None = None, direction: Sequence[float] | None = None, spacing: Sequence[float] | None = None, display_convention: DisplayConvention = 'radiological', show_disagreement: bool = True, colorbar: ColorbarSpec = True, colorbar_label: str = 'Habitat', align_labels: bool | None = None, crop_to: str = 'none', crop_pad: int = 6) → Figure[source]

Side-by-side habitat overlays, optional disagreement mask.

Independently clustered maps permute integer ids. By default this remaps labels_b (panel 2 only) onto labels_a by maximal voxel overlap – the same Hungarian pairing habitat_stability() uses – before colouring and before the disagreement panel. Habitat 2 on the left is then the same spatial region as habitat 2 on the right. Disagreement is aligned_b != a on labelled voxels, not raw id inequality. Maps that already share a model_id (apply-saved-model, or maps renamed by align_habitat_maps_to_prototypes()) are left unchanged – those ids are already the same definition.

Parameters:
  • image – Anatomy volume (z, y, x) or 2D.

  • labels_a – Reference / train labels (same shape).

  • labels_b – Compared / predicted labels (same shape).

  • titles – Panel titles for A and B.

  • alpha – Overlay opacity (default 1.0 = opaque habitat colours).

  • axis – Slice axis for 3D volumes.

  • index – Slice index; densest union of labels when omitted.

  • direction – Optional SimpleITK direction cosines.

  • spacing – Optional SimpleITK spacing (x, y[, z]).

  • display_convention – Radiological / neurological / native.

  • show_disagreement – If True, add a third panel for label mismatch.

  • colorbar – Discrete habitat-ID colorbar on the last habitat panel (default True). The disagreement panel is not a habitat map and does not get this bar. Pass False to hide it.

  • colorbar_label – Colorbar label (English default "Habitat").

  • align_labels – None (default) aligns unless both inputs share a model_id; True always aligns; False never aligns. Independent one_step fits on the same subject share a model_id (spec + subject-id digest) and need True.

  • crop_to – "none" (default) draws the full field of view; "labels" zooms every panel to the bounding box of the union of non-background voxels in both maps so a small tumour 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="labels" (default 6).

Returns:

A matplotlib Figure.

Examples using habit.viz.plot_habitat_label_compare

Preprocessing voxel texture before clustering

Preprocessing voxel texture before clustering

Why habitat ids must be matched

Why habitat ids must be matched

Matching maps of the same voxels by overlap

Matching maps of the same voxels by overlap

Prototype matching step by step

Prototype matching step by step

Precise voxel features

Precise voxel features