rotate¶
- torchvision.transforms.functional.rotate(img: Tensor, angle: float, interpolation: InterpolationMode = InterpolationMode.NEAREST, expand: bool = False, center: Optional[List[int]] = None, fill: Optional[List[float]] = None) Tensor [source]¶
依據角度旋轉影像。如果影像是 torch Tensor,預期其形狀為 […, H, W],其中 … 表示任意數量的領先維度。
- 參數:
img (PIL Image 或 Tensor) – 要旋轉的影像。
angle (數字) – 旋轉角度值,以度為單位,逆時針方向。
interpolation (InterpolationMode) – 期望的插值枚舉,由
torchvision.transforms.InterpolationMode
定義。預設值為InterpolationMode.NEAREST
。如果輸入是 Tensor,則僅支援InterpolationMode.NEAREST
、InterpolationMode.BILINEAR
。也接受相應的 Pillow 整數常數,例如PIL.Image.BILINEAR
。expand (bool, optional) – 可選的擴展標誌。 如果為 true,則擴展輸出影像,使其足夠大以容納整個旋轉影像。 如果為 false 或省略,則使輸出影像的大小與輸入影像的大小相同。 請注意,expand 標誌假定繞中心旋轉且沒有平移。
center (序列, optional) – 可選的旋轉中心。 原點是左上角。 預設值是影像的中心。
fill (序列 或 數字, optional) –
轉換後的影像外部區域的像素填充值。 如果給定一個數字,則該值分別用於所有通道。
注意
在 torchscript 模式下,不支援單個 int/float 值,請使用長度為 1 的序列:
[value, ]
。
- 返回:
旋轉後的影像。
- 返回類型:
PIL Image 或 Tensor
使用
rotate
的範例