RandomTranslationPerturber

class nrtk.impls.perturb_image.generic.random_translation_perturber.RandomTranslationPerturber(seed: int | Generator | None = 1, color_fill: Sequence[int] | None = [0, 0, 0])

RandomTranslationPerturber randomly translates an image and adjusts bounding boxes accordingly.

Attributes:
rng (numpy.random.Generator):

Random number generator for deterministic behavior.

color_fill (numpy.array):

Background color fill for RGB image.

Methods:
perturb:

Applies a random translation to an input image and adjusts bounding boxes.

__call__:

Calls the perturb method with the given input image.

get_config:

Returns the current configuration of the RandomTranslationPerturber instance.

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 RandomTranslationPerturber instance.

get_default_config

Generate and return a default configuration dictionary for this class.

get_impls

Discover and return a set of classes that implement the calling class.

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

Randomly translates an image and adjusts bounding boxes.

__init__(seed: int | Generator | None = 1, color_fill: Sequence[int] | None = [0, 0, 0]) None

RandomTranslationPerturber applies a random translation perturbation to an input image.

It ensures that bounding boxes are adjusted correctly to reflect the translated image coordinates.

Args:
seed:

Numpy random number generator.

color_fill:

Background color fill for RGB image.

get_config() dict[str, Any]

Returns the current configuration of the RandomTranslationPerturber instance.

Returns:
return dict[str, Any]:

Configuration dictionary with current settings.

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

Randomly translates an image and adjusts bounding boxes.

Args:
image:

Input image as a numpy array of shape (H, W, C).

boxes:

List of bounding boxes in AxisAlignedBoundingBox format and their corresponding classes.

max_translation_limit:

Max translation magnitude (translate_h, translate_w) lesser than or equal to the size of the input image.

additional_params:

Additional perturbation keyword arguments (currently unused).

Returns:
return tuple[np.ndarray, Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None]:

Translated image with the modified bounding boxes.