TranslationPerturbation

Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

class TranslationPerturbation(shift_voxels: Sequence[float] | None = None, max_shift_voxels: float = 1.0, interpolator: str = 'bspline', shift_fraction: float | None = None, random_signs: bool = True, warp_masks: bool = True)[source]

Bases: object

Translate image content by a (random) sub-voxel shift.

Matches MIRP perturbation_translation_fraction when shift_fraction is set: a fraction of one voxel along x, y and z (Prior et al., Radiol Artif Intell 2024;6(2):e230118, Appendix S2). shift_voxels is the explicit SimpleITK (x, y, z) alternative. When both are unset, each axis is drawn from Uniform(-max_shift_voxels, +max_shift_voxels).

Parameters:
  • shift_voxels – Fixed shift in voxel units, SimpleITK (x, y, z) order; None defers to shift_fraction or random sampling.

  • shift_fraction – MIRP-style fraction of a voxel in [0, 1]. When set (and shift_voxels is unset), the shift is ±fraction on each axis (signs random if random_signs).

  • max_shift_voxels – Sampling bound when neither fixed shift is set.

  • random_signs – When using shift_fraction, randomize the sign of each axis (MIRP interpolates at a shifted grid; the direction of the shift is not anatomically privileged).

  • interpolator – Interpolator for the intensity images ("bspline" is the paper’s choice); masks use nearest neighbour only when warp_masks is True.

  • warp_masks – When True, apply the same translation to every ROI. Prior 2024 extraction keeps the original mask (False).

__init__(shift_voxels: Sequence[float] | None = None, max_shift_voxels: float = 1.0, interpolator: str = 'bspline', shift_fraction: float | None = None, random_signs: bool = True, warp_masks: bool = True) → None[source]
property spec: Spec

Return the algorithm specification used for provenance.

__call__(subject: Subject, *, rng: Generator) → Subject[source]

Return a copy of subject translated by the (sampled) shift.

Parameters:
  • subject – Subject providing images and masks.

  • rng – Random generator sampling the shift when shift_voxels is unset.

Returns:

The perturbed subject copy.