- class paddle.vision.transforms. RandomAffine ( degrees, translate=None, scale=None, shear=None, interpolation='nearest', fill=0, center=None, keys=None ) [source]
Random affine transformation of the image.
degrees (int|float|tuple) – The angle interval of the random rotation. If set as a number instead of sequence like (min, max), the range of degrees will be (-degrees, +degrees) in clockwise order. If set 0, will not rotate.
translate (tuple, optional) – Maximum absolute fraction for horizontal and vertical translations. For example translate=(a, b), then horizontal shift is randomly sampled in the range -img_width * a < dx < img_width * a and vertical shift is randomly sampled in the range -img_height * b < dy < img_height * b. Default is None, will not translate.
scale (tuple, optional) – Scaling factor interval, e.g (a, b), then scale is randomly sampled from the range a <= scale <= b. Default is None, will keep original scale and not scale.
shear (sequence or number, optional) – Range of degrees to shear, ranges from -180 to 180 in clockwise order. If set as a number, a shear parallel to the x axis in the range (-shear, +shear) will be applied. Else if set as a sequence of 2 values a shear parallel to the x axis in the range (shear, shear) will be applied. Else if set as a sequence of 4 values, a x-axis shear in (shear, shear) and y-axis shear in (shear, shear) will be applied. Default is None, will not apply shear.
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
fill (int|list|tuple, optional) – Pixel fill value for the area outside the transformed image. If given a number, the value is used for all bands respectively.
center (2-tuple, optional) – Optional center of rotation, (x, y). Origin is the upper left corner. Default is the center of the image.
keys (list[str]|tuple[str], optional) – Same as
BaseTransform. Default: None.
img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
output(PIL.Image|np.ndarray|Paddle.Tensor): An affined image.
A callable object of RandomAffine.
import paddle from paddle.vision.transforms import RandomAffine transform = RandomAffine([-90, 90], translate=[0.2, 0.2], scale=[0.5, 0.5], shear=[-10, 10]) fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32) fake_img = transform(fake_img) print(fake_img.shape)