CoolFace
Modelpublic

InPeerReview/RemoteSensingChangeDetection-RSCD.HA2F

sourceHugging Faceupdated 10mo agoView on Hugging Face
2likes
Transforms.cpython-39.pyc70 linesDownload Raw Back to __pycache__
1a

28��gJ�@s�ddlZddlZddlZddlZddlZGdd�de�ZGdd�de�ZGdd�de�ZGdd	�d	e�Z	Gd3d�de�Z4Gdd
�d
e�ZGdd�de�ZGdd�de�Z
Gdd�de�ZdS)�Nc@s eZdZdZdd�Zdd�ZdS)�Scalez15    Resize the given image to a fixed scale6    cCs||_||_dS)zY7        :param wi: width after resizing8        :param he: height after reszing9        N)�w�h)�self�wi�he�r�DC:\Users\82607\Desktop\code\ChangeViT-master\.\dataset\Transforms.py�__init__
szScale.__init__cCs6t�||j|jf�}tj||j|jftjd�}||gS)zr10        :param img: RGB image11        :param label: semantic label image12        :return: resized images13        ��
interpolation)�cv2�resizerr�
INTER_NEAREST)r�img�labelrrr	�__call__szScale.__call__N��__name__�14__module__�__qualname__�__doc__r15rrrrr	rs16rc@s&eZdZd	dd�Zdd�Zdd�ZdS)17�ResizeFcCs*t|ttf�s|f}||_||_||_dS�N)�18isinstance�list�tuple�min_size�max_size�strict)rrrrrrr	r19%s20zResize.__init__c21Cs�|\}}|js�t�|j�}|j}|durltt||f��}tt||f��}||||krltt	|||��}||kr|||ks�||kr�||kr�||fS||kr�|}t|||�}	n|}	t|||�}|	|fS||kr�|j|jdfS|jd|jfSdS)Nr)22r�random�choicerr�float�min�max�int�round)23rZ24image_sizerr�sizerZmin_original_sizeZmax_original_sizeZowZohrrr	�get_size-s( zResize.get_sizecCs:|�|jdd��}t�||�}tj||tjd�}||fS)N�r)r(�shaper
rr)r�imagerr'rrr	rIszResize.__call__N)F)rrrr25r(rrrrr	r$s26rc@s eZdZdZdd�Zdd�ZdS)�RandomCropResizezL27    Randomly crop and resize the given image with a probability of 0.528    cCs||_||_dS)zs29        :param crop_area: area to be cropped (this is the max value and we select between 0 and crop area30        N)�cw�ch)rZ	crop_arearrr	r31VszRandomCropResize.__init__c	Cs�t��dkr�|jdd�\}}t�d|j�}t�d|j�}||||�|||�f}||||�|||�f}t�|||f�}tj|||ftjd�}||fS||gSdS)N��?r)rr)r r*�randintr.r-r
rr)	rrrrr�x1�y1Zimg_cropZ32label_croprrr	r]szRandomCropResize.__call__Nrrrrr	r,Qsr,c@seZdZdZdd�ZdS)�33RandomFlip�A34    Randomly flip the given Image with a probability of 0.535    cCsPt��dkr$t�|d�}t�|d�}t��dkrHt�|d�}t�|d�}||gS)Nr/r�)r r
�flip)rr+rrrr	rsszRandomFlip.__call__N�rrrrrrrrr	r3nsr3c@seZdZdZdd�ZdS)�RandomExchanger4cCsZt��dkrR|dd�dd�dd�f}|dd�dd�dd�f}tj||fdd�}||gS)Nr/r��r))�axis)r �numpy�concatenate)rr+r�pre_img�post_imgrrr	r�s36zRandomExchange.__call__Nr7rrrr	r8}sr8c@s eZdZdZdd�Zdd�ZdS)�	Normalizez�37    Given mean: (B, G, R) and std: (B, G, R),38    will normalize each channel of the torch.*Tensor, i.e.39    channel = (channel - mean) / std40    cCs ||_||_dg|_dg|_dS)�u41        :param mean: global mean computed from dataset42        :param std: global std computed from dataset43        r/N)�mean�stdZ44depth_meanZ	depth_std)rrBrCrrr	r45�szNormalize.__init__cCs�|�tj�}|d}t�|d�}td�D](}|dd�dd�|f|j|8<q*td�D](}|dd�dd�|f|j|<q\||gS)N��r:)�astype�np�float32�ceil�rangerBrC)rr+r�irrr	r�s&&zNormalize.__call__Nrrrrr	r@�s46r@c@seZdZddd�Zdd�ZdS)�
GaussianNoise皙�����?cCs47||_dS)rAN)rC)rrCrrr	r48�szGaussianNoise.__init__cCs.tjjd|j|jd�}||�tj�}||gS)Nr)�loc�scaler')rFr �normalrCr*rErG)rr+r�noiserrr	r�szGaussianNoise.__call__N)rL)rrrr49rrrrr	rK�s50rKc@s"eZdZdZddd�Zdd�ZdS)	�ToTensorzW51    This class converts the data to tensor so that it can be processed by PyTorch52    r5cCs53||_dS)zP54        :param scale: set this parameter according to the output scale55        N)rN)rrNrrr	r56�szToTensor.__init__cCs�|jdkr^|jdd�\}}t�|t|�t|�f�}tj|t||j�t||j�ftjd�}|dd�dd�ddd�f��}|�d�}t�	|�}t�57tj|tjd��j
dd�}||gS)	Nr5r)r�����)r)rr5)�dtyper)�dim)rNr*r
rr%r�copy�	transpose�torch�58from_numpy�59LongTensorrF�array�	unsqueeze)rr+rrrZimage_tensorZlabel_tensorrrr	r�s60 � 6162zToTensor.__call__N)r5rrrrr	rQ�s63rQc@s eZdZdZdd�Zdd�ZdS)�Composez/64    Composes several transforms together.65    cCs66||_dSr��67transforms)rr^rrr	r68�szCompose.__init__cGs|jD]}||�}q|Srr])r�args�trrr	r�s6970zCompose.__call__Nrrrrr	r\�sr\)r<rFrWr r
�objectrrr,r3r8r@rKrQr\rrrr	�<module>s-