perturb_image

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.

perturb_image(image: ImageVolume, method: str, *, mask: MaskVolume | None = None, seed: int = 0, rng: Generator | None = None, **params: Any) → ImageVolume[source]

Return a same-grid perturbed copy of one image.

This is the atomic teaching / experiment call: one volume, one registered method, and that method’s parameters. Intensity methods are gaussian_noise, translation, rotation, rigid, and bspline_deform (the last needs the optional monai extra). Mask-only contour methods (morphological, gradient_weighted, slice_extent, and bspline_deform with mask_only=True) leave the image unchanged; call the registered component on a Subject when you need the edited mask. Geometric methods resample back onto the original voxel grid so the result stays voxel-wise comparable to image.

mask is optional. When given, methods that need an ROI (for example gaussian_noise with noise_method="roi_std", or bspline_deform with target_dice) see it, and geometric methods warp the mask internally. This function still returns only the perturbed intensity volume. Use the registered component on a Subject when you also need the warped mask.

Parameters:
  • image – Source intensity volume.

  • method – Registered image_perturbation name.

  • mask – Optional ROI used by methods that consult or warp a mask.

  • seed – Used when rng is omitted; each call with the same seed and parameters is reproducible.

  • rng – Random generator; overrides seed when set.

  • **params – Constructor kwargs of the named method (validated by that method’s params model). Examples: sigma / noise_method for gaussian_noise; shift_voxels or shift_fraction for translation; angle_degrees for rotation.

Returns:

Perturbed intensity volume on the same grid as image. metadata["perturbation"] records the component Spec.

Raises:

Examples using habit.precision.perturb_image

Precise voxel features

Precise voxel features