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 的示例