← Back to all transforms
RandomGravel
Description
Adds gravel-like artifacts to the input image. This transform simulates the appearance of gravel or small stones scattered across specific regions of an image. It's particularly useful for augmenting datasets of road or terrain images, adding realistic texture variations. Args: gravel_roi (tuple[float, float, float, float]): Region of interest where gravel will be added, specified as (x_min, y_min, x_max, y_max) in relative coordinates [0, 1]. Default: (0.1, 0.4, 0.9, 0.9). number_of_patches (int): Number of gravel patch regions to generate within the ROI. Each patch will contain multiple gravel particles. Default: 2. p (float): Probability of applying the transform. Default: 0.5. Targets: image Image types: uint8, float32 Number of channels: 3 Note: - The gravel effect is created by modifying the saturation channel in the HLS color space. - Gravel particles are distributed within randomly generated patches inside the specified ROI. - This transform is particularly useful for: * Augmenting datasets for road condition analysis * Simulating variations in terrain for computer vision tasks * Adding realistic texture to synthetic images of outdoor scenes Mathematical Formulation: For each gravel patch: 1. A rectangular region is randomly generated within the specified ROI. 2. Within this region, multiple gravel particles are placed. 3. For each particle: - Random (x, y) coordinates are generated within the patch. - A random radius (r) between 1 and 3 pixels is assigned. - A random saturation value (sat) between 0 and 255 is assigned. 4. The saturation channel of the image is modified for each particle: image_hls[y-r:y+r, x-r:x+r, 1] = sat Examples: >>> import numpy as np >>> import albumentations as A >>> image = np.random.randint(0, 256, [100, 100, 3], dtype=np.uint8) # Default usage >>> transform = A.RandomGravel(p=1.0) >>> augmented_image = transform(image=image)["image"] # Custom ROI and number of patches >>> transform = A.RandomGravel( ... gravel_roi=(0.2, 0.2, 0.8, 0.8), ... number_of_patches=5, ... p=1.0 ... ) >>> augmented_image = transform(image=image)["image"] # Combining with other transforms >>> transform = A.Compose([ ... A.RandomGravel(p=0.7), ... A.RandomBrightnessContrast(p=0.5), ... ]) >>> augmented_image = transform(image=image)["image"] References: - Road surface textures: https://en.wikipedia.org/wiki/Road_surface - HLS color space: https://en.wikipedia.org/wiki/HSL_and_HSV
Parameters
- gravel_roi: tuple[float, float, float, float] (default: (0.1, 0.4, 0.9, 0.9))
- number_of_patches: int (default: 2)
- p: float (default: 0.5)
Targets
- Image
Try it out
ⓘ
Original Image:
Result:
Transform result will appear here