Rotate
Rotate the input by an angle selected randomly from the uniform distribution.
limitRange from which a random angle is picked. If limit is a single float, an angle is picked from (-limit, limit). Default: (-90, 90)
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.
rotate_methodMethod to rotate bounding boxes. Should be 'largest_box' or 'ellipse'. Default: 'largest_box'
crop_borderWhether to crop border after rotation. If True, the output image size might differ from the input. Default: False
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
>>> # Create example 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] # Class labels for bounding boxes
>>> keypoints = np.array([[20, 30], [60, 70]], dtype=np.float32)
>>> keypoint_labels = [0, 1] # Labels for keypoints
>>> # Define the transform
>>> transform = A.Compose([
... A.Rotate(limit=45, 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 to all targets
>>> transformed = transform(
... image=image,
... mask=mask,
... bboxes=bboxes,
... bbox_labels=bbox_labels,
... keypoints=keypoints,
... keypoint_labels=keypoint_labels
... )
>>> rotated_image = transformed["image"]
>>> rotated_mask = transformed["mask"]
>>> rotated_bboxes = transformed["bboxes"]
>>> rotated_bbox_labels = transformed["bbox_labels"]
>>> rotated_keypoints = transformed["keypoints"]
>>> rotated_keypoint_labels = transformed["keypoint_labels"]- The rotation angle is randomly selected for each execution within the range specified by 'limit'.
- When 'crop_border' is False, the output image will have the same size as the input, potentially introducing black triangles in the corners.
- When 'crop_border' is True, the output image is cropped to remove black triangles, which may result in a smaller image.
- Bounding boxes are rotated and may change size or shape.
- Keypoints are rotated around the center of the image.