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.
scale_rangeStandard 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_rangeRange 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_rangeRange 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).
interpolationFlag 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_interpolationFlag 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_scaleIf 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_methodMethod to use for keypoint remapping.
pProbability of applying the transform. Default: 0.5.
>>> 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"]ElasticTransform instead, which is at least 10x faster.