Shortcuts

随机透视

class torchvision.transforms.RandomPerspective(distortion_scale=0.5, p=0.5, interpolation=InterpolationMode.BILINEAR, fill=0)[source]

对给定图像以给定概率执行随机透视变换。 如果图像是torch张量,则期望其具有[…, H, W]形状,其中…表示任意数量的前导维度。

Parameters:
  • distortion_scale (float) – 用于控制失真程度的参数,范围从0到1。 默认值为0.5。

  • p (float) – 图像被转换的概率。默认值为0.5。

  • 插值 (InterpolationMode) – 由torchvision.transforms.InterpolationMode定义的期望插值枚举。默认是InterpolationMode.BILINEAR。 如果输入是张量,仅支持InterpolationMode.NEAREST, InterpolationMode.BILINEAR。 相应的Pillow整数常量,例如PIL.Image.BILINEAR也被接受。

  • fill (sequencenumber) – 变换图像外部区域的像素填充值。默认值为 0。如果给定一个数字,则该值将分别用于所有波段。

使用 RandomPerspective 的示例:

变换的图示

Illustration of transforms
forward(img)[source]
Parameters:

img (PIL ImageTensor) – 需要进行透视变换的图像。

Returns:

随机变换的图像。

Return type:

PIL 图像或张量

static get_params(width: int, height: int, distortion_scale: float) Tuple[List[List[int]], List[List[int]]][source]

获取用于随机透视变换的perspective参数。

Parameters:
  • width (int) – 图像的宽度。

  • height (int) – 图像的高度。

  • distortion_scale (float) – 用于控制失真程度的参数,范围从0到1。

Returns:

包含原始图像的[左上角, 右上角, 右下角, 左下角]的列表, 包含变换后图像的[左上角, 右上角, 右下角, 左下角]的列表。