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, andbspline_deform(the last needs the optionalmonaiextra). Mask-only contour methods (morphological,gradient_weighted,slice_extent, andbspline_deformwithmask_only=True) leave the image unchanged; call the registered component on aSubjectwhen you need the edited mask. Geometric methods resample back onto the original voxel grid so the result stays voxel-wise comparable toimage.maskis optional. When given, methods that need an ROI (for examplegaussian_noisewithnoise_method="roi_std", orbspline_deformwithtarget_dice) see it, and geometric methods warp the mask internally. This function still returns only the perturbed intensity volume. Use the registered component on aSubjectwhen you also need the warped mask.- Parameters:
image – Source intensity volume.
method – Registered
image_perturbationname.mask – Optional ROI used by methods that consult or warp a mask.
seed – Used when
rngis omitted; each call with the same seed and parameters is reproducible.rng – Random generator; overrides
seedwhen set.**params – Constructor kwargs of the named method (validated by that method’s params model). Examples:
sigma/noise_methodforgaussian_noise;shift_voxelsorshift_fractionfortranslation;angle_degreesforrotation.
- Returns:
Perturbed intensity volume on the same grid as
image.metadata["perturbation"]records the componentSpec.- Raises:
HABITAPIError – When
methodis unknown orparamsfail validation.OptionalDependencyError – When the method’s extra is missing (
bspline_deformwithout MONAI).