CoolFace
Apppublic

procgne/Plonk

sourceHugging Facemitupdated 10mo agoView on Hugging Face
0likes
image_processing.cpython-310.pyc36 linesDownload Raw Back to __pycache__
1o

2��yfA�@sBddlZddlmmZddlZdd�ZGdd�dejj�ZdS)�NcCs*|ddd}t�|dd��tj�}|S)N�g@g�o@r��)�torch�clip�to�uint8)�imageZimage_torch�r	�;/home/dufour/Documents/diff_plonk/utils/image_processing.py�remap_image_torchsrcs8eZdZdZd�fdd�	Zdd�Zdefd	d3�Z�ZS)�4CenterCropa�Crops the given image at the center. Allows to crop to the maximum possible size.5    Args:6        size (sequence or int): Desired output size of the crop. If size is an7            int instead of sequence like (h, w), a square crop (size, size) is8            made.9        ratio (str): Desired output ratio of the crop that will do the maximum possible crop with the given ratio.10    N�1:1cst���||_||_dS)N)�super�__init__�size�ratio)�selfrr��	__class__r	r11rs1213zCenterCrop.__init__cCs�|jdurXt|tj�r|jdd�\}}n|j\}}|j�d�}t|d�t|d�}t||�}t||�}||krJ||krE||f}n||f}n||krS||f}n||f}n|j}t	j14j�||�S)z�15        Args:16            img (PIL Image or Tensor): Image to be cropped.17 18        Returns:19            PIL Image or Tensor: Cropped image.20        N������:rr)
r�21isinstancer�Tensor�shaper�split�float�int�torchvision�22transforms�23functionalZcenter_crop)r�img�h�wrZ	ratioed_wZ	ratioed_hrr	r	r24�forwards"252627282930zCenterCrop.forward�returncCs|jj�d|j�d�S)Nz(size=�))r�__name__r)rr	r	r31�__repr__9szCenterCrop.__repr__)Nr
)	r&�32__module__�__qualname__�__doc__rr#�strr'�
__classcell__r	r	rr33rs34r)	rZtorch.nn.functional�nnr�Frr�Modulerr	r	r	r35�<module>s36