RandomPerspective

class paddle.vision.transforms. RandomPerspective ( prob=0.5, distortion_scale=0.5, interpolation='nearest', fill=0, keys=None ) [source]

Random perspective transformation with a given probability.

Parameters
  • prob (float, optional) – Probability of using transformation, ranges from 0 to 1, default is 0.5.

  • distortion_scale (float, optional) – Degree of distortion, ranges from 0 to 1, default is 0.5.

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

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

Shape:
  • img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).

  • output(PIL.Image|np.ndarray|Paddle.Tensor): A perspectived image.

Returns

A callable object of RandomPerspective.

Examples

>>> import paddle
>>> from paddle.vision.transforms import RandomPerspective

>>> transform = RandomPerspective(prob=1.0, distortion_scale=0.9)
>>> fake_img = paddle.randn((3, 200, 150)).astype(paddle.float32)
>>> fake_img = transform(fake_img)
>>> print(fake_img.shape)
[3, 200, 150]
get_params ( width, height, distortion_scale )

get_params

Returns

[top-left, top-right, bottom-right, bottom-left] of the original image, endpoints (list[list[int]]): [top-left, top-right, bottom-right, bottom-left] of the transformed image.

Return type

startpoints (list[list[int]])