Skip to main content

mask_volume

mask_volume(mask, spacing, class_index=1)

How much of a volume one class occupies, in millilitres.

Millilitres rather than cubic millimetres, because a millilitre is a cubic centimetre and that is the unit a radiology report is written in.

Parameters

Name Type Description Default
mask np.ndarray One volume of class indices, as Engine.predict returns after an argmax - three dimensions, not a stack. required
spacing Any Voxel size in millimetres, three numbers, in the array’s own axis order. pyplatypus.data.volumes.volume_spacing reads it out of the file. required
class_index int The class to measure, matched against the array’s own values rather than used as an index into it. For a mask from argmax that value is the channel number, counted from 0, so the default of 1 is the foreground of a binary segmentation. It is what makes the R package’s forward trivial: R collapses with which.max and counts its classes from 1, so R passes its own numbering and no translation happens anywhere. 1

Returns

Name Type Description
float The volume in millilitres.

Raises

Name Type Description
MeasureError If mask is not one volume, or spacing is not three positive numbers.

mask = np.zeros((10, 10, 4), dtype=int) mask[2:6, 2:6, 1:3] = 1 round(mask_volume(mask, spacing=(2, 2, 5)), 3) # 32 voxels of 20 mm^3 0.64