rotate¶
-
torchvision.transforms.functional.
rotate
(img: torch.Tensor, angle: float, interpolation: torchvision.transforms.functional.InterpolationMode = <InterpolationMode.NEAREST: 'nearest'>, expand: bool = False, center: Optional[List[int]] = None, fill: Optional[List[float]] = None, resample: Optional[int] = None) → torch.Tensor[source]¶ Rotate the image by angle. If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions.
- Parameters
img (PIL Image or Tensor) – image to be rotated.
angle (number) – rotation angle value in degrees, counter-clockwise.
interpolation (InterpolationMode) – Desired interpolation enum defined by
torchvision.transforms.InterpolationMode
. Default isInterpolationMode.NEAREST
. If input is Tensor, onlyInterpolationMode.NEAREST
,InterpolationMode.BILINEAR
are supported. For backward compatibility integer values (e.g.PIL.Image[.Resampling].NEAREST
) are still accepted, but deprecated since 0.13 and will be removed in 0.15. Please use InterpolationMode enum.expand (bool, optional) – Optional expansion flag. If true, expands the output image to make it large enough to hold the entire rotated image. If false or omitted, make the output image the same size as the input image. Note that the expand flag assumes rotation around the center and no translation.
center (sequence, optional) – Optional center of rotation. Origin is the upper left corner. Default is the center of the image.
fill (sequence or number, optional) –
Pixel fill value for the area outside the transformed image. If given a number, the value is used for all bands respectively.
Note
In torchscript mode single int/float value is not supported, please use a sequence of length 1:
[value, ]
.resample (int, optional) –
Warning
This parameter was deprecated in
0.12
and will be removed in0.14
. Please useinterpolation
instead.
- Returns
Rotated image.
- Return type
PIL Image or Tensor
Examples using
rotate
:Illustration of transforms