Shortcuts

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, resample: Optional[int] = None, fillcolor: 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 is InterpolationMode.NEAREST. If input is Tensor, only InterpolationMode.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.

  • 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, ].

  • fillcolor (sequence or number, optional) –

    Warning

    This parameter was deprecated in 0.12 and will be removed in 0.14. Please use fill instead.

  • resample (int, optional) –

    Warning

    This parameter was deprecated in 0.12 and will be removed in 0.14. Please use interpolation instead.

  • 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:

Illustration of transforms

Illustration of transforms

Illustration of transforms

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources