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 = 1)

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.

ccw_sort

Sorts points in counterclockwise order around a center point.

from_config

Instantiate a new instance of this class given the configuration JSON-compliant dictionary encapsulating initialization arguments.

get_bezier_curve

Given an array of points, create a curve through those points.

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_random_points_within_min_dist

Function to create n random points in the unit square, which are min_dst apart, then scale them.

get_type_string

Returns the fully qualified type string of the PerturbImage class or its subclass.

is_usable

Checks if the necessary dependencies (Scipy, Shapely and GeoPandas) 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 = 1) 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 Scipy, Shapely or GeoPandas is not found,

install via pip install nrtk[waterdroplet].

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.

static ccw_sort(points: ndarray[Any, Any]) ndarray[Any, Any]

Sorts points in counterclockwise order around a center point.

static get_bezier_curve(points: ndarray[Any, Any], rad: float = 0.2, edgy: float = 0.0, tol: float = 1e-08) tuple[ndarray[Any, Any], ndarray[Any, Any]]

Given an array of points, create a curve through those points.

rad is a number between 0 and 1 to steer the distance of

control points.

edgy is a parameter which controls how “edgy” the curve is,

edgy=0 is smoothest.

tol is a parameter which controls the tolerance used when

comparing angles. Default is 1e-8.

get_config() dict[str, Any]

Returns the current configuration of the WaterDropletPerturber instance.

Returns:
return dict[str, Any]:

Configuration dictionary with current settings.

static get_random_points_within_min_dist(rng: Generator, n: int = 5, scale: float = 0.8, min_dst: float | None = None, recursive: int = 0) ndarray[Any, Any]

Function to create n random points in the unit square, which are min_dst apart, then scale them.

classmethod is_usable() bool

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

Returns:
return bool:

True if Scipy, Shapely and GeoPandas are available.

perturb(image: ndarray[Any, Any], boxes: Iterable[tuple[AxisAlignedBoundingBox, dict[Hashable, float]]] | None = None, **additional_params: Any) 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 perturbation keyword arguments (currently unused).

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.