RandomCropPerturber#
- class nrtk.impls.perturb_image.geometric.random.RandomCropPerturber(*, crop_size: tuple[int, int] | None = None, seed: int | None = None, is_static: bool = False)#
RandomCropPerturber randomly crops an image and adjusts bounding boxes accordingly.
- Attributes:
crop_size (tuple[int, int]): Target crop dimensions for the input image. 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.
Methods
from_configInstantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.
Returns the current configuration of the RandomCropPerturber 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 crops an image and adjusts bounding boxes.
- __init__(*, crop_size: tuple[int, int] | None = None, seed: int | None = None, is_static: bool = False) None#
RandomCropPerturber applies a random cropping perturbation to an input image.
It ensures that bounding boxes are adjusted correctly to reflect the new cropped region.
- Args:
- crop_size:
Target crop size as (crop_height, crop_width). If crop_size is None, it defaults to the size of the input image. If crop_size is greater than or equal to image size, the original image is returned.
- 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).
- get_config() dict[str, Any]#
Returns the current configuration of the RandomCropPerturber instance.
- perturb(*, image: ndarray[Any, Any], boxes: Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None = None, **_: Any) tuple[ndarray[Any, Any], Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None]#
Randomly crops 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.
- Returns:
Cropped image with the modified bounding boxes.