One-step affine: random shift, scale, and rotation. Limits sampled per call; good for pose or scale augmentation without separate transforms.
shift_rangeshift factor range (low, high) for both height and width.
Absolute values must lie in [-1, 1]. Default: (-0.0625, 0.0625).
scale_rangescaling factor range (low, high). Note that this range
is biased by 1, so sampling happens from (1 + low, 1 + high). Default: (-0.1, 0.1).
rotate_rangerotation range (low, high). Default: (-45, 45).
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.
border_modeflag that is used to specify the pixel extrapolation method. Should be one of: cv2.BORDER_CONSTANT, cv2.BORDER_REPLICATE, cv2.BORDER_REFLECT, cv2.BORDER_WRAP, cv2.BORDER_REFLECT_101. Default: cv2.BORDER_CONSTANT
fillpadding value if border_mode is cv2.BORDER_CONSTANT.
fill_maskpadding value if border_mode is cv2.BORDER_CONSTANT applied for masks.
shift_range_xshift factor range (low, high) for width. If set,
overrides shift_range along the x-axis. Absolute values must lie in [-1, 1].
shift_range_yshift factor range (low, high) for height. If set,
overrides shift_range along the y-axis. Absolute values must lie in [-1, 1].
rotate_methodrotation method used for the bounding boxes. Should be one of "largest_box" or "ellipse". Default: "largest_box"
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.
pprobability of applying the transform. Default: 0.5.
>>> import numpy as np
>>> import albumentations as A
>>> import cv2
>>>
>>> # Prepare sample data
>>> 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], [40, 40, 80, 80]], dtype=np.float32)
>>> bbox_labels = [1, 2]
>>> keypoints = np.array([[20, 30], [60, 70]], dtype=np.float32)
>>> keypoint_labels = [0, 1]
>>>
>>> # Define transform with parameters as tuples when possible
>>> transform = A.Compose([
... A.ShiftScaleRotate(
... shift_range=(-0.0625, 0.0625),
... scale_range=(-0.1, 0.1),
... rotate_range=(-45, 45),
... interpolation=cv2.INTER_LINEAR,
... border_mode=cv2.BORDER_CONSTANT,
... rotate_method="largest_box",
... 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 the transform
>>> transformed = transform(
... image=image,
... mask=mask,
... bboxes=bboxes,
... bbox_labels=bbox_labels,
... keypoints=keypoints,
... keypoint_labels=keypoint_labels
... )
>>>
>>> # Get the transformed data
>>> transformed_image = transformed['image'] # Shifted, scaled and rotated image
>>> transformed_mask = transformed['mask'] # Shifted, scaled and rotated mask
>>> transformed_bboxes = transformed['bboxes'] # Shifted, scaled and rotated bounding boxes
>>> transformed_bbox_labels = transformed['bbox_labels'] # Labels for transformed bboxes
>>> transformed_keypoints = transformed['keypoints'] # Shifted, scaled and rotated keypoints
>>> transformed_keypoint_labels = transformed['keypoint_labels'] # Labels for transformed keypoints