1. Brightness, Contrast, Hue, or Saturation Effect
Brightness, Contrast, Hue, or Saturation Effect
Use the Color Correction Effect to change the capture’s brightness, contrast, hue, saturation, and gamma properties during the capture process. The following graphic shows a sample:
1.Original capture
2.Brightness
3. Contrast: Change the contrast between the light and dark colors.
4.Hue: Change is similar to rotating a color wheel to select a different mixture of colors.
5.Saturation: The quantity of a color in pixels, from gray at the lowest saturation to rich color in the highest.
6.Gamma: Adjust the intensity of colors by changing the gamma constant used to map the intensity values. Gamma correction changes brightness using a logarithmic scale for visual perception. Gamma is a constant used to calculate the progression. For most CRTs, the gamma constant is in the range of 2.2 to 2.5.
jitter的意思
v. 紧张不安 / 抖动 / 战战兢兢 / 神经过敏
n. 紧张不安 / 晃动 / 偏移 / 振动
这里抖动或者偏移 是随机变化的含义
下面以亮度brightness举例,假设brightness设置为0.5
brightness_change = transforms.ColorJitter(brightness=0.5)
它的含义是将图像的亮度随机变化为原图亮度的50%(1−0.5)∼150%(1+0.5)
说明中的[max(0, 1 - brightness), 1 + brightness]就是 [0.5 , 1.5]
其他参数可以举一反三
brightness(float或 float类型元组(min, max))– 亮度的偏移幅度。
brightness_factor从[max(0, 1 - brightness), 1 + brightness]中随机采样产生。应当是非负数。
contrast(float或 float类型元组(min, max))– 对比度偏移幅度。
contrast_factor从[max(0, 1 - contrast), 1 + contrast]中随机采样产生。应当是非负数。
saturation(float或 float类型元组(min, max))– 饱和度偏移幅度。
saturation_factor从[max(0, 1 - saturation), 1 + saturation]中随机采样产生。应当是非负数。
hue(float或 float类型元组(min, max))– 色相偏移幅度。
hue_factor从[-hue, hue]中随机采样产生,其值应当满足0<= hue <= 0.5或-0.5 <= min <= max <= 0.5
import numpy as np
import cv2
import os
import torch
import math
import torchvision.transforms as transforms
from PIL import Image
# 单独设置
# 随机改变图像的亮度
brightness_change = transforms.ColorJitter(brightness=0.5)
# 随机改变图像的色调
hue_change = transforms.ColorJitter(hue=0.5)
# 随机改变图像的对比度
contrast_change = transforms.ColorJitter(contrast=0.5)
# 综合设置
color_aug = transforms.ColorJitter(brightness=0.5, contrast=0.5, saturation=0.5, hue=0.5)
transform = transforms.Compose([
brightness_change,
hue_change,
contrast_change,
])