affine¶
- 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 [源代码]¶
对图像应用仿射变换,保持图像中心不变。如果图像是 torch Tensor,则应具有 […, H, W] 形状,其中 … 表示任意数量的前导维度。
- 参数:
img (PIL 图像 或 Tensor) – 要变换的图像。
angle (数字) – 旋转角度,以度为单位,介于 -180 和 180 之间,顺时针方向。
translate (python:整数 序列) – 水平和垂直平移(旋转后平移)
scale (float) – 整体缩放比例
shear (float 或 序列) – 剪切角度值,以度为单位,介于 -180 到 180 之间,顺时针方向。如果指定序列,则第一个值对应于平行于 x 轴的剪切,而第二个值对应于平行于 y 轴的剪切。
interpolation (InterpolationMode) – 期望的插值枚举,由
torchvision.transforms.InterpolationMode
定义。默认为InterpolationMode.NEAREST
。如果输入是 Tensor,则仅支持InterpolationMode.NEAREST
、InterpolationMode.BILINEAR
。也接受相应的 Pillow 整数常量,例如PIL.Image.BILINEAR
。fill (序列 或 数字, 可选) –
变换后图像外部区域的像素填充值。如果给定一个数字,则该值分别用于所有波段。
注意
在 torchscript 模式下,不支持单个 int/float 值,请使用长度为 1 的序列:
[value, ]
。center (序列, 可选) – 可选的旋转中心。原点是左上角。默认为图像的中心。
- 返回:
变换后的图像。
- 返回类型:
PIL 图像或 Tensor
使用
affine
的示例