RandomPerspective¶
- class torchvision.transforms.RandomPerspective(distortion_scale=0.5, p=0.5, interpolation=InterpolationMode.BILINEAR, fill=0)[source]¶
Performs a random perspective transformation of the given image with a given probability. If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions.
- Parameters:
distortion_scale (float) – argument to control the degree of distortion and ranges from 0 to 1. Default is 0.5.
p (float) – probability of the image being transformed. Default is 0.5.
interpolation (InterpolationMode) – Desired interpolation enum defined by
torchvision.transforms.InterpolationMode. Default isInterpolationMode.BILINEAR. If input is Tensor, onlyInterpolationMode.NEAREST,InterpolationMode.BILINEARare supported. The corresponding Pillow integer constants, e.g.PIL.Image.BILINEARare accepted as well.fill (sequence or number) – Pixel fill value for the area outside the transformed image. Default is
0. If given a number, the value is used for all bands respectively.
Examples using
RandomPerspective:- forward(img)[source]¶
- Parameters:
img (PIL Image or Tensor) – Image to be Perspectively transformed.
- Returns:
Randomly transformed image.
- Return type:
PIL Image or Tensor
- static get_params(width: int, height: int, distortion_scale: float) tuple[list[list[int]], list[list[int]]][source]¶
Get parameters for
perspectivefor a random perspective transform.- Parameters:
- Returns:
List containing [top-left, top-right, bottom-right, bottom-left] of the original image, List containing [top-left, top-right, bottom-right, bottom-left] of the transformed image.