boundary_weighted_perturbation

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.

boundary_weighted_perturbation(mask: ndarray, weights: ndarray, rng: Generator, max_radius_voxels: int = 2, probability: float = 0.5) → ndarray[source]

Locally grow or shrink a mask where weights is high (gradient-weighted).

Models the fact that inter-rater disagreement concentrates where image contrast is poor: boundary voxels at high-gradient (sharp) edges are drawn consistently, whereas low-gradient (fuzzy) edges vary. weights is typically a normalised gradient-magnitude map; the local perturbation probability scales with 1 - weight so fuzzy edges move more.

A random subset of boundary voxels is flipped (foreground -> background shrinks, background -> foreground grows) within a local radius, biased toward the low-weight side.

Parameters:
  • mask – Integer / boolean label array; 0 is background.

  • weights – Per-voxel weight in [0, 1], same shape as mask; high means a confident (sharp) edge. Typically a normalised gradient magnitude of the driving image.

  • rng – Random generator supplying the flip decisions.

  • max_radius_voxels – Neighbourhood radius bounding each local flip.

  • probability – Base flip probability at zero weight; the effective probability is probability * (1 - weight).

Returns:

A new label array, same shape and dtype as mask.

Raises:

ValueError – If weights shape differs from mask.