← Back to all transforms
PiecewiseAffine
Description
Apply affine transformations that differ between local neighborhoods. This augmentation places a regular grid of points on an image and randomly moves the neighborhood of these point around via affine transformations. This leads to local distortions. This is mostly a wrapper around scikit-image's ``PiecewiseAffine``. See also ``Affine`` for a similar technique. Note: This augmenter is very slow. Try to use ``ElasticTransformation`` instead, which is at least 10x faster. Note: For coordinate-based inputs (keypoints, bounding boxes, polygons, ...), this augmenter still has to perform an image-based augmentation, which will make it significantly slower and not fully correct for such inputs than other transforms. Args: scale (float, tuple of float): Each point on the regular grid is moved around via a normal distribution. This scale factor is equivalent to the normal distribution's sigma. Note that the jitter (how far each point is moved in which direction) is multiplied by the height/width of the image if ``absolute_scale=False`` (default), so this scale can be the same for different sized images. Recommended values are in the range ``0.01`` to ``0.05`` (weak to strong augmentations). * If a single ``float``, then that value will always be used as the scale. * If a tuple ``(a, b)`` of ``float`` s, then a random value will be uniformly sampled per image from the interval ``[a, b]``. nb_rows (int, tuple of int): Number of rows of points that the regular grid should have. Must be at least ``2``. For large images, you might want to pick a higher value than ``4``. You might have to then adjust scale to lower values. * If a single ``int``, then that value will always be used as the number of rows. * If a tuple ``(a, b)``, then a value from the discrete interval ``[a..b]`` will be uniformly sampled per image. nb_cols (int, tuple of int): Number of columns. Analogous to `nb_rows`. interpolation (int): The order of interpolation. The order has to be in the range 0-5: - 0: Nearest-neighbor - 1: Bi-linear (default) - 2: Bi-quadratic - 3: Bi-cubic - 4: Bi-quartic - 5: Bi-quintic mask_interpolation (int): same as interpolation but for mask. cval (number): The constant value to use when filling in newly created pixels. cval_mask (number): Same as cval but only for masks. mode (str): {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional Points outside the boundaries of the input are filled according to the given mode. Modes match the behaviour of `numpy.pad`. absolute_scale (bool): Take `scale` as an absolute value rather than a relative value. keypoints_threshold (float): Used as threshold in conversion from distance maps to keypoints. The search for keypoints works by searching for the argmin (non-inverted) or argmax (inverted) in each channel. This parameters contains the maximum (non-inverted) or minimum (inverted) value to accept in order to view a hit as a keypoint. Use ``None`` to use no min/max. Default: 0.01 Targets: image, mask, keypoints, bboxes Image types: uint8, float32
Parameters
- p: float (default: 0.5)
- scale: int | tuple[int, int] | float | tuple[float, float] (default: (0.03, 0.05))
- nb_rows: int | tuple[int, int] (default: 4)
- nb_cols: int | tuple[int, int] (default: 4)
- interpolation: Literal['cv2.INTER_NEAREST', 'cv2.INTER_LINEAR', 'cv2.INTER_CUBIC', 'cv2.INTER_AREA', 'cv2.INTER_LANCZOS4', 'cv2.INTER_BITS', 'cv2.INTER_NEAREST_EXACT', 'cv2.INTER_MAX'] (default: 1)
- mask_interpolation: Literal['cv2.INTER_NEAREST', 'cv2.INTER_LINEAR', 'cv2.INTER_CUBIC', 'cv2.INTER_AREA', 'cv2.INTER_LANCZOS4', 'cv2.INTER_BITS', 'cv2.INTER_NEAREST_EXACT', 'cv2.INTER_MAX'] (default: 0)
- cval: int (default: 0)
- cval_mask: int (default: 0)
- mode: Literal['constant', 'edge', 'symmetric', 'reflect', 'wrap'] (default: 'constant')
- absolute_scale: bool (default: false)
- keypoints_threshold: float (default: 0.01)
Targets
- Image
- Mask
- BBoxes
- Keypoints
Try it out
Original Image (width = 484, height = 733):
Transformed Image:
Transform not yet applied