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 Image or Tensor) – 要变换的图像。
angle (number) – 旋转角度,单位为度(-180 到 180 之间),顺时针方向。
translate (sequence of python:integers) – 水平和垂直平移(旋转后的平移)
scale (float) – 整体缩放比例
shear (float or sequence) – 剪切角度值,单位为度(-180 到 180 之间),顺时针方向。如果指定序列,则第一个值对应平行于 x 轴的剪切,第二个值对应平行于 y 轴的剪切。
interpolation (InterpolationMode) – 所需的插值模式,由
torchvision.transforms.InterpolationMode
定义。默认值为InterpolationMode.NEAREST
。如果输入是 Tensor,则仅支持InterpolationMode.NEAREST
和InterpolationMode.BILINEAR
。相应的 Pillow 整型常量,例如PIL.Image.BILINEAR
也可接受。fill (sequence or number, optional) –
变换后图像外部区域的像素填充值。如果给定一个数字,该值将分别用于所有通道。
注意
在 torchscript 模式下不支持单个 int/float 值,请使用长度为 1 的序列:
[value, ]
。center (sequence, optional) – 可选的旋转中心。原点是左上角。默认值为图像中心。
- 返回值:
变换后的图像。
- 返回值类型:
PIL Image 或 Tensor
使用 affine 的示例