SaltAndPepperNoisePerturber#

class nrtk.impls.perturb_image.photometric.noise.SaltAndPepperNoisePerturber(*, seed: int | None = None, is_static: bool = False, amount: float = 0.05, salt_vs_pepper: float = 0.5, clip: bool = True)#

Adds salt & pepper noise to image stimulus.

Attributes:
seed (int | None):

Random seed for reproducible results. None means non-deterministic.

is_static (bool):

If True and seed is set, resets RNG state after each perturb call.

clip (bool):

Decide if output is clipped between the range of [-1, 1].

amount (float):

Proportion of image pixels to replace with noise on range [0, 1]

salt_vs_pepper (float):

Proportion of salt vs. pepper noise. Higher values represent more salt.

Methods

from_config

Instantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.

get_config

Returns the current configuration of the SaltAndPepperNoisePerturber instance.

get_default_config

Generate and return a default configuration dictionary for this class.

get_impls

Discover plugins, skipping any entrypoints that fail to load.

get_type_string

Returns the fully qualified type string of the PerturbImage class or its subclass.

is_usable

Check whether this class is available for use.

perturb

Return image stimulus with S&P noise.

__init__(*, seed: int | None = None, is_static: bool = False, amount: float = 0.05, salt_vs_pepper: float = 0.5, clip: bool = True) None#

Initializes the SaltAndPepperNoisePerturber.

Args:
seed:

Random seed for reproducible results. Defaults to None for non-deterministic behavior.

is_static:

If True and seed is provided, resets the random state after each perturb call for identical results on repeated calls.

amount:

Proportion of image pixels to replace with noise on range [0, 1].

salt_vs_pepper:

Proportion of salt vs. pepper noise on range [0, 1]. Higher values represent more salt.

clip:

Decide if output is clipped between the range of [-1, 1].

get_config() dict[str, Any]#

Returns the current configuration of the SaltAndPepperNoisePerturber instance.

perturb(*, image: ndarray[Any, Any], boxes: Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None = None, **kwargs: Any) tuple[ndarray[Any, Any], Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None]#

Return image stimulus with S&P noise.