Shortcuts

仿射

torchvision.transforms.functional.affine(img: Tensor, angle: float, translate: List[int], scale: float, shear: List[float], interpolation: InterpolationMode = InterpolationMode.NEAREST, fill: Optional[List[float]] = None, center: Optional[List[int]] = None) Tensor[source]

对图像应用仿射变换,保持图像中心不变。 如果图像是torch张量,则期望其具有[…, H, W]形状,其中…表示任意数量的前导维度。

Parameters:
  • img (PIL ImageTensor) – 要转换的图像。

  • angle (number) – 旋转角度,范围在-180到180度之间,顺时针方向。

  • translate (sequence of python:integers) – 水平和垂直平移(旋转后平移)

  • scale (float) – 整体比例

  • shear (floatsequence) – 剪切角度值,范围在-180到180度之间,顺时针方向。 如果指定了一个序列,第一个值对应于平行于x轴的剪切,而第二个值对应于平行于y轴的剪切。

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

  • fill (sequencenumber, 可选) –

    变换图像外部区域的像素填充值。如果给定一个数字,则该值将分别用于所有波段。

    注意

    在torchscript模式下,不支持单个int/float值,请使用长度为1的序列:[value, ]

  • center (sequence, optional) – 可选的旋转中心。原点位于左上角。 默认值为图像的中心。

Returns:

转换后的图像。

Return type:

PIL 图像或张量

使用 affine 的示例:

变换的图示

Illustration of transforms