RandomCropPerturber
- class nrtk.impls.perturb_image.generic.crop_perturber.RandomCropPerturber(box_alignment_mode: str = 'extent', seed: Generator | int | None = 1)
RandomCropPerturber randomly crops an image and adjusts bounding boxes accordingly. Methods: perturb: Applies a random crop 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 RandomCropPerturber instance.
Methods
from_configInstantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.
Returns the current configuration of the _SPNoisePerturber instance.
get_default_configGenerate and return a default configuration dictionary for this class.
get_implsDiscover and return a set of classes that implement the calling class.
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__(box_alignment_mode: str = 'extent', seed: Generator | int | None = 1) 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.
- Attributes:
rng (numpy.random.Generator): Random number generator for deterministic behavior.
- get_config() dict[str, Any]
Returns the current configuration of the _SPNoisePerturber instance.
- Returns:
dict[str, Any]: Configuration dictionary with current settings.
- perturb(image: ndarray, boxes: Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None = None, additional_params: dict[str, Any] | None = None) tuple[ndarray, Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None]
Randomly crops an image and adjusts bounding boxes.
- Parameters:
image – Input image as a numpy array of shape (H, W, C).
boxes – List of bounding boxes in AxisAlignedBoundingBox format and their corresponding classes.
additional_params – Dictionary containing: - “crop_size” (Tuple[int, int]): Crop size as (crop_height, crop_width).
- Returns:
Cropped image as numpy array with the modified bounding boxes