
    ёi'                       % S SK Jr  S SKrS SKrS SKJrJrJr  S SKr	S SK
Jr  S SKrS SKJr  SSKJr  SSKJr  S	S
KJrJrJr  \(       a{  S SKJrJrJr  S SKJr  S SKJr   S SK!J"r"J#r#  S SKJ$r$  S SKJ%r%J&r&J'r'J(r(  \S   r)S\*S'   \S   r+S\*S'   \S   r,S\*S'   \" S\$\ \RZ                  \   5      r.\\$\ \RZ                  \   4   r// r0S/S jr1S0S jr2S1S jr3 S2     S3S jjr4 S4       S5S jjr5  S6         S7S jjr6            S8S jr7S9S jr8S:S jr9S:S  jr:      S;S! jr;S<S" jr<      S=S# jr=S>S$ jr>S% r?   S?                 S@S& jjr@    SA             SBS' jjrAS( rB  SC           SDS) jjrCSESFS* jjrD\  SG           SHS+ jj5       rE\  SG           SIS, jj5       rE  SJS- jrE SK               SLS. jjrFg)M    )annotationsN)TYPE_CHECKINGAnyoverload)Image)	unreached   )Variable)Value   )functional_cv2functional_pilfunctional_tensor)LiteralTypeVarUnion)	TypeAlias	TypeGuard)Tensor)DataLayoutImageSize2Size3Size4)nearestbilinearbicubiclanczoshammingr   _InterpolationPil)r   r   arear   r   _InterpolationCv2)constantedgereflect	symmetric_PaddingMode_ImageDataTc                6    [        U [        R                  5      $ N)
isinstancer   imgs    c/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/vision/transforms/functional.py_is_pil_imager.   <   s    c5;;''    c                L    [        U [        R                  [        [        45      $ )zT
Return True if img is a Tensor for dynamic mode or Variable for static graph mode.
)r*   paddler   r
   r   r+   s    r-   _is_tensor_imager2   @   s     cFMM8U;<<r/   c                b    [        U [        R                  5      =(       a    U R                  S;   $ )N>      r	   )r*   npndarrayndimr+   s    r-   _is_numpy_imager8   G   s!    c2::&?CHH,>?r/   c                v   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " X5      $ [        U 5      (       a  [        R                  " X5      $ UR                  5       S:X  a  U $ U R                  S5      $ )aR  Converts a ``PIL.Image`` or ``numpy.ndarray`` to paddle.Tensor.

Converts a PIL.Image or numpy.ndarray (H x W x C) to a paddle.Tensor of shape (C x H x W).

If input is a grayscale image (H x W), it will be converted to an image of shape (H x W x 1).
And the shape of output tensor will be (1 x H x W).

If you want to keep the shape of output tensor as (H x W x C), you can set data_format = ``HWC`` .

Converts a PIL.Image or numpy.ndarray in the range [0, 255] to a paddle.Tensor in the
range [0.0, 1.0] if the PIL Image belongs to one of the modes (L, LA, P, I, F, RGB, YCbCr,
RGBA, CMYK, 1) or if the numpy.ndarray has dtype = np.uint8.

In the other cases, tensors are returned without scaling.

Args:
    pic (PIL.Image|np.ndarray): Image to be converted to tensor.
    data_format (str, optional): Data format of output tensor, should be 'HWC' or
        'CHW'. Default: 'CHW'.

Returns:
    Tensor: Converted image. Data type is same as input img.

Examples:
    .. code-block:: pycon

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.0).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> tensor = F.to_tensor(fake_img)
        >>> print(tensor.shape)
        paddle.Size([3, 256, 300])

zJpic should be PIL Image or Tensor Image or ndarray with dim=[2 or 3]. Got chw)r   r4   r   )
r.   r8   r2   	TypeErrortypeF_pil	to_tensorF_cv2lower	transpose)picdata_formats     r-   r>   r>   K   s    P 	coc226Fs6K6KXY]^aYbXcd
 	
 Ss00			s00!'')U2sPi8PPr/   c                Z   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " XU5      $ [        U 5      (       a  [        R                  " XU5      $ [        R                  " XU5      $ )aR  
Resizes the image to given size

Args:
    input (PIL.Image|np.ndarray|paddle.Tensor): Image to be resized.
    size (int|list|tuple): Target size of input data, with (height, width) shape.
    interpolation (int|str, optional): Interpolation method. when use pil backend,
        support method are as following:
        - "nearest": Image.NEAREST,
        - "bilinear": Image.BILINEAR,
        - "bicubic": Image.BICUBIC,
        - "box": Image.BOX,
        - "lanczos": Image.LANCZOS,
        - "hamming": Image.HAMMING
        when use cv2 backend, support method are as following:
        - "nearest": cv2.INTER_NEAREST,
        - "bilinear": cv2.INTER_LINEAR,
        - "area": cv2.INTER_AREA,
        - "bicubic": cv2.INTER_CUBIC,
        - "lanczos": cv2.INTER_LANCZOS4

Returns:
    PIL.Image|np.array|paddle.Tensor: Resized image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> converted_img = F.resize(fake_img, 224)
        >>> print(converted_img.size)
        (262, 224)

        >>> converted_img = F.resize(fake_img, (200, 150))
        >>> print(converted_img.size)
        (150, 200)
Jimg should be PIL Image or Tensor Image or ndarray with dim=[2 or 3]. Got )	r.   r8   r2   r;   r<   r=   resizeF_tr?   )r,   sizeinterpolations      r-   rF   rF      s    \ 	coc226Fs6K6KXY]^aYbXcd
 	
 S||C}55	#		zz#]33||C}55r/   c                Z   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " XX#5      $ [        U 5      (       a  [        R                  " XX#5      $ [        R                  " XX#5      $ )a,  
Pads the given PIL.Image or numpy.array or paddle.Tensor on all sides with specified padding mode and fill value.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be padded.
    padding (int|list|tuple): Padding on each border. If a single int is provided this
        is used to pad all borders. If list/tuple of length 2 is provided this is the padding
        on left/right and top/bottom respectively. If a list/tuple of length 4 is provided
        this is the padding for the left, top, right and bottom borders
        respectively.
    fill (float, optional): Pixel fill value for constant fill. If a tuple of
        length 3, it is used to fill R, G, B channels respectively.
        This value is only used when the padding_mode is constant. Default: 0.
    padding_mode: Type of padding. Should be: constant, edge, reflect or symmetric. Default: 'constant'.

        - constant: pads with a constant value, this value is specified with fill

        - edge: pads with the last value on the edge of the image

        - reflect: pads with reflection of image (without repeating the last value on the edge)

                   padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
                   will result in [3, 2, 1, 2, 3, 4, 3, 2]

        - symmetric: pads with reflection of image (repeating the last value on the edge)

                     padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
                     will result in [2, 1, 1, 2, 3, 4, 4, 3]

Returns:
    PIL.Image|np.array|paddle.Tensor: Padded image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> padded_img = F.pad(fake_img, padding=1)
        >>> print(padded_img.size)
        (302, 258)

        >>> padded_img = F.pad(fake_img, padding=(2, 1))
        >>> print(padded_img.size)
        (304, 258)
rE   )	r.   r8   r2   r;   r<   r=   padrG   r?   )r,   paddingfillpadding_modes       r-   rK   rK      s    n 	coc226Fs6K6KXY]^aYbXcd
 	
 Syyt::	#		wwsT88yyt::r/   c                `   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " XX#U5      $ [        U 5      (       a  [        R                  " XX#U5      $ [        R                  " XX#U5      $ )a[  Crops the given Image.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be cropped. (0,0) denotes the top left
        corner of the image.
    top (int): Vertical component of the top left corner of the crop box.
    left (int): Horizontal component of the top left corner of the crop box.
    height (int): Height of the crop box.
    width (int): Width of the crop box.

Returns:
    PIL.Image|np.array|paddle.Tensor: Cropped image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> cropped_img = F.crop(fake_img, 56, 150, 200, 100)
        >>> print(cropped_img.size)
        (100, 200)

rE   )	r.   r8   r2   r;   r<   r=   croprG   r?   )r,   topleftheightwidths        r-   rP   rP     s    < 	coc226Fs6K6KXY]^aYbXcd
 	
 Szz#D%88	#		xx$66zz#D%88r/   c                T   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " X5      $ [        U 5      (       a  [        R                  " X5      $ [        R                  " X5      $ )a  Crops the given Image and resize it to desired size.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be cropped. (0,0) denotes the top left corner of the image.
    output_size (sequence or int): (height, width) of the crop box. If int,
        it is used for both directions

Returns:
    PIL.Image|np.array|paddle.Tensor: Cropped image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> cropped_img = F.center_crop(fake_img, (150, 100))
        >>> print(cropped_img.size)
        (100, 150)
rE   )	r.   r8   r2   r;   r<   r=   center_croprG   r?   )r,   output_sizes     r-   rV   rV   .  s    0 	coc226Fs6K6KXY]^aYbXcd
 	
 S  22	#		s00  22r/   c                T   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " U 5      $ [        U 5      (       a  [        R                  " U 5      $ [        R                  " U 5      $ )aY  Horizontally flips the given Image or np.array or paddle.Tensor.

Args:
    img (PIL.Image|np.array|Tensor): Image to be flipped.

Returns:
    PIL.Image|np.array|paddle.Tensor:  Horizontally flipped image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> flipped_img = F.hflip(fake_img)
        >>> print(flipped_img.size)
        (300, 256)

rE   )	r.   r8   r2   r;   r<   r=   hfliprG   r?   r+   s    r-   rY   rY   T      . 	coc226Fs6K6KXY]^aYbXcd
 	
 S{{3	#		yy~{{3r/   c                T   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " U 5      $ [        U 5      (       a  [        R                  " U 5      $ [        R                  " U 5      $ )a\  Vertically flips the given Image or np.array or paddle.Tensor.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be flipped.

Returns:
    PIL.Image|np.array|paddle.Tensor:  Vertically flipped image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> flipped_img = F.vflip(fake_img)
        >>> print(flipped_img.size)
        (300, 256)

rE   )	r.   r8   r2   r;   r<   r=   vfliprG   r?   r+   s    r-   r\   r\   y  rZ   r/   c                   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " X5      $ [        U 5      (       a4  [        R                  " U R                  [        R                  5      U5      $ [        R                  " X5      $ )a4  Adjusts brightness of an Image.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be adjusted.
    brightness_factor (float): How much to adjust the brightness. Can be
        any non negative number. 0 gives a black image, 1 gives the
        original image while 2 increases the brightness by a factor of 2.

Returns:
    PIL.Image|np.array|paddle.Tensor: Brightness adjusted image.

Examples:
    .. code-block:: python
        :name: code-example1

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> np.random.seed(2023)
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> print(fake_img.size)
        (300, 256)
        >>> print(fake_img.load()[1, 1]) # type: ignore[index]
        (61, 155, 171)
        >>> converted_img = F.adjust_brightness(fake_img, 0.5)
        >>> print(converted_img.size)
        (300, 256)
        >>> print(converted_img.load()[1, 1])
        (30, 77, 85)
rE   )r.   r8   r2   r;   r<   r=   adjust_brightnessr?   astyper5   uint8rG   )r,   brightness_factors     r-   r^   r^     s    F 	coc226Fs6K6KXY]^aYbXcd
 	
 S&&s>>			&&szz"((';=NOO$$S<<r/   c                T   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " X5      $ [        U 5      (       a  [        R                  " X5      $ [        R                  " X5      $ )a"  Adjusts contrast of an Image.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be adjusted.
    contrast_factor (float): How much to adjust the contrast. Can be any
        non negative number. 0 gives a solid gray image, 1 gives the
        original image while 2 increases the contrast by a factor of 2.

Returns:
    PIL.Image|np.array|paddle.Tensor: Contrast adjusted image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> converted_img = F.adjust_contrast(fake_img, 0.4)
        >>> print(converted_img.size)
        (300, 256)
rE   )	r.   r8   r2   r;   r<   r=   adjust_contrastr?   rG   )r,   contrast_factors     r-   rc   rc     s    2 	coc226Fs6K6KXY]^aYbXcd
 	
 S$$S::			$$S::""388r/   c                T   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " X5      $ [        U 5      (       a  [        R                  " X5      $ [        R                  " X5      $ )a&  Adjusts color saturation of an image.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be adjusted.
    saturation_factor (float):  How much to adjust the saturation. 0 will
        give a black and white image, 1 will give the original image while
        2 will enhance the saturation by a factor of 2.

Returns:
    PIL.Image|np.array|paddle.Tensor: Saturation adjusted image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> converted_img = F.adjust_saturation(fake_img, 0.4)
        >>> print(converted_img.size)
        (300, 256)

rE   )	r.   r8   r2   r;   r<   r=   adjust_saturationr?   rG   )r,   saturation_factors     r-   rf   rf     s    8 	coc226Fs6K6KXY]^aYbXcd
 	
 S&&s>>			&&s>>$$S<<r/   c                T   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " X5      $ [        U 5      (       a  [        R                  " X5      $ [        R                  " X5      $ )a  Adjusts hue of an image.

The image hue is adjusted by converting the image to HSV and
cyclically shifting the intensities in the hue channel (H).
The image is then converted back to original image mode.

`hue_factor` is the amount of shift in H channel and must be in the
interval `[-0.5, 0.5]`.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be adjusted.
    hue_factor (float):  How much to shift the hue channel. Should be in
        [-0.5, 0.5]. 0.5 and -0.5 give complete reversal of hue channel in
        HSV space in positive and negative direction respectively.
        0 means no shift. Therefore, both -0.5 and 0.5 will give an image
        with complementary colors while 0 gives the original image.

Returns:
    PIL.Image|np.array|paddle.Tensor: Hue adjusted image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> converted_img = F.adjust_hue(fake_img, 0.4)
        >>> print(converted_img.size)
        (300, 256)

rE   )	r.   r8   r2   r;   r<   r=   
adjust_huer?   rG   )r,   
hue_factors     r-   ri   ri      s    F 	coc226Fs6K6KXY]^aYbXcd
 	
 S00			00~~c..r/   c                   [         R                  " U5      n[         R                  " US   5      n[         R                  " US   5      n[         R                  " XW-
  5      [         R                  " U5      -  n[         R                  " XW-
  5      * [         R                  " U5      -  [         R                  " U5      -  [         R                  " U5      -
  n	[         R                  " XW-
  5      [         R                  " U5      -  n
[         R                  " XW-
  5      * [         R                  " U5      -  [         R                  " U5      -  [         R                  " U5      -   nU u  pUu  pX* SU
* US/nU Vs/ s H  nUU-  PM
     nnUS==   US   U* U-
  -  US   U* U-
  -  -   -  ss'   US==   US   U* U-
  -  US   U* U-
  -  -   -  ss'   US==   U-  ss'   US==   U-  ss'   U$ s  snf )Nr   r           r4      r	      )mathradianscostansin)centerangle	translatescaleshearrotsxsyabcdcxcytxtymatrixxs                     r-   _get_affine_matrixr   Q  s    ,,u
C	eAh	B	eAh	B 	TXXb\)A	#(	dhhrl*TXXb\9DHHSMIATXXb\)A	#(	dhhrl*TXXb\9DHHSMIA FBFB S1"a%F!'(Aa%iF(
1IrcBh'&)sRx*@@@I
1IrcBh'&)sRx*@@@I
1IOI
1IOIM )s   8G-c           
     r   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U[        [        45      (       d  [        S5      e[        U[        [        45      (       d  [        S5      e[        U5      S:w  a  [        S5      eUS::  a  [        S5      e[        U[        R                  [        [        445      (       d  [        S5      e[        U[        5      (       d  [        S	5      e[        U[        5      (       a  [        U5      n[        U[        5      (       a  [        U5      n[        U[        R                  5      (       a  US/n[        U[        5      (       a  [        U5      n[        U5      S
:X  a
  US   US   /n[        U5      S:w  a  [        SU 35      eUb&  [        U[        [        45      (       d  [        S5      e[        U 5      (       a?  U R                  u  pUc
  US-  U	S-  /n[!        XqX#U5      n
["        R$                  " X
XV5      $ [        U 5      (       a7  U R&                  SS u  pUc
  US-  U	S-  4n[(        R$                  " XX#XEXg5      $ [        U 5      (       a  SS/nUbF  U R&                  S   U R&                  S   p[+        XxU	/5       VVs/ s H  u  pSXS-  -
  -  PM     nnnU Vs/ s H  nSU-  PM
     nn[!        XXU5      n
[,        R$                  " X
XV5      $ [/        5         gs  snnf s  snf )aa  Apply affine transformation on the image.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be affined.
    angle (int|float): The angle of the random rotation in clockwise order.
    translate (list[float]): Maximum absolute fraction for horizontal and vertical translations.
    scale (float): Scale factor for the image, scale should be positive.
    shear (list[float]): Shear angle values which are parallel to the x-axis and y-axis in clockwise order.
    interpolation (str, optional): Interpolation method. If omitted, or if the
        image has only one channel, it is set to PIL.Image.NEAREST or cv2.INTER_NEAREST
        according the backend.
        When use pil backend, support method are as following:
        - "nearest": Image.NEAREST,
        - "bilinear": Image.BILINEAR,
        - "bicubic": Image.BICUBIC
        When use cv2 backend, support method are as following:
        - "nearest": cv2.INTER_NEAREST,
        - "bilinear": cv2.INTER_LINEAR,
        - "bicubic": cv2.INTER_CUBIC
    fill (int|list|tuple, optional): Pixel fill value for the area outside the transformed
        image. If given a number, the value is used for all bands respectively.
    center (tuple|None, optional): Optional center of rotation, (x, y).
        Origin is the upper left corner.
        Default is the center of the image.

Returns:
    PIL.Image|np.array|paddle.Tensor: Affine Transformed image.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32)
        >>> affined_img = F.affine(
        ...     fake_img,
        ...     45,
        ...     translate=[0.2, 0.2],
        ...     scale=0.5,
        ...     shear=[-10, 10],
        ... )
        >>> print(affined_img.shape)
        paddle.Size([3, 256, 300])
rE   z%Argument angle should be int or floatz'Argument translate should be a sequencer4   z3Argument translate should be a sequence of length 2rl   z!Argument scale should be positivezAShear should be either a single value or a sequence of two valuesz)Argument interpolation should be a stringr   r   z6Shear should be a sequence containing two values. Got Nz$Argument center should be a sequenceg      ?g      ?)r.   r8   r2   r;   r<   r*   intfloatlisttuplelen
ValueErrornumbersNumberstrrH   r   r=   affineshaper?   ziprG   r   )r,   ru   rv   rw   rx   rI   rM   rt   rT   rS   r   center_fr~   sttranslate_fs                   r-   r   r   p  s   p 	coc226Fs6K6KXY]^aYbXcd
 	
 ec5\**?@@i$//ABB
9~NOO|<==egnntUm<==O
 	
 mS))CDD%e)U##O	%((%U
5zQq58$
5zQDUGL
 	
 *VdE]"C"C>??S >ck6C<0F#F9UK||C==s		!A >ck6C<0F||	%
 	
 :IIbM399R=E 14FFO0L0Lqs7{#0L   )22	1sQw	2#H[Ozz#};;K 3s   L..L4c                   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U[        5      (       a  [        U5      n[        U[        5      (       a  [        U5      n[        U 5      (       a  [        R                  " XX#XE5      $ [        U 5      (       a  [        R                  " XX#XE5      $ [        R                  " XX#XE5      $ )a)  Rotates the image by angle.


Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be rotated.
    angle (float or int): In degrees degrees counter clockwise order.
    interpolation (str, optional): Interpolation method. If omitted, or if the
        image has only one channel, it is set to PIL.Image.NEAREST or cv2.INTER_NEAREST
        according the backend. when use pil backend, support method are as following:
        - "nearest": Image.NEAREST,
        - "bilinear": Image.BILINEAR,
        - "bicubic": Image.BICUBIC
        when use cv2 backend, support method are as following:
        - "nearest": cv2.INTER_NEAREST,
        - "bilinear": cv2.INTER_LINEAR,
        - "bicubic": cv2.INTER_CUBIC
    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 (list|tuple|None, optional): Optional center of rotation.
        Origin is the upper left corner.
        Default is the center of the image.
    fill (list|tuple or int, optional): RGB pixel fill value for area outside the rotated image.
        If int, it is used for all channels respectively. Default value is 0.


Returns:
    PIL.Image|np.array|paddle.Tensor: Rotated image.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> rotated_img = F.rotate(fake_img, 90)
        >>> print(rotated_img.size)
        (300, 256)

rE   )r.   r8   r2   r;   r<   r*   r   r   r=   rotaterG   r?   )r,   ru   rI   expandrt   rM   s         r-   r   r     s    h 	coc226Fs6K6KXY]^aYbXcd
 	
 &$v$T{S||CvLL	#		zz#mVJJ||CvLLr/   c                   [         R                  " S[        U 5      -  S45      n[        [	        X5      5       Hg  u  nu  pEUS   US   SSSSUS   * US   -  US   * US   -  /USU-  SS24'   SSSUS   US   SUS   * US   -  US   * US   -  /USU-  S-   SS24'   Mi     [         R
                  " U 5      R                  S/5      n[         R                  R                  X&5      S   n[        U5      nU$ )a&  
get coefficients (a, b, c, d, e, f, g, h) of the perspective transforms.

In Perspective Transform each pixel (x, y) in the original image gets transformed as,
 (x, y) -> ( (ax + by + c) / (gx + hy + 1), (dx + ey + f) / (gx + hy + 1) )

Args:
    startpoints (list[list[int]]): [top-left, top-right, bottom-right, bottom-left] of the original image,
    endpoints (list[list[int]]): [top-left, top-right, bottom-right, bottom-left] of the transformed image.

Returns:
    output (list): octuple (a, b, c, d, e, f, g, h) for transforming each pixel.
r4      r   r   N)
r5   zerosr   	enumerater   arrayreshapelinalglstsqr   )	startpoints	endpointsa_matrixip1p2b_matrixresoutputs	            r-   _get_perspective_coeffsr   E  s#    xxS--q12H Y!<=8BqEqEUFRUNUFRUN	
Q qEqEUFRUNUFRUN	"
QA >, xx$,,aS1H
))//(
-a
0C#YFMr/   c                   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a"  [        X5      n[        R                  " XX45      $ [        U 5      (       a"  [        X5      n[        R                  " XX45      $ [        R                  " XX#U5      $ )a  Perform perspective transform of the given image.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be transformed.
    startpoints (list of list of ints): List containing four lists of two integers corresponding to four corners
        ``[top-left, top-right, bottom-right, bottom-left]`` of the original image.
    endpoints (list of list of ints): List containing four lists of two integers corresponding to four corners
        ``[top-left, top-right, bottom-right, bottom-left]`` of the transformed image.
    interpolation (str, optional): Interpolation method. If omitted, or if the
        image has only one channel, it is set to PIL.Image.NEAREST or cv2.INTER_NEAREST
        according the backend.
        When use pil backend, support method are as following:
        - "nearest": Image.NEAREST,
        - "bilinear": Image.BILINEAR,
        - "bicubic": Image.BICUBIC
        When use cv2 backend, support method are as following:
        - "nearest": cv2.INTER_NEAREST,
        - "bilinear": cv2.INTER_LINEAR,
        - "bicubic": cv2.INTER_CUBIC
    fill (int|list|tuple, optional): Pixel fill value for the area outside the transformed
        image. If given a number, the value is used for all bands respectively.

Returns:
    PIL.Image|np.array|paddle.Tensor: transformed Image.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32)
        >>> startpoints = [[0, 0], [33, 0], [33, 25], [0, 25]]
        >>> endpoints = [[3, 2], [32, 3], [30, 24], [2, 25]]
        >>> perspectived_img = F.perspective(fake_img, startpoints, endpoints)
        >>> print(perspectived_img.shape)
        paddle.Size([3, 256, 300])

rE   )
r.   r8   r2   r;   r<   r   r=   perspectiverG   r?   )r,   r   r   rI   rM   coeffss         r-   r   r   r  s    \ 	coc226Fs6K6KXY]^aYbXcd
 	
 S(@  mBB	#		(@sM@@  i
 	
r/   c                T   [        U 5      (       d7  [        U 5      (       d'  [        U 5      (       d  [        S[	        U 5       35      e[        U 5      (       a  [
        R                  " X5      $ [        U 5      (       a  [        R                  " X5      $ [        R                  " X5      $ )ap  Converts image to grayscale version of image.

Args:
    img (PIL.Image|np.array|paddle.Tensor): Image to be converted to grayscale.
    num_output_channels (int, optional): The number of channels for the output
        image. Single channel. Default: 1.
Returns:
    PIL.Image|np.array|paddle.Tensor: Grayscale version of the image.
        if num_output_channels = 1 : returned image is single channel

        if num_output_channels = 3 : returned image is 3 channel with r = g = b

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> gray_img = F.to_grayscale(fake_img)
        >>> print(gray_img.size)
        (300, 256)

rE   )	r.   r8   r2   r;   r<   r=   to_grayscalerG   r?   )r,   num_output_channelss     r-   r   r     s    6 	coc226Fs6K6KXY]^aYbXcd
 	
 S!!#;;	#		99!!#;;r/   c                    g r)    r,   meanstdrC   to_rgbs        r-   	normalizer     s     r/   c                    g r)   r   r   s        r-   r   r     s     r/   c                   [        U 5      (       a  [        R                  " XX#5      $ [        U 5      (       a3  [        R
                  " U 5      R                  [        R                  5      n [        R                  " XX#U5      $ )a  Normalizes a tensor or image with mean and standard deviation.

Args:
    img (PIL.Image|np.array|paddle.Tensor): input data to be normalized.
    mean (list|tuple): Sequence of means for each channel.
    std (list|tuple): Sequence of standard deviations for each channel.
    data_format (str|None, optional): Data format of input img, should be 'HWC' or
        'CHW'. Default: 'CHW'.
    to_rgb (bool, optional): Whether to convert to rgb. If input is tensor,
        this option will be ignored. Default: False.

Returns:
    PIL.Image|np.array|paddle.Tensor: Normalized mage. Data format is same as input img.

Examples:
    .. code-block:: python

        >>> import numpy as np
        >>> from PIL import Image
        >>> from paddle.vision.transforms import functional as F
        >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
        >>> fake_img = Image.fromarray(fake_img)
        >>> mean = [127.5, 127.5, 127.5]
        >>> std = [127.5, 127.5, 127.5]
        >>> normalized_img = F.normalize(fake_img, mean, std, data_format='HWC')
        >>> print(normalized_img.max(), normalized_img.min())
        0.99215686 -1.0

)	r2   rG   r   r.   r5   r   r_   float32r?   r   s        r-   r   r     s[    J }}S99((3-&&rzz2Cs#FCCr/   c           
         [        U 5      (       a  [        R                  " XX#XEUS9$ [        U 5      (       a  [        R                  " XX#XEUS9$ [
        R                  " XX#XEUS9$ )aA  Erase the pixels of selected area in input image with given value.

Args:
    img (paddle.Tensor | np.array | PIL.Image): input Tensor image.
         For Tensor input, the shape should be (C, H, W). For np.array input,
         the shape should be (H, W, C).
    i (int): y coordinate of the top-left point of erased region.
    j (int): x coordinate of the top-left point of erased region.
    h (int): Height of the erased region.
    w (int): Width of the erased region.
    v (paddle.Tensor | np.array): value used to replace the pixels in erased region. It
        should be np.array when img is np.array or PIL.Image.
    inplace (bool, optional): Whether this transform is inplace. Default: False.

Returns:
    paddle.Tensor | np.array | PIL.Image: Erased image. The type is same with input image.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)
        >>> fake_img = paddle.randn((3, 2, 4)).astype(paddle.float32)
        >>> print(fake_img)
        Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[ 0.06132207,  1.11349595,  0.41906244, -0.24858207],
          [-1.85169315, -1.50370061,  1.73954511,  0.13331604]],
        [[ 1.66359663, -0.55764782, -0.59911072, -0.57773495],
         [-1.03176904, -0.33741450, -0.29695082, -1.50258386]],
        [[ 0.67233968, -1.07747352,  0.80170447, -0.06695852],
         [-1.85003340, -0.23008066,  0.65083790,  0.75387722]]])

        >>> values = paddle.zeros((1,1,1), dtype=paddle.float32)
        >>> result = paddle.vision.transforms.erase(fake_img, 0, 1, 1, 2, values)
        >>> print(result)
        Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[ 0.06132207,  0.        ,  0.        , -0.24858207],
          [-1.85169315, -1.50370061,  1.73954511,  0.13331604]],
        [[ 1.66359663,  0.        ,  0.        , -0.57773495],
         [-1.03176904, -0.33741450, -0.29695082, -1.50258386]],
        [[ 0.67233968,  0.        ,  0.        , -0.06695852],
         [-1.85003340, -0.23008066,  0.65083790,  0.75387722]]])

)inplace)r2   rG   eraser.   r=   r?   )r,   r   jhwvr   s          r-   r   r     sZ    j yyqW==	s		{{31w??{{31w??r/   )r,   _ImageDataTypereturnzTypeGuard[PILImage])r,   r   r   zTypeGuard[Tensor])r,   r   r   zTypeGuard[npt.NDArray[Any]])CHW)rB   PILImage | npt.NDArray[Any]rC   r   r   r   )r   )r,   r'   rH   r   rI   %_InterpolationPil | _InterpolationCv2r   r'   )r   r"   )
r,   r'   rL   zSize2 | Size4rM   r   rN   r&   r   r'   )r,   r'   rQ   r   rR   r   rS   r   rT   r   r   r'   )r,   r'   rW   r   r   r'   )r,   r'   r   r'   )r,   r'   ra   r   r   r'   )r,   r'   rd   r   r   r'   )r,   r'   rg   r   r   r'   )r,   r'   rj   r   r   r'   )r   r   N)r,   r'   ru   r   rv   !list[float] | tuple[float, float]rw   r   rx   r   rI   r   rM   r   rt   (list[float] | tuple[float, float] | Noner   r'   )r   FNr   )r,   r'   ru   r   rI   r   r   boolrt   r   rM   r   r   r'   )r   r   )r,   r'   r   list[list[int]]r   r   rI   r   rM   r   r   r'   )r   )r,   r'   r   r   r   r'   )..)r,   r   r   (list[float] | tuple[float, float, float]r   r   rC   r   r   r   r   r   )r,   r   r   r   r   r   rC   r   r   r   r   znpt.NDArray[Any])r   F)F)r,   r'   r   r   r   r   r   r   r   r   r   znpt.NDArray[Any] | Tensorr   r   r   r'   )G
__future__r   ro   r   typingr   r   r   numpyr5   PILr   r1   paddle._typingr   base.frameworkr
   base.libpaddle.pirr    r   r?   r   r=   r   rG   r   r   r   numpy.typingnpt	PIL.ImagePILImagetyping_extensionsr   r   r   r   r   r   r   r   __annotations__r!   r&   NDArrayr'   r   __all__r.   r2   r8   r>   rF   rK   rP   rV   rY   r\   r^   rc   rf   ri   r   r   r   r   r   r   r   r   r   r/   r-   <module>r      sN   #   / /    $ & '  ..+6CC#*>$y  $+;$y  &2L)  -3;;s;KLK68S[[-==>N
(=@
 FK3Q	$3Q3B3Q3Qr <F96	96
96 996 	96~ !+	B;	B;B; B; 	B;
 B;J)9	)9)9&))936)9?B)9)9X#3L" J" J.=	.=)..=.=b$9N'=	'=).'='=T./bJ <E7;K	KK 1K 	K
 -K 9K K 5K Kb <E7;DM	DMDM 9DM 	DM
 5DM DM DMN*b <E=
	=
 =
 =
 9	=

 =
 =
@&<R 

 $'	
2 
2 !	
   
 

 $'	$
2 
2 !	
   
 +Dj :@	:@
:@ :@ 	:@
 :@ !:@ :@ :@r/   