PybsmPerturber

class nrtk.impls.perturb_image.pybsm.perturber.PybsmPerturber(sensor: PybsmSensor, scenario: PybsmScenario, reflectance_range: ndarray = array([0.05, 0.5]), rng_seed: int = 1, box_alignment_mode: str = 'extent', **kwargs: Any)

Implements image perturbation using pyBSM sensor and scenario configurations.

The PybsmPerturber class applies realistic perturbations to images by leveraging pyBSM’s simulation functionalities. It takes in a sensor and scenario, along with other optional parameters, to simulate environmental effects on the image.

Attributes:

sensor (PybsmSensor): The sensor configuration for the perturbation. scenario (PybsmScenario): Scenario settings to apply during the perturbation. reflectance_range (np.ndarray): Default reflectance range for image simulation.

Methods

from_config

Instantiates a PybsmPerturber from a configuration dictionary.

get_config

Returns the current configuration of the PybsmPerturber instance.

get_default_config

Provides the default configuration for PybsmPerturber instances.

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

Checks if the necessary dependency (pyBSM) is available.

perturb

__init__(sensor: PybsmSensor, scenario: PybsmScenario, reflectance_range: ndarray = array([0.05, 0.5]), rng_seed: int = 1, box_alignment_mode: str = 'extent', **kwargs: Any) None

Initializes the PybsmPerturber.

Parameters:
  • sensor – pyBSM sensor object.

  • scenario – pyBSM scenario object.

  • reflectance_range – Array of reflectances that correspond to pixel values.

  • rng_seed – integer seed value that will be used for the random number generator

  • box_alignment_mode

    Mode for how to handle how bounding boxes change. Should be one of the following options:

    extent: a new axis-aligned bounding box that encases the transformed misaligned box extant: a new axis-aligned bounding box that is encased inside the transformed misaligned box median: median between extent and extant

    Default value is extent

Raises:

ImportError if pyBSM is not found, install via pip install nrtk[pybsm].

Raises:

ValueError if reflectance_range length != 2

Raises:

ValueError if reflectance_range not strictly ascending

__repr__() str

Returns a representation of the perturber including sensor and scenario names.

Returns:

str: Representation showing sensor and scenario names.

__str__() str

Returns a string representation combining sensor and scenario names.

Returns:

str: Concatenated sensor and scenario names.

classmethod from_config(config_dict: dict, merge_default: bool = True) PybsmPerturber

Instantiates a PybsmPerturber from a configuration dictionary.

Args:

config_dict (dict): Configuration dictionary with initialization parameters. merge_default (bool, optional): Whether to merge with default configuration. Defaults to True.

Returns:

C: An instance of PybsmPerturber configured according to config_dict.

get_config() dict[str, Any]

Returns the current configuration of the PybsmPerturber instance.

Returns:

dict[str, Any]: Configuration dictionary with current settings.

classmethod get_default_config() dict[str, Any]

Provides the default configuration for PybsmPerturber instances.

Returns:

dict[str, Any]: A dictionary with the default configuration values.

classmethod is_usable() bool

Checks if the necessary dependency (pyBSM) is available.

Returns:

bool: True pyBSM is available; False otherwise.

property params: dict

Retrieves the theta parameters related to the perturbation configuration.

This method provides extra configuration details for the PybsmPerturber instance, which may include specific parameters related to the sensor, scenario, or any additional customizations applied during initialization.

Returns:

dict[str, Any]: A dictionary containing additional perturbation parameters.

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]
Raises:

ValueError if ‘img_gsd’ not present in additional_params