albumentations.augmentations.geometric.distortion
Apply bounded XY deformations from a compact control grid to images and annotations. Use it for shape variation in segmentation and medical imaging.
Members
- classElasticTransform
- classGridDistortion
- classOpticalDistortion
- classPiecewiseAffine
- classPixelSpread
- classThinPlateSpline
- classWaterRefraction
ElasticTransformclass
ElasticTransform(
displacement_range: tuple[float, float] = (0.02, 0.05),
control_grid_shape: tuple[int, int] = (7, 7),
interpolation: 0 | 1 | 2 | 3 | 4 = 1,
mask_interpolation: 0 | 1 | 2 | 3 | 4 = 0,
border_mode: 0 | 1 | 2 | 3 | 4 = 0,
fill: tuple[float, ...] | float = 0,
fill_mask: tuple[float, ...] | float = 0,
p: float = 0.5
)Apply bounded XY deformations from a compact control grid to images and annotations. Use it for shape variation in segmentation and medical imaging. `displacement_range` is measured relative to the shorter span between the first and last pixel centers. The sampled cubic B-spline coefficients use pixel units after scaling. One map is shared by every raster and annotation target in an invocation; volumes receive the same XY deformation on every depth slice.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| displacement_range | tuple[float, float] | (0.02, 0.05) | Range for the sampled relative displacement magnitude. |
| control_grid_shape | tuple[int, int] | (7, 7) | Number of cubic B-spline coefficient rows and columns, each at least 4. |
| interpolation | One of:
| 1 | Interpolation used for images. |
| mask_interpolation | One of:
| 0 | Interpolation used for masks. |
| border_mode | One of:
| 0 | OpenCV border mode for raster targets. |
| fill | One of:
| 0 | Fill value for images. |
| fill_mask | One of:
| 0 | Fill value for masks. |
| p | float | 0.5 | Probability of applying the transform. |
Examples
>>> import numpy as np
>>> import albumentations as A
>>> image = np.zeros((100, 100, 3), dtype=np.uint8)
>>> mask = np.zeros((100, 100), dtype=np.uint8)
>>> bboxes = np.array([[10, 10, 50, 50]], dtype=np.float32)
>>> bbox_labels = [1]
>>> keypoints = np.array([[20, 30]], dtype=np.float32)
>>> keypoint_labels = [0]
>>> transform = A.Compose(
... [A.ElasticTransform(displacement_range=(0.02, 0.05), control_grid_shape=(7, 7), p=1.0)],
... bbox_params=A.BboxParams(coord_format="pascal_voc", label_fields=["bbox_labels"]),
... keypoint_params=A.KeypointParams(
... coord_format="xy", label_fields=["keypoint_labels"], label_mapping={}
... ),
... )
>>> transformed = transform(
... image=image,
... mask=mask,
... bboxes=bboxes,
... bbox_labels=bbox_labels,
... keypoints=keypoints,
... keypoint_labels=keypoint_labels,
... )
>>> transformed_image = transformed["image"]
>>> transformed_mask = transformed["mask"]
>>> transformed_bboxes = transformed["bboxes"]
>>> transformed_bbox_labels = transformed["bbox_labels"]
>>> transformed_keypoints = transformed["keypoints"]
>>> transformed_keypoint_labels = transformed["keypoint_labels"]Notes
The constructor enforces `2 * high * sqrt((rows - 3)^2 + (columns - 3)^2) < 0.75`. `ReplayCompose` stores the compact sampled coefficient lattice and replays it for the same spatial shape. Applied configuration fixes the realized magnitude but samples a new lattice.
GridDistortionclass
GridDistortion(
num_steps: int = 5,
distort_range: tuple[float, float] = (-0.3, 0.3),
interpolation: 0 | 1 | 2 | 3 | 4 = 1,
normalized: bool = True,
mask_interpolation: 0 | 1 | 2 | 3 | 4 = 0,
keypoint_remapping_method: 'direct' | 'mask' = mask,
p: float = 0.5,
border_mode: 0 | 1 | 2 | 3 | 4 = 0,
fill: tuple[float, ...] | float = 0,
fill_mask: tuple[float, ...] | float = 0,
map_resolution_range: tuple[float, float] = (1.0, 1.0)
)Apply grid distortion by dividing the image into cells and warping each. Params: num_steps, distort_range, interpolation, normalized. This transformation divides the image into a grid and randomly distorts each cell, creating localized warping effects. It's particularly useful for data augmentation in tasks like medical image analysis, OCR, and other domains where local geometric variations are meaningful.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| num_steps | int | 5 | Number of grid cells on each side of the image. Higher values create more granular distortions. Must be at least 1. Default: 5. |
| distort_range | tuple[float, float] | (-0.3, 0.3) | Range of distortion, sampled per image. Higher absolute values create stronger distortions. Should be in [-1, 1]. Default: (-0.3, 0.3). |
| interpolation | One of:
| 1 | OpenCV interpolation method used for image transformation. Options include cv2.INTER_LINEAR, cv2.INTER_CUBIC, etc. Default: cv2.INTER_LINEAR. |
| normalized | bool | True | If True, ensures that the distortion does not move pixels outside the image boundaries. This can result in less extreme distortions but guarantees that no information is lost. Default: True. |
| mask_interpolation | One of:
| 0 | Flag that is used to specify the interpolation algorithm for mask. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_NEAREST. |
| keypoint_remapping_method | One of:
| mask | Method to use for keypoint remapping. - "mask": Uses mask-based remapping. Faster, especially for many keypoints, but may be less accurate for large distortions. Recommended for large images or many keypoints. - "direct": Uses inverse mapping. More accurate for large distortions but slower. Default: "mask" |
| p | float | 0.5 | Probability of applying the transform. Default: 0.5. |
| border_mode | One of:
| 0 | - |
| fill | One of:
| 0 | - |
| fill_mask | One of:
| 0 | - |
| map_resolution_range | tuple[float, float] | (1.0, 1.0) | Range for sampling the displacement map resolution relative to the target size. Values below 1.0 generate lower-resolution maps and upscale them, trading precision for speed. Default: (1.0, 1.0). |
Examples
>>> import albumentations as A
>>> transform = A.Compose([
... A.GridDistortion(num_steps=5, distort_range=(-0.3, 0.3), p=1.0),
... ])
>>> transformed = transform(image=image, mask=mask, bboxes=bboxes, keypoints=keypoints)
>>> transformed_image = transformed['image']
>>> transformed_mask = transformed['mask']
>>> transformed_bboxes = transformed['bboxes']
>>> transformed_keypoints = transformed['keypoints']Notes
- The same distortion is applied to all targets (image, mask, bboxes, keypoints) to maintain consistency. - When normalized=True, the distortion is adjusted to ensure all pixels remain within the image boundaries.
OpticalDistortionclass
OpticalDistortion(
distort_range: tuple[float, float] = (-0.05, 0.05),
interpolation: 0 | 1 | 2 | 3 | 4 = 1,
mask_interpolation: 0 | 1 | 2 | 3 | 4 = 0,
mode: 'camera' | 'fisheye' = camera,
keypoint_remapping_method: 'direct' | 'mask' = mask,
p: float = 0.5,
border_mode: 0 | 1 | 2 | 3 | 4 = 0,
fill: tuple[float, ...] | float = 0,
fill_mask: tuple[float, ...] | float = 0,
map_resolution_range: tuple[float, float] = (1.0, 1.0)
)Apply optical distortion (lens/camera or fisheye model) to images, masks, bboxes, keypoints. Params: distort_range, mode (camera/fisheye), interpolation. Supports two distortion models: 1. Camera matrix model (original): Uses OpenCV's camera calibration model with k1=k2=k distortion coefficients 2. Fisheye model: Direct radial distortion: r_dist = r * (1 + gamma * r²)
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| distort_range | tuple[float, float] | (-0.05, 0.05) | Range of distortion coefficient, sampled per image. For camera model: recommended range (-0.05, 0.05). For fisheye model: recommended range (-0.3, 0.3). Default: (-0.05, 0.05) |
| interpolation | One of:
| 1 | Interpolation method used for image transformation. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR. |
| mask_interpolation | One of:
| 0 | Flag that is used to specify the interpolation algorithm for mask. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_NEAREST. |
| mode | One of:
| camera | Distortion model to use: - 'camera': Original camera matrix model - 'fisheye': Fisheye lens model Default: 'camera' |
| keypoint_remapping_method | One of:
| mask | Method to use for keypoint remapping. - "mask": Uses mask-based remapping. Faster, especially for many keypoints, but may be less accurate for large distortions. Recommended for large images or many keypoints. - "direct": Uses inverse mapping. More accurate for large distortions but slower. Default: "mask" |
| p | float | 0.5 | Probability of applying the transform. Default: 0.5. |
| border_mode | One of:
| 0 | - |
| fill | One of:
| 0 | - |
| fill_mask | One of:
| 0 | - |
| map_resolution_range | tuple[float, float] | (1.0, 1.0) | Range for sampling the displacement map resolution relative to the target size. Values below 1.0 generate lower-resolution maps and upscale them, trading precision for speed. Default: (1.0, 1.0). |
Examples
>>> import albumentations as A
>>> transform = A.Compose([
... A.OpticalDistortion(distort_range=(-0.1, 0.1), p=1.0),
... ])
>>> transformed = transform(image=image, mask=mask, bboxes=bboxes, keypoints=keypoints)
>>> transformed_image = transformed['image']
>>> transformed_mask = transformed['mask']
>>> transformed_bboxes = transformed['bboxes']
>>> transformed_keypoints = transformed['keypoints']Notes
- The distortion is applied using OpenCV's initUndistortRectifyMap and remap functions. - The distortion coefficient (k) is randomly sampled from the distort_range range. - Bounding boxes and keypoints are transformed along with the image to maintain consistency. - Fisheye model directly applies radial distortion
PiecewiseAffineclass
PiecewiseAffine(
scale_range: tuple[float, float] = (0.03, 0.05),
nb_rows_range: tuple[int, int] = (4, 4),
nb_cols_range: tuple[int, int] = (4, 4),
interpolation: 0 | 1 | 2 | 3 | 4 = 1,
mask_interpolation: 0 | 1 | 2 | 3 | 4 = 0,
absolute_scale: bool = False,
keypoint_remapping_method: 'direct' | 'mask' = mask,
p: float = 0.5,
border_mode: 0 | 1 | 2 | 3 | 4 = 0,
fill: tuple[float, ...] | float = 0,
fill_mask: tuple[float, ...] | float = 0,
map_resolution_range: tuple[float, float] = (1.0, 1.0)
)Apply piecewise affine transformations via a regular grid of control points. Params: scale_range, nb_rows_range, nb_cols_range, interpolation. This augmentation places a regular grid of points on an image and randomly moves the neighborhood of these points around via affine transformations. This leads to local distortions in the image.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| scale_range | tuple[float, float] | (0.03, 0.05) | Standard deviation of the normal distributions used to sample random corner offsets, sampled per image. Recommended values are in (0.01, 0.05) for small distortions and (0.05, 0.1) for larger distortions. Default: (0.03, 0.05). |
| nb_rows_range | tuple[int, int] | (4, 4) | Range for the number of rows in the regular grid; a value from the discrete interval [a..b] is uniformly sampled per image. Both ends must be >= 2. Default: (4, 4). |
| nb_cols_range | tuple[int, int] | (4, 4) | Range for the number of columns in the regular grid; a value from the discrete interval [a..b] is uniformly sampled per image. Both ends must be >= 2. Default: (4, 4). |
| interpolation | One of:
| 1 | Flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR. |
| mask_interpolation | One of:
| 0 | Flag that is used to specify the interpolation algorithm for mask. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_NEAREST. |
| absolute_scale | bool | False | If set to True, the value of the scale parameter will be treated as an absolute pixel value. If set to False, it will be treated as a fraction of the image height and width. Default: False. |
| keypoint_remapping_method | One of:
| mask | Method to use for keypoint remapping. - "mask": Uses mask-based remapping. Faster, especially for many keypoints, but may be less accurate for large distortions. Recommended for large images or many keypoints. - "direct": Uses inverse mapping. More accurate for large distortions but slower. Default: "mask" |
| p | float | 0.5 | Probability of applying the transform. Default: 0.5. |
| border_mode | One of:
| 0 | - |
| fill | One of:
| 0 | - |
| fill_mask | One of:
| 0 | - |
| map_resolution_range | tuple[float, float] | (1.0, 1.0) | Range for sampling the displacement map resolution relative to the target size. Values below 1.0 generate lower-resolution maps and upscale them, trading precision for speed. Default: (1.0, 1.0). |
Examples
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.Compose([
... A.PiecewiseAffine(scale_range=(0.03, 0.05), nb_rows_range=(4, 4), nb_cols_range=(4, 4), p=0.5),
... ])
>>> transformed = transform(image=image)
>>> transformed_image = transformed["image"]Notes
- The augmentation may not always produce visible effects, especially with small scale values. - For keypoints and bounding boxes, the transformation might move them outside the image boundaries. In such cases, the keypoints will be set to (-1, -1) and the bounding boxes will be removed.
PixelSpreadclass
PixelSpread(
radius: int = 2,
interpolation: 0 | 1 | 2 | 3 | 4 = 0,
mask_interpolation: 0 | 1 | 2 | 3 | 4 = 0,
keypoint_remapping_method: 'direct' | 'mask' = mask,
border_mode: 0 | 1 | 2 | 3 | 4 = 4,
fill: tuple[float, ...] | float = 0,
fill_mask: tuple[float, ...] | float = 0,
map_resolution_range: tuple[float, float] = (1.0, 1.0),
p: float = 0.5
)Stochastically displaces each pixel by sampling its value from a random source within a local square neighborhood, without blurring or coherent warping. For every output pixel `(row, col)` an offset `(d_row, d_col)` is drawn independently and uniformly from the square neighborhood `[-radius, radius] x [-radius, radius]` and the pixel value is read from source position `(row + d_row, col + d_col)`. The same dense remapping field is applied to all targets (image, mask, bboxes, keypoints) so spatial annotations remain consistent. This occupies a useful middle ground between blur (which aggregates a neighborhood) and smooth elastic warps (which produce coherent displacement fields): the displacement field is intentionally non-smooth and high-frequency, making it suitable for simulating sensor noise, compression artifacts, fine-grained texture corruption, and domain shifts where local pixel structure becomes unstable but global object geometry is preserved.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| radius | int | 2 | Maximum pixel displacement in each direction. The sampling neighborhood is the square `[-radius, radius] x [-radius, radius]`, giving `(2*radius+1)^2` possible source locations per output pixel. Must be >= 1. Default: 2. |
| interpolation | One of:
| 0 | Interpolation flag used by `cv2.remap`. Default: `cv2.INTER_NEAREST`. Nearest-neighbor is the natural choice because the effect is explicitly about discrete pixel reassignment, not sub-pixel blending. |
| mask_interpolation | One of:
| 0 | Interpolation flag for masks. Default: `cv2.INTER_NEAREST`. |
| keypoint_remapping_method | One of:
| mask | Strategy for remapping keypoints. Default: `"mask"`. |
| border_mode | One of:
| 4 | OpenCV border extrapolation mode for out-of-bounds source lookups. Default: `cv2.BORDER_REFLECT_101`. |
| fill | One of:
| 0 | Fill value used when `border_mode` is `cv2.BORDER_CONSTANT`. Default: 0. |
| fill_mask | One of:
| 0 | Fill value for masks under constant border. Default: 0. |
| map_resolution_range | tuple[float, float] | (1.0, 1.0) | Range for sampling the displacement map resolution relative to the target size. Values below 1.0 generate lower-resolution maps and upscale them, trading precision for speed. Default: (1.0, 1.0). |
| p | float | 0.5 | Probability of applying the transform. Default: 0.5. |
Examples
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> mask = np.random.randint(0, 2, (100, 100), dtype=np.uint8)
>>> bboxes = np.array([[10, 10, 50, 50]], dtype=np.float32)
>>> bbox_labels = [1]
>>> keypoints = np.array([[20, 30]], dtype=np.float32)
>>> keypoint_labels = [0]
>>>
>>> transform = A.Compose([
... A.PixelSpread(radius=3, p=1.0)
... ], bbox_params=A.BboxParams(coord_format='pascal_voc', label_fields=['bbox_labels']),
... keypoint_params=A.KeypointParams(coord_format='xy', label_fields=['keypoint_labels']))
>>>
>>> result = transform(
... image=image,
... mask=mask,
... bboxes=bboxes,
... bbox_labels=bbox_labels,
... keypoints=keypoints,
... keypoint_labels=keypoint_labels,
... )
>>> transformed_image = result['image']
>>> transformed_mask = result['mask']ThinPlateSplineclass
ThinPlateSpline(
scale_range: tuple[float, float] = (0.2, 0.4),
num_control_points: int = 4,
interpolation: 0 | 1 | 2 | 3 | 4 = 1,
mask_interpolation: 0 | 1 | 2 | 3 | 4 = 0,
keypoint_remapping_method: 'direct' | 'mask' = mask,
p: float = 0.5,
border_mode: 0 | 1 | 2 | 3 | 4 = 0,
fill: tuple[float, ...] | float = 0,
fill_mask: tuple[float, ...] | float = 0,
map_resolution_range: tuple[float, float] = (1.0, 1.0)
)Apply Thin Plate Spline (TPS) for smooth, non-rigid deformations. Control points warp the image like pins on a thin plate; smooth interpolation between points. Imagine the image printed on a thin metal plate that can be bent and warped smoothly: - Control points act like pins pushing or pulling the plate - The plate resists sharp bending, creating smooth deformations - The transformation maintains continuity (no tears or folds) - Areas between control points are interpolated naturally The transform works by: 1. Creating a regular grid of control points (like pins in the plate) 2. Randomly displacing these points (like pushing/pulling the pins) 3. Computing a smooth interpolation (like the plate bending) 4. Applying the resulting deformation to the image
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| scale_range | tuple[float, float] | (0.2, 0.4) | Range for random displacement of control points. Values should be in [0.0, 1.0]: - 0.0: No displacement (identity transform) - 0.1: Subtle warping - 0.2-0.4: Moderate deformation (recommended range) - 0.5+: Strong warping Default: (0.2, 0.4) |
| num_control_points | int | 4 | Number of control points per side. Creates a grid of num_control_points x num_control_points points. - 2: Minimal deformation (affine-like) - 3-4: Moderate flexibility (recommended) - 5+: More local deformation control Must be >= 2. Default: 4 |
| interpolation | One of:
| 1 | OpenCV interpolation flag. Used for image sampling. See also: cv2.INTER_* Default: cv2.INTER_LINEAR |
| mask_interpolation | One of:
| 0 | OpenCV interpolation flag. Used for mask sampling. See also: cv2.INTER_* Default: cv2.INTER_NEAREST |
| keypoint_remapping_method | One of:
| mask | Method to use for keypoint remapping. - "mask": Uses mask-based remapping. Faster, especially for many keypoints, but may be less accurate for large distortions. Recommended for large images or many keypoints. - "direct": Uses inverse mapping. More accurate for large distortions but slower. Default: "mask" |
| p | float | 0.5 | Probability of applying the transform. Default: 0.5 |
| border_mode | One of:
| 0 | - |
| fill | One of:
| 0 | - |
| fill_mask | One of:
| 0 | - |
| map_resolution_range | tuple[float, float] | (1.0, 1.0) | Range for sampling the displacement map resolution relative to the target size. Values below 1.0 generate lower-resolution maps and upscale them, trading precision for speed. Default: (1.0, 1.0). |
Examples
>>> import numpy as np
>>> import albumentations as A
>>> import cv2
>>>
>>> # Create sample data
>>> image = np.zeros((100, 100, 3), dtype=np.uint8)
>>> mask = np.zeros((100, 100), dtype=np.uint8)
>>> mask[25:75, 25:75] = 1 # Square mask
>>> bboxes = np.array([[10, 10, 40, 40]]) # Single box
>>> bbox_labels = [1]
>>> keypoints = np.array([[50, 50]]) # Single keypoint at center
>>> keypoint_labels = [0]
>>>
>>> # Set up transform with Compose to handle all targets
>>> transform = A.Compose([
... A.ThinPlateSpline(scale_range=(0.2, 0.4), p=1.0)
... ], bbox_params=A.BboxParams(coord_format='pascal_voc', label_fields=['bbox_labels']),
... keypoint_params=A.KeypointParams(coord_format='xy', label_fields=['keypoint_labels']))
>>>
>>> # Apply to all targets
>>> result = transform(
... image=image,
... mask=mask,
... bboxes=bboxes,
... bbox_labels=bbox_labels,
... keypoints=keypoints,
... keypoint_labels=keypoint_labels
... )
>>>
>>> # Access transformed results
>>> transformed_image = result['image']
>>> transformed_mask = result['mask']
>>> transformed_bboxes = result['bboxes']
>>> transformed_bbox_labels = result['bbox_labels']
>>> transformed_keypoints = result['keypoints']
>>> transformed_keypoint_labels = result['keypoint_labels']Notes
- The transformation preserves smoothness and continuity - Stronger scale values may create more extreme deformations - Higher number of control points allows more local deformations - The same deformation is applied consistently to all targets
References
- [{'description': '"Principal Warps', 'source': 'Thin-Plate Splines and the Decomposition of Deformations" by F.L. Bookstein https://doi.org/10.1109/34.24792'}, {'description': 'Thin Plate Splines in Computer Vision', 'source': 'https://en.wikipedia.org/wiki/Thin_plate_spline'}, {'description': 'Similar implementation in Kornia', 'source': 'https://kornia.readthedocs.io/en/latest/augmentation.html#kornia.augmentation.RandomThinPlateSpline'}]
WaterRefractionclass
WaterRefraction(
amplitude_range: tuple[float, float] = (0.01, 0.05),
wavelength_range: tuple[float, float] = (0.05, 0.2),
num_waves_range: tuple[int, int] = (3, 7),
interpolation: 0 | 1 | 2 | 3 | 4 = 1,
mask_interpolation: 0 | 1 | 2 | 3 | 4 = 0,
keypoint_remapping_method: 'direct' | 'mask' = mask,
border_mode: 0 | 1 | 2 | 3 | 4 = 4,
fill: tuple[float, ...] | float = 0,
fill_mask: tuple[float, ...] | float = 0,
map_resolution_range: tuple[float, float] = (1.0, 1.0),
p: float = 0.5
)Simulate looking through water or wavy glass via sine-wave displacement maps. Params: amplitude_range, wavelength_range, num_waves_range, interpolation. Generates displacement maps from overlaid sine waves at random frequencies, phases, and angles to create a refraction distortion effect.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| amplitude_range | tuple[float, float] | (0.01, 0.05) | Range for maximum displacement as a fraction of image size. Default: (0.01, 0.05). |
| wavelength_range | tuple[float, float] | (0.05, 0.2) | Range for wave period as a fraction of image size. Default: (0.05, 0.2). |
| num_waves_range | tuple[int, int] | (3, 7) | Range for number of overlaid sine waves. More waves = more complex distortion. Default: (3, 7). |
| interpolation | One of:
| 1 | OpenCV interpolation flag. Default: cv2.INTER_LINEAR. |
| mask_interpolation | One of:
| 0 | OpenCV interpolation for masks. Default: cv2.INTER_NEAREST. |
| keypoint_remapping_method | One of:
| mask | - |
| border_mode | One of:
| 4 | OpenCV border mode. Default: cv2.BORDER_REFLECT_101. |
| fill | One of:
| 0 | Fill value for constant border. Default: 0. |
| fill_mask | One of:
| 0 | Fill value for mask borders. Default: 0. |
| map_resolution_range | tuple[float, float] | (1.0, 1.0) | Range for sampling the displacement map resolution relative to the target size. Values below 1.0 generate lower-resolution maps and upscale them, trading precision for speed. Default: (1.0, 1.0). |
| p | float | 0.5 | Probability of applying the transform. Default: 0.5. |
Examples
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.WaterRefraction(amplitude_range=(0.02, 0.04), p=1.0)
>>> result = transform(image=image)["image"]Notes
This is a geometric (DualTransform) because the displacement warps the image geometry - masks, bboxes, and keypoints are transformed accordingly.