仿射變換¶
- 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 (數字) – 旋轉角度(以度為單位),範圍在 -180 到 180 之間,順時針方向。
translate (python:整數序列) – 水平和垂直平移(旋轉後的平移)
scale (浮點數) – 整體縮放比例
shear (浮點數 或 序列) – 剪下角度(以度為單位),範圍在 -180 到 180 之間,順時針方向。如果指定了序列,第一個值對應於平行於 x 軸的剪下,第二個值對應於平行於 y 軸的剪下。
interpolation (InterpolationMode) – 由
torchvision.transforms.InterpolationMode定義的所需插值列舉。預設為InterpolationMode.NEAREST。如果輸入是 Tensor,則僅支援InterpolationMode.NEAREST和InterpolationMode.BILINEAR。也接受相應的 Pillow 整數常量,例如PIL.Image.BILINEAR。fill (sequence 或 number, optional) –
變換後圖像區域的畫素填充值。如果提供數字,則該值將分別用於所有通道。
注意
在 torchscript 模式下,不支援單個 int/float 值,請使用長度為 1 的序列:
[value, ]。center (序列, 可選) – 可選的旋轉中心。原點是左上角。預設為影像中心。
- 返回:
轉換後的影像。
- 返回型別:
PIL 影像或張量
使用
affine的示例