WaterDropletPerturber

class nrtk.impls.perturb_image.generic.water_droplet_perturber.WaterDropletPerturber(size_range: Sequence[float] = [0.0, 1.0], num_drops: int = 20, blur_strength: float = 0.25, psi: float = 1.5707963267948966, n_air: float = 1.0, n_water: float = 1.33, f_x: int = 400, f_y: int = 400, seed: int | None = None)

Implements the physics-based, photorealistic water/rain droplet model.

The WaterDropletPerturber class simulates the effects of rain/water droplets on an image similar to the rain drops on a window, car-windshield, etc. The equations defined for this model are based on the dynamics, geometry and photometry of a water/rain droplet.

Attributes:
size_range (Sequence[float]):

Range of size multiplier values used for computing the size of the water droplet.

num_drops (int):

Target number of water droplets.

blur_strength (float):

Strength of Gaussian blur operation.

psi (float):

Angle between the camera line-of-sight and glass plane (radians).

n_air (float):

Density of air.

n_water (float):

Density of water.

f_x (int):

Camera focal length in x direction (cm).

f_y (int):

Camera focal length in y direction (cm).

seed (int):

Random seed for reproducibility.

Methods

blur

Blur the area within the boundaries of the droplets.

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 WaterDropletPerturber 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

Checks if the necessary dependencies (OpenCV, Scipy and Shapely) are available.

perturb

Applies the Water Droplet perturbation effect to the provided input image.

render

Rendering the image with the Water Droplet effect.

__init__(size_range: Sequence[float] = [0.0, 1.0], num_drops: int = 20, blur_strength: float = 0.25, psi: float = 1.5707963267948966, n_air: float = 1.0, n_water: float = 1.33, f_x: int = 400, f_y: int = 400, seed: int | None = None) None

Initializes the WaterDropletPerturber.

Args:
size_range:

Range of size multiplier values used for computing the size of the water droplet.

num_drops:

Target number of water droplets.

blur_strength:

Strength of Gaussian blur operation.

psi:

Angle between the line-of-sight and glass plane (radians).

n_air:

Density of air.

n_water:

Density of water.

f_x:

Camera focal length in x direction (cm).

f_y:

Camera focal length in y direction (cm).

seed:

Random seed for reproducibility.

If any of the parameters are absent, the following values will be set as defaults:

size_range = (0.0, 1.0) num_drops = 20 blur_strength = 0.25 psi = 90.0 / 180.0 * np.pi n_air = 1.0 n_water = 1.33 f_x = 400 f_y = 400 seed = None

Raises:
raises ImportError:

If OpenCV, Scipy or Shapely is not found, install via pip install nrtk[waterdroplet,graphics] or pip install nrtk[waterdroplet,headless].

blur(image: ndarray[Any, Any], rain_image: ndarray[Any, Any], mask: ndarray[Any, Any]) ndarray[Any, Any]

Blur the area within the boundaries of the droplets.

Args:
image (np.ndarray):

Input Image.

rain_image (np.ndarray):

Image rendered with Water droplet effect.

mask (np.ndarray):

Image mask.

Returns:

np.ndarray: Output of blur operation applied on the rain_image.

get_config() dict[str, Any]

Returns the current configuration of the WaterDropletPerturber instance.

Returns:
return dict[str, Any]:

Configuration dictionary with current settings.

classmethod is_usable() bool

Checks if the necessary dependencies (OpenCV, Scipy and Shapely) are available.

Returns:
return bool:

True if OpenCV, Scipy and Shapely are available.

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 Water Droplet perturbation effect to the provided input image.

Args:
image:

The image to be perturbed.

boxes:

Bounding boxes for source detections.

additional_params:

Additional parameters, if applicable.

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

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

render(image: ndarray[Any, Any]) tuple[ndarray[Any, Any], ndarray[Any, Any]]

Rendering the image with the Water Droplet effect.

Args:

image: Input Image.

Returns:
return np.ndarray:

Image rendered with Water Droplet effect.

return np.ndarray:

Image mask.