affine

paddle.vision.transforms. affine ( img, angle, translate, scale, shear, interpolation='nearest', fill=0, center=None ) [source]

Apply affine transformation on the image.

Parameters
  • img (PIL.Image|np.array|paddle.Tensor) – Image to be affined.

  • angle (int|float) – The angle of the random rotation in clockwise order.

  • translate (list[float]) – Maximum absolute fraction for horizontal and vertical translations.

  • scale (float) – Scale factor for the image, scale should be positive.

  • shear (list[float]) – Shear angle values which are parallel to the x-axis and y-axis in 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

  • 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.

Returns

Affine Transformed image.

Return type

PIL.Image|np.array|paddle.Tensor

Examples

>>> import paddle
>>> from paddle.vision.transforms import functional as F
>>> fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32)
>>> affined_img = F.affine(fake_img, 45, translate=[0.2, 0.2], scale=0.5, shear=[-10, 10])
>>> print(affined_img.shape)
[3, 256, 300]