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 或 Tensor) – 要轉換的圖像。
angle (number) – 旋轉角度,以度為單位,介於 -180 到 180 之間,順時針方向。
translate (python:integers 序列) – 水平和垂直方向的平移 (旋轉後的平移)
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 (序列 或 數字, optional) –
用於填充轉換後圖像外部區域的像素值。 如果給定一個數字,該值將分別用於所有通道。
注意
在 torchscript 模式下,不支援單個 int/float 值,請使用長度為 1 的序列:
[value, ]
。center (序列, optional) – 可選的旋轉中心。原點是左上角。預設值是圖像的中心。
- 返回:
轉換後的圖像。
- 返回類型:
PIL Image 或 Tensor
使用
affine
的示例