save_class_volumes

save_class_volumes(
    prediction,
    directory,
    *,
    reference,
    classes,
    cases=None,
    threshold=0.5,
    suffix='',
)

One binary volume per class, which is how an overlapping prediction reaches disk in 3D.

save_class_masks is this function for pictures, and regions was motivated by BraTS, which stores its overlapping regions as volumes - so this is the writer the motivating dataset actually needs. Each file is <case><suffix>_<class>.nii.gz, 0 or 1 as int16, carrying the reference’s canonical affine like everything else here.

classes rather than names, and cases for the per-file half, which is the same split save_class_masks settled: in the R package names already means the files a writer writes, so a sibling where the same word meant the classes would accept a call copied from one to the other whenever the counts happened to match.

A channel where nothing reaches threshold is written as an empty volume rather than skipped, for save_class_masks’s reason: a missing file reads as “this run did not produce that class” and an empty one as “it did and the answer was nothing”, and only one of those is true.

Parameters

Name Type Description Default
prediction np.ndarray | Sequence[np.ndarray] Channels-last probabilities, as for save_volumes. required
directory str | Path Where to write. Created, with parents, if it does not exist. required
reference Sequence[str | Path] The scan each mask was predicted from, in the same order. required
classes Sequence[str] One name per channel, in channel order. Passed through class_filename, so whole tumour is whole_tumour on disk. required
cases Sequence[str] | None One name per volume. Defaults to mask_0001 and so on. None
threshold float A channel is hot where it reaches this. 0.5 is what every metric in the package thresholds a multilabel channel at. 0.5
suffix str Added before the class, so two models can write into one directory. ''

Returns

Name Type Description
list[Path] The paths written, volume by volume and within a volume channel by channel.