DefocusOTFPerturber

class nrtk.impls.perturb_image.pybsm.defocus_otf_perturber.DefocusOTFPerturber(sensor: PybsmSensor | None = None, scenario: PybsmScenario | None = None, w_x: float | None = None, w_y: float | None = None, interp: bool = True)

Implements image perturbation using defocus and Optical Transfer Function (OTF).

DefocusOTFPerturber applies optical defocus perturbations to input images based on specified sensor and scenario configurations. The perturbation uses the Optical Transfer Function (OTF) and Point Spread Function (PSF) for simulation.

See https://pybsm.readthedocs.io/en/latest/explanation.html for image formation concepts and parameter details.

Attributes:
sensor (PybsmSensor | None):

The sensor configuration for the simulation.

scenario (PybsmScenario | None):

The scenario configuration, such as altitude and ground range.

w_x (float | None):

Defocus parameter in the x-direction.

w_y (float | None):

Defocus parameter in the y-direction.

interp (bool):

Whether to interpolate atmosphere data.

mtf_wavelengths (np.ndarray):

Array of wavelengths used for Modulation Transfer Function (MTF).

D (float):

Lens diameter in meters.

slant_range (float):

Slant range in meters, calculated from altitude and ground range.

ifov (float):

Instantaneous Field of View (IFOV).

Methods:
perturb:

Applies the defocus effect to the input image.

__call__:

Alias for the perturb method.

get_default_config:

Provides the default configuration for the perturber.

from_config:

Instantiates the perturber from a configuration dictionary.

get_config:

Retrieves the current configuration of the perturber instance.

Methods

from_config

Instantiates a DefocusOTFPerturber from a configuration dictionary.

get_config

Returns the current configuration of the DefocusOTFPerturber instance.

get_default_config

Retrieves the default configuration for DefocusOTFPerturber 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 dependencies pyBSM is available.

perturb

Applies the defocus aperture-based perturbation to the provided image.

__init__(sensor: PybsmSensor | None = None, scenario: PybsmScenario | None = None, w_x: float | None = None, w_y: float | None = None, interp: bool = True) None

Initializes a DefocusOTFPerturber instance with the specified parameters.

Args:
sensor:

Sensor configuration for the simulation.

scenario:

Scenario configuration (altitude, ground range, etc.).

w_x:

the 1/e blur spot radii in the x direction. Defaults to the sensor’s value if provided.

w_y:

the 1/e blur spot radii in the y direction. Defaults to the sensor’s value if provided.

interp:

Whether to interpolate atmosphere data. Defaults to True.

If a value is provided for w_x and/or w_y those values will be used in the otf calculation.

If both sensor and scenario parameters are provided, but not w_x and/or w_y, the value(s) of w_x and/or w_y will come from the sensor and scenario objects.

If either sensor or scenario parameters are absent, default values will be used for both sensor and scenario parameters (except for w_x/w_y as defined below).

If any of w_x or w_y are absent and sensor/scenario objects are also absent, the absent value(s) will default to 0.0 for both.

Raises:
raises ImportError:

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

classmethod from_config(config_dict: dict[str, Any], merge_default: bool = True) Self

Instantiates a DefocusOTFPerturber from a configuration dictionary.

Args:
config_dict:

Configuration dictionary with initialization parameters.

merge_default:

Whether to merge with default configuration. Defaults to True.

Returns:
return DefocusOTFPerturber:

An instance of DefocusOTFPerturber.

get_config() dict[str, Any]

Returns the current configuration of the DefocusOTFPerturber instance.

Returns:
return dict[str, Any]:

Configuration dictionary with current settings.

classmethod get_default_config() dict[str, Any]

Retrieves the default configuration for DefocusOTFPerturber instances.

Returns:
return dict[str, Any]:

A dictionary with the default configuration values.

classmethod is_usable() bool

Checks if the necessary dependencies pyBSM is available.

Returns:
return bool:

True if pyBSM is available; False otherwise.

perturb(image: ndarray[Any, Any], boxes: Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None = None, additional_params: dict[str, Any] | None = None) tuple[ndarray[Any, Any], Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None]

Applies the defocus aperture-based perturbation to the provided image.

Args:
image:

The image to be perturbed.

boxes:

Bounding boxes for detections in input image.

additional_params:
Dictionary containing:
  • “img_gsd” (float): GSD is the distance between the centers of two adjacent

    pixels in an image, measured on the ground.

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

The perturbed image and bounding boxes scaled to perturbed image shape.

Raises:
raises ValueError:

If ‘img_gsd’ is not provided in additional_params.