perspective¶
- paddle.vision.transforms. perspective ( img, startpoints, endpoints, interpolation='nearest', fill=0 ) [source]
-
Perform perspective transform of the given image.
- Parameters
-
img (PIL.Image|np.array|paddle.Tensor) – Image to be transformed.
startpoints (list of list of ints) – List containing four lists of two integers corresponding to four corners
[top-left, top-right, bottom-right, bottom-left]
of the original image.endpoints (list of list of ints) – List containing four lists of two integers corresponding to four corners
[top-left, top-right, bottom-right, bottom-left]
of the transformed image.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.
- Returns
-
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) >>> startpoints = [[0, 0], [33, 0], [33, 25], [0, 25]] >>> endpoints = [[3, 2], [32, 3], [30, 24], [2, 25]] >>> perspectived_img = F.perspective(fake_img, startpoints, endpoints) >>> print(perspectived_img.shape) [3, 256, 300]