RandomRotation

class paddle.vision.transforms. RandomRotation ( degrees, interpolation='nearest', expand=False, center=None, fill=0, keys=None ) [source]

Rotates the image by angle.

Parameters
  • degrees (sequence or float or int) – Range of degrees to select from. If degrees is a number instead of sequence like (min, max), the range of degrees will be (-degrees, +degrees) clockwise order.

  • interpolation (str, optional) – Interpolation method. If omitted, or if the image has only one channel, it is set to PIL.Image.NEAREST or cv2.INTER_NEAREST according the backend. when use pil backend, support method are as following: - “nearest”: Image.NEAREST, - “bilinear”: Image.BILINEAR, - “bicubic”: Image.BICUBIC when use cv2 backend, support method are as following: - “nearest”: cv2.INTER_NEAREST, - “bilinear”: cv2.INTER_LINEAR, - “bicubic”: cv2.INTER_CUBIC

  • expand (bool|optional) – Optional expansion flag. Default: False. If true, expands the output to make it large enough to hold the entire rotated image. If false or omitted, make the output image the same size as the input image. Note that the expand flag assumes rotation around the center and no translation.

  • center (2-tuple|optional) – Optional center of rotation. Origin is the upper left corner. Default is the center of the image.

  • keys (list[str]|tuple[str], optional) – Same as BaseTransform. Default: None.

Examples

import numpy as np
from PIL import Image
from paddle.vision.transforms import RandomRotation

transform = RandomRotation(90)

fake_img = Image.fromarray((np.random.rand(200, 150, 3) * 255.).astype(np.uint8))

fake_img = transform(fake_img)
print(fake_img.size)