a
    d&                     @  s   d dl mZ d dlmZmZmZmZmZ d dlZ	d dl
Z
d dlmZ ddlmZmZ G dd deZee
je	jjef Ze
jZee
jef Ze
jZdS )	    )annotations)AnyListOptionalTupleUnionN)InterpolationMode   )_FillTypeJIT	Datapointc                
   @  s  e Zd ZdZedd dddZdddddd	d
dd dddZed dd dddZdddddddZe	ddddZ
e	ddddZd dddZd dd d!Zejdd"fd#d$d%d&d d'd(d)Zddddd d*d+d,Zd#d d-d.d/Zejd"fddddd#d$d&d d0d1d2Zdtd#d4dd d5d6d7Zejd8ddfd9d$d:d;d<d d=d>d?Zejddfd@dAd9dAd$d<d;d dBdCdDZejddfdEdEd$d<d;d dFdGdHZejdfdd$d<d dIdJdKZdudd dMdNdOZd9d dPdQdRZd9d dSdTdUZd9d dVdWdXZd9d dYdZd[Zd9d d\d]d^Zdvd9d9d d_d`daZ dd dbdcddZ!d9d dedfdgZ"d ddhdiZ#d ddjdkZ$d ddldmZ%dwd#d;d dndodpZ&dxdAdAd:d dqdrdsZ'dS )yImagea$  [BETA] :class:`torch.Tensor` subclass for images.

    Args:
        data (tensor-like, PIL.Image.Image): Any data that can be turned into a tensor with :func:`torch.as_tensor` as
            well as PIL images.
        dtype (torch.dtype, optional): Desired data type of the bounding box. If omitted, will be inferred from
            ``data``.
        device (torch.device, optional): Desired device of the bounding box. If omitted and ``data`` is a
            :class:`torch.Tensor`, the device is taken from it. Otherwise, the bounding box is constructed on the CPU.
        requires_grad (bool, optional): Whether autograd should record operations on the bounding box. If omitted and
            ``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
    ztorch.Tensor)tensorreturnc                 C  s   | | }|S N)as_subclass)clsr   image r   f/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torchvision/datapoints/_image.py_wrap   s    
zImage._wrapNdtypedevicerequires_gradr   zOptional[torch.dtype]z'Optional[Union[torch.device, str, int]]zOptional[bool])datar   r   r   r   c                C  sd   t |tjjr$ddlm} ||}| j||||d}|jdk rFtn|jdkrZ|	d}| 
|S )Nr   )
functionalr      )
isinstancePILr   Ztorchvision.transforms.v2r   Zpil_to_tensorZ
_to_tensorndim
ValueErrorZ	unsqueezer   )r   r   r   r   r   Fr   r   r   r   __new__   s    



zImage.__new__)otherr   r   c                 C  s
   |  |S r   )r   )r   r#   r   r   r   r   	wrap_like4   s    zImage.wrap_like)tensor_contentsstr)r%   r   c                C  s   |   S r   )Z
_make_repr)selfr%   r   r   r   __repr__8   s    zImage.__repr__zTuple[int, int])r   c                 C  s   t | jdd  S )N)tupleshaper'   r   r   r   spatial_size;   s    zImage.spatial_sizeintc                 C  s
   | j d S )N)r+   r,   r   r   r   num_channels?   s    zImage.num_channelsc                 C  s    | j | tj}t| |S r   )_FZhorizontal_flip_image_tensorr   torchTensorr   r$   r'   outputr   r   r   horizontal_flipC   s    zImage.horizontal_flipc                 C  s    | j | tj}t| |S r   )r1   Zvertical_flip_image_tensorr   r2   r3   r   r$   r4   r   r   r   vertical_flipG   s    zImage.vertical_flipwarnz	List[int]zUnion[InterpolationMode, int]zOptional[int]zOptional[Union[str, bool]])sizeinterpolationmax_size	antialiasr   c                 C  s*   | j j| tj||||d}t| |S )N)r:   r;   r<   )r1   Zresize_image_tensorr   r2   r3   r   r$   )r'   r9   r:   r;   r<   r5   r   r   r   resizeK   s    zImage.resize)topleftheightwidthr   c                 C  s(   | j | tj||||}t| |S r   )r1   Zcrop_image_tensorr   r2   r3   r   r$   )r'   r>   r?   r@   rA   r5   r   r   r   cropW   s    z
Image.crop)output_sizer   c                 C  s$   | j j| tj|d}t| |S )N)rC   )r1   Zcenter_crop_image_tensorr   r2   r3   r   r$   )r'   rC   r5   r   r   r   center_crop[   s    zImage.center_crop)r>   r?   r@   rA   r9   r:   r<   r   c           	   
   C  s4   | j j| tj||||t|||d}t| |S )N)r9   r:   r<   )r1   Zresized_crop_image_tensorr   r2   r3   listr   r$   )	r'   r>   r?   r@   rA   r9   r:   r<   r5   r   r   r   resized_crop_   s    


zImage.resized_cropconstantz(Optional[Union[int, float, List[float]]])paddingfillpadding_moder   c                 C  s(   | j j| tj|||d}t| |S )N)rI   rJ   )r1   Zpad_image_tensorr   r2   r3   r   r$   )r'   rH   rI   rJ   r5   r   r   r   padu   s    z	Image.padFfloatboolzOptional[List[float]]r
   )angler:   expandcenterrI   r   c                 C  s,   | j j| tj|||||d}t| |S )N)r:   rO   rI   rP   )r1   Zrotate_image_tensorr   r2   r3   r   r$   )r'   rN   r:   rO   rP   rI   r5   r   r   r   rotate~   s    zImage.rotatezUnion[int, float]zList[float])rN   	translatescaleshearr:   rI   rP   r   c           	   
   C  s0   | j j| tj|||||||d}t| |S )N)rR   rS   rT   r:   rI   rP   )r1   Zaffine_image_tensorr   r2   r3   r   r$   )	r'   rN   rR   rS   rT   r:   rI   rP   r5   r   r   r   affine   s    


zImage.affinezOptional[List[List[int]]])startpoints	endpointsr:   rI   coefficientsr   c                 C  s,   | j j| tj|||||d}t| |S )N)r:   rI   rX   )r1   Zperspective_image_tensorr   r2   r3   r   r$   )r'   rV   rW   r:   rI   rX   r5   r   r   r   perspective   s    
zImage.perspective)displacementr:   rI   r   c                 C  s(   | j j| tj|||d}t| |S )N)r:   rI   )r1   Zelastic_image_tensorr   r2   r3   r   r$   )r'   rZ   r:   rI   r5   r   r   r   elastic   s    zImage.elasticr	   )num_output_channelsr   c                 C  s$   | j j| tj|d}t| |S )N)r\   )r1   Zrgb_to_grayscale_image_tensorr   r2   r3   r   r$   )r'   r\   r5   r   r   r   rgb_to_grayscale   s    zImage.rgb_to_grayscale)brightness_factorr   c                 C  s$   | j j| tj|d}t| |S )N)r^   )r1   Zadjust_brightness_image_tensorr   r2   r3   r   r$   )r'   r^   r5   r   r   r   adjust_brightness   s    zImage.adjust_brightness)saturation_factorr   c                 C  s$   | j j| tj|d}t| |S )N)r`   )r1   Zadjust_saturation_image_tensorr   r2   r3   r   r$   )r'   r`   r5   r   r   r   adjust_saturation   s    zImage.adjust_saturation)contrast_factorr   c                 C  s$   | j j| tj|d}t| |S )N)rb   )r1   Zadjust_contrast_image_tensorr   r2   r3   r   r$   )r'   rb   r5   r   r   r   adjust_contrast   s    zImage.adjust_contrast)sharpness_factorr   c                 C  s$   | j j| tj|d}t| |S )N)rd   )r1   Zadjust_sharpness_image_tensorr   r2   r3   r   r$   )r'   rd   r5   r   r   r   adjust_sharpness   s    zImage.adjust_sharpness)
hue_factorr   c                 C  s$   | j j| tj|d}t| |S )N)rf   )r1   Zadjust_hue_image_tensorr   r2   r3   r   r$   )r'   rf   r5   r   r   r   
adjust_hue   s    zImage.adjust_hue)gammagainr   c                 C  s&   | j j| tj||d}t| |S )N)rh   ri   )r1   Zadjust_gamma_image_tensorr   r2   r3   r   r$   )r'   rh   ri   r5   r   r   r   adjust_gamma   s    zImage.adjust_gamma)bitsr   c                 C  s$   | j j| tj|d}t| |S )N)rk   )r1   Zposterize_image_tensorr   r2   r3   r   r$   )r'   rk   r5   r   r   r   	posterize   s    zImage.posterize)	thresholdr   c                 C  s$   | j j| tj|d}t| |S )N)rm   )r1   Zsolarize_image_tensorr   r2   r3   r   r$   )r'   rm   r5   r   r   r   solarize   s    zImage.solarizec                 C  s    | j | tj}t| |S r   )r1   Zautocontrast_image_tensorr   r2   r3   r   r$   r4   r   r   r   autocontrast   s    zImage.autocontrastc                 C  s    | j | tj}t| |S r   )r1   Zequalize_image_tensorr   r2   r3   r   r$   r4   r   r   r   equalize   s    zImage.equalizec                 C  s    | j | tj}t| |S r   )r1   Zinvert_image_tensorr   r2   r3   r   r$   r4   r   r   r   invert   s    zImage.invert)kernel_sizesigmar   c                 C  s&   | j j| tj||d}t| |S )N)rr   rs   )r1   Zgaussian_blur_image_tensorr   r2   r3   r   r$   )r'   rr   rs   r5   r   r   r   gaussian_blur   s    zImage.gaussian_blur)meanstdinplacer   c                 C  s(   | j j| tj|||d}t| |S )N)ru   rv   rw   )r1   Znormalize_image_tensorr   r2   r3   r   r$   )r'   ru   rv   rw   r5   r   r   r   	normalize   s    zImage.normalize)NrG   )r	   )r	   )N)F)(__name__
__module____qualname____doc__classmethodr   r"   r$   r(   propertyr-   r0   r6   r7   r   ZBILINEARr=   rB   rD   rF   rK   ZNEARESTrQ   rU   rY   r[   r]   r_   ra   rc   re   rg   rj   rl   rn   ro   rp   rq   rt   rx   r   r   r   r   r      st     r   )
__future__r   typingr   r   r   r   r   Z	PIL.Imager   r2   Z!torchvision.transforms.functionalr   Z
_datapointr
   r   r   r3   Z
_ImageTypeZ_ImageTypeJITZ_TensorImageTypeZ_TensorImageTypeJITr   r   r   r   <module>   s    v