data augmentation - pytorch

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,
    ])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值