taufactor.metrics.base

Functions

triple_phase_boundary(img)

Compute triple-phase boundary (TPB) density.

volume_fraction(img[, phases])

Compute volume fractions for labels in a segmented image.

taufactor.metrics.base.triple_phase_boundary(img)[source]

Compute triple-phase boundary (TPB) density.

Calculates the fraction of voxel vertices/edges that are shared by at least three distinct phases. The input image must contain exactly three unique labels.

Parameters:

img (numpy.ndarray | torch.Tensor) – Segmented 2D or 3D image with exactly three phase labels.

Returns:

Triple-phase boundary density (normalized by the number of candidate vertices/edges).

Return type:

float

Raises:
  • ImportError – If PyTorch is not available.

  • ValueError – If the image does not contain exactly three phases.

taufactor.metrics.base.volume_fraction(img, phases={})[source]

Compute volume fractions for labels in a segmented image.

Calculates the fraction of voxels belonging to each phase. If phases is empty, all unique labels in img are measured. Otherwise, uses the provided mapping of phase names to label values.

Parameters:
  • img (torch.Tensor | numpy.ndarray) – Segmented image. If not a torch.Tensor, it will be converted to one.

  • phases (dict[str, int], optional) – Mapping from phase name to the integer label in img. If empty (default), all labels in the image are measured and names are derived from the label values.

Returns:

Mapping from phase name to volume fraction in the range [0, 1].

Return type:

dict[str, float]

Raises:

ImportError – If PyTorch is not available.