(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)
return F_t.affine(
        img, matrix=matrix, interpolation=interpolation.value, fill=fill)
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.

    Args:
        img (PIL Image or Tensor): image to transform.
        angle (number): rotation angle in degrees between -180 and 180, clockwise direction.
        translate (sequence of 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
            :class:`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.

    Returns:
        PIL Image or Tensor: Transformed image.
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.
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 .
def 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) -> Tensor:
    """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.

    Args:
        img (PIL Image or Tensor): image to transform.
        angle (number): rotation angle in degrees between -180 and 180, clockwise direction.
        translate (sequence of 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
            :class:`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.

    Returns:
        PIL Image or Tensor: Transformed image.
    """
    if resample is not None:
        warnings.warn(
            "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
        )
        interpolation = _interpolation_modes_from_int(resample)

    # Backward compatibility with integer value
    if isinstance(interpolation, int):
        warnings.warn(
            "Argument interpolation should be of type InterpolationMode instead of int. "
            "Please, use InterpolationMode enum.")
        interpolation = _interpolation_modes_from_int(interpolation)

    if fillcolor is not None:
        warnings.warn(
            "Argument fillcolor is deprecated and will be removed since v0.10.0. Please, use fill instead"
        )
        fill = fillcolor

    if not isinstance(angle, (int, float)):
        raise TypeError("Argument angle should be int or float")

    if not isinstance(translate, (list, tuple)):
        raise TypeError("Argument translate should be a sequence")

    if len(translate) != 2:
        raise ValueError("Argument translate should be a sequence of length 2")

    if scale <= 0.0:
        raise ValueError("Argument scale should be positive")

    if not isinstance(shear, (numbers.Number, (list, tuple))):
        raise TypeError(
            "Shear should be either a single value or a sequence of two values")

    if not isinstance(interpolation, InterpolationMode):
        raise TypeError("Argument interpolation should be a InterpolationMode")

    if isinstance(angle, int):
        angle = float(angle)

    if isinstance(translate, tuple):
        translate = list(translate)

    if isinstance(shear, numbers.Number):
        shear = [shear, 0.0]

    if isinstance(shear, tuple):
        shear = list(shear)

    if len(shear) == 1:
        shear = [shear[0], shear[0]]

    if len(shear) != 2:
        raise ValueError(
            "Shear should be a sequence containing two values. Got {}".format(
                shear))

    img_size = _get_image_size(img)
    if not isinstance(img, torch.Tensor):
        # center = (img_size[0] * 0.5 + 0.5, img_size[1] * 0.5 + 0.5)
        # it is visually better to estimate the center without 0.5 offset
        # otherwise image rotated by 90 degrees is shifted vs output image of torch.rot90 or F_t.affine
        center = [img_size[0] * 0.5, img_size[1] * 0.5]
        matrix = _get_inverse_affine_matrix(center, angle, translate, scale,
                                            shear)
        pil_interpolation = pil_modes_mapping[interpolation]
        return F_pil.affine(
            img, matrix=matrix, interpolation=pil_interpolation, fill=fill)

    translate_f = [1.0 * t for t in translate]
    matrix = _get_inverse_affine_matrix([0.0, 0.0], angle, translate_f, scale,
                                        shear)
    return F_t.affine(
        img, matrix=matrix, interpolation=interpolation.value, fill=fill)
def 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 ) -> Tensor : if resample is not None : warnings . warn ( "Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead" ) interpolation = _interpolation_modes_from_int ( resample ) # Backward compatibility with integer value if isinstance ( interpolation , int ) : warnings . warn ( "Argument interpolation should be of type InterpolationMode instead of int. " "Please, use InterpolationMode enum." ) interpolation = _interpolation_modes_from_int ( interpolation ) if fillcolor is not None : warnings . warn ( "Argument fillcolor is deprecated and will be removed since v0.10.0. Please, use fill instead" ) fill = fillcolor if not isinstance ( angle , ( int , float ) ) : raise TypeError ( "Argument angle should be int or float" ) if not isinstance ( translate , ( list , tuple ) ) : raise TypeError ( "Argument translate should be a sequence" ) if len ( translate ) != 2 : raise ValueError ( "Argument translate should be a sequence of length 2" ) if scale <= 0.0 : raise ValueError ( "Argument scale should be positive" ) if not isinstance ( shear , ( numbers . Number , ( list , tuple ) ) ) : raise TypeError ( "Shear should be either a single value or a sequence of two values" ) if not isinstance ( interpolation , InterpolationMode ) : raise TypeError ( "Argument interpolation should be a InterpolationMode" ) if isinstance ( angle , int ) : angle = float ( angle ) if isinstance ( translate , tuple ) : translate = list ( translate ) if isinstance ( shear , numbers . Number ) : shear = [ shear , 0.0 ] if isinstance ( shear , tuple ) : shear = list ( shear ) if len ( shear ) == 1 : shear = [ shear [ 0 ] , shear [ 0 ] ] if len ( shear ) != 2 : raise ValueError ( "Shear should be a sequence containing two values. Got {}" . format ( shear ) ) img_size = _get_image_size ( img ) if not isinstance ( img , torch . Tensor ) : # center = (img_size[0] * 0.5 + 0.5, img_size[1] * 0.5 + 0.5) # it is visually better to estimate the center without 0.5 offset # otherwise image rotated by 90 degrees is shifted vs output image of torch.rot90 or F_t.affine center = [ img_size [ 0 ] * 0.5 , img_size [ 1 ] * 0.5 ] matrix = _get_inverse_affine_matrix ( center , angle , translate , scale , shear ) pil_interpolation = pil_modes_mapping [ interpolation ] return F_pil . affine ( img , matrix = matrix , interpolation = pil_interpolation , fill = fill ) translate_f = [ 1.0 * t for t in translate ] matrix = _get_inverse_affine_matrix ( [ 0.0 , 0.0 ] , angle , translate_f , scale , shear ) return F_t . affine ( img , matrix = matrix , interpolation = interpolation . value , fill = fill )