RandomTranslationPerturber#
- class nrtk.impls.perturb_image.geometric.random.RandomTranslationPerturber(*, seed: int | None = None, is_static: bool = False, color_fill: Sequence[int] | None = [0, 0, 0])#
RandomTranslationPerturber randomly translates an image and adjusts bounding boxes accordingly.
- Attributes:
- seed (int | None):
Random seed for reproducibility. None for non-deterministic behavior.
- is_static (bool):
If True, resets RNG after each call for consistent results.
- color_fill (numpy.array):
Background color fill for RGB image.
Methods
from_configInstantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.
Returns the current configuration of the RandomTranslationPerturber instance.
get_default_configGenerate and return a default configuration dictionary for this class.
get_implsDiscover plugins, skipping any entrypoints that fail to load.
get_type_stringReturns the fully qualified type string of the PerturbImage class or its subclass.
is_usableCheck whether this class is available for use.
Randomly translates an image and adjusts bounding boxes.
- __init__(*, seed: int | None = None, is_static: bool = False, 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:
Random seed for reproducible results. Defaults to None for non-deterministic behavior.
- is_static:
If True and seed is provided, resets RNG after each perturb call for consistent results across multiple calls (useful for video frame processing).
- color_fill:
Background color fill for RGB image. Defaults to [0, 0, 0] (black).
- get_config() dict[str, Any]#
Returns the current configuration of the RandomTranslationPerturber instance.
- perturb(*, image: ndarray[Any, Any], boxes: Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None = None, max_translation_limit: tuple[int, int] | None = None, **kwargs: 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.
- kwargs:
Additional perturbation keyword arguments (currently unused).
- Returns:
Translated image with the modified bounding boxes.