RandomCropPerturber

class nrtk.impls.perturb_image.generic.random_crop_perturber.RandomCropPerturber(crop_size: tuple[int, int] | None = None, seed: int | Generator | None = 1)

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 | numpy.random.Generator): Random seed or number generator for deterministic behavior.

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_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 RandomCropPerturber 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 crops an image and adjusts bounding boxes.

__init__(crop_size: tuple[int, int] | None = None, seed: int | Generator | 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.

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.

seed:

Seed for rng. Defaults to 1.

get_config() dict[str, Any]

Returns the current configuration of the RandomCropPerturber 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, **_: 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.

additional_params:

Additional perturbation keyword arguments (currently unused).

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

Cropped image with the modified bounding boxes.