Shortcuts

affine

torchvision.transforms.functional.affine(img: torch.Tensor, angle: float, translate: List[int], scale: float, shear: List[float], interpolation: torchvision.transforms.functional.InterpolationMode = <InterpolationMode.NEAREST: 'nearest'>, fill: Optional[List[float]] = None, resample: Optional[int] = None, fillcolor: Optional[List[float]] = None, center: Optional[List[int]] = None)torch.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.NEAREST) are still acceptable.

  • 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, int, float) – deprecated argument and will be removed since v0.10.0. Please use the fill parameter instead.

  • resample (int, optional) – deprecated argument and will be removed since v0.10.0. Please use the interpolation parameter 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:

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