예제 #1
0
파일: DataAug.py 프로젝트: Shujun-He/PANDA
def random_color(tensor, p=.5):
    '''
    brightness_factor (Union[float, torch.Tensor]) – Brightness adjust factor per element in the batch.
    0 does not modify the input image while any other number modify the brightness.
    contrast_factor (Union[float, torch.Tensor]) – Contrast adjust factor per element in the batch.
    0 generates a compleatly black image,
    1 does not modify the input image while any other non-negative number modify the brightness by this factor.
    hue_factor (float):0 means no shift. Therefore,
    both -PI and PI will give an image with complementary colors while 0 gives the original image.
    saturation_factor (float) – How much to adjust the saturation. 0 will give a black
    order=0 is brightness, 1 is contrast, 2 is saturation, 4 is hue.
    '''
    gamma = torch.ones(tensor.shape[1])
    gamma = np.random.uniform(0.75, 1.25)
    random_number = np.random.uniform()
    if random_number < p:
        for i in range(tensor.shape[0]):
            tensor[i] = kornia.adjust_gamma(tensor[i], gamma)

    # hue=torch.ones(tensor.shape[1])
    # hue=np.random.uniform(-0.4,0.4)
    # random_number=np.random.uniform()
    # if random_number<p:
    #     for i in range(tensor.shape[0]):
    #         tensor[i]=kornia.adjust_hue(tensor[i],hue)

    # contrast=torch.ones(tensor.shape[1])
    # contrast=np.random.uniform(0.6,1.4)
    # random_number=np.random.uniform()
    # if random_number<p:
    #     for i in range(tensor.shape[0]):
    #         tensor[i]=kornia.adjust_contrast(tensor[i],contrast)
    #
    # brightness=torch.ones(tensor.shape[1])
    # brightness=np.random.uniform(-0.4,0.4)
    # random_number=np.random.uniform()
    # if random_number<p:
    #     for i in range(tensor.shape[0]):
    #         tensor[i]=kornia.adjust_brightness(tensor[i],brightness)

    return tensor
def Gamma(x, alpha, beta):
    # alpha (1.0, 3.0), beta (1.0, 3.0)
    return kornia.adjust_gamma(x, gamma=alpha, gain=beta)
예제 #3
0

#############################
# Show original
imshow(x_rgb)

#############################
# Adjust Brightness
x_brightness: torch.Tensor = kornia.adjust_brightness(x_rgb, 0.6)
imshow(x_brightness)

#############################
# Adjust Contrast
x_contrast: torch.Tensor = kornia.adjust_contrast(x_rgb, 0.2)
imshow(x_contrast)

#############################
# Adjust Gamma
x_gamma: torch.Tensor = kornia.adjust_gamma(x_rgb, gamma=3., gain=1.5)
imshow(x_gamma)

#############################
# Adjust Saturation
x_saturated: torch.Tensor = kornia.adjust_saturation(x_rgb, 0.2)
imshow(x_saturated)

#############################
# Adjust Hue
x_hue: torch.Tensor = kornia.adjust_hue(x_rgb, 0.5)
imshow(x_hue)
예제 #4
0
def Gamma(x, v):
    return kornia.adjust_gamma(x, v)