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 [source]ΒΆ
Apply affine transformation on the image keeping image center invariant. 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 transform.
angle (number) β rotation angle in degrees between -180 and 180, clockwise direction.
translate (sequence of python:integers) β horizontal and vertical translations (post-rotation translation)
scale (float) β overall scale
shear (float or sequence) β shear angle value in degrees between -180 to 180, clockwise direction. If a sequence is specified, the first value corresponds to a shear parallel to the x-axis, while the second value corresponds to a shear parallel to the y-axis.
interpolation (InterpolationMode) β Desired interpolation enum defined by
torchvision.transforms.InterpolationMode
. Default isInterpolationMode.NEAREST
. If input is Tensor, onlyInterpolationMode.NEAREST
,InterpolationMode.BILINEAR
are supported. The corresponding Pillow integer constants, e.g.PIL.Image.BILINEAR
are accepted as well.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, ]
.center (sequence, optional) β Optional center of rotation. Origin is the upper left corner. Default is the center of the image.
- Returns:
Transformed image.
- Return type:
PIL Image or Tensor
Examples using
affine
: