albumentation

常用的图像增强库
albumentation

github地址 :https://github.com/albumentations-team/albumentations

官网地址:https://albumentations.readthedocs.io/en/latest/

imgaug

github: https://github.com/aleju/imgaug

官网地址: https://imgaug.readthedocs.io/en/latest/

Augmentor

github地址:https://github.com/mdbloice/Augmentor

官网地址: https://augmentor.readthedocs.io/en/master/

Automold

github地址: https://github.com/UjjwalSaxena/Automold–Road-Augmentation-Library

data-augmentation-review

github 地址:https://github.com/AgaMiko/data-augmentation-review

其中我所使用较多的是第一种:albumentation。接下来是我初次使用的一些方案

# python环境下安装的方式为:
pip install albumentations
import albumentations as A
import cv2
# 单种增强使用方式
img = cv2.imread("you path of image")
transform = A.RandomResizedCrop()
img_transform = transform(image=img)["image"]

# 多种增强使用方式
img = cv2.imread("you path of image")
transform = A.Compose([
    A.RandomResizedCrop(),
    A.CropAndPad()
])
img_transform = transform(image=img)["image"]

# 任意在多种增强方式中选择一种
img = cv2.imread("you path of image")
transform = A.Compose([
    A.OneOf([
		A.RandomResizedCrop(),
		A.CropAndPad() 
    ])
])
img_transform = transform(image=img)["image"]

# 任意在n种方式种选择n-1种
img = cv2.imread("you path of image")
transform = A.Compose([
    A.SomeOf([
		A.RandomResizedCrop(),
		A.CropAndPad(),
		A.RandomSizedCrop()
    ], n=random.randint(1, 2))
])
img_transform = transform(image=img)["image"]

# 还可以将SomeOf 和 OneOf 组合起来使用
# 每种变换还自带选择的概率
# 比如下面的概率为默认概率
transform = A.RandomResizedCrop()
# 将概率设置为0.8
transform = A.RandomResizedCrop(p=0.8)

CropAndPad()

#截取或者填充图片
#第一个参数和第二个参数同时只能设定一个
#第一个参数 px 指在图片四周添加一定px的填充 可以是int型数值 或者 2位元组 4位元组; 填充的颜色可以由pad_cval(0,255)修改
#第二个参数 percent 指按比例添加填充
#第一和第二 当为正数时,填充图片,为负数时裁剪图片

transform = A.CropAndPad(px=(random.randint(0,int(img.shape[0]*0.1))),pad_cval=random.randint(0,255))

img.png

CenterCrop()

#中心裁剪
#第一个参数 高度 
#第二个参数 宽度
transform = A.CenterCrop(random.randint(int(height*0.7),int(height*0.9)),random.randint(int(weight*0.7),int(weight*0.9)))

img_1.png

RandomResizedCrop()

#先随机裁剪 再 resize到一定的尺度
#第一个参数 高度
#第二个参数 宽度
#第三个参数 随机裁剪的比例
transform = A.RandomResizedCrop(224,224,(0.7,0.9))

img_2.png

CropNonEmptyMaskIfExists()

如果遮罩为非空,则使用遮罩裁剪区域,否则进行随机裁剪。

未用

RandomSizedCrop()

#裁剪输入的随机部分并将其重新缩放到某个大小
#第一个参数 为裁剪的最大最小值,相当于裁剪范围
#第二个参数 高度
#第三个参数 宽度
transform = A.RandomSizedCrop((100,height),height,weight)

img_3.png

RandomSizedBBoxSafeCrop()

这个是yolo ssd 数据增强使用的 现在不需要 所以不添加

ColorJitter()

#随机更改图片的亮度、对比度、饱和度、颜色
#第一个参数 亮度
#第二个参数 对比度
#第三个参数 饱和度
#第四个参数 颜色
#上面4个参数范围在(0,1)之间
transform = A.ColorJitter(0.2, 0.5, 0.5, 1)

img_4.png

RGBShift()

#三原色在原本基础上增加或者减小
#前面三个参数分别是R、G、B三个通道在原来的基础上增加或者减小
transform = A.RGBShift(np.random.randint(0,255),np.random.randint(0,255),np.random.randint(0,255))

img_5.png

RandomGamma()

#gamma变换
#第一个参数是gamma变换的范围  目前不知道范围的局限
transform = A.RandomGamma((0,255))

img_6.png

ToGray()

# 将原来的图片灰度化
transform = A.ToGray()

img_7.png

ImageCompression()

#压缩图片
#第一个参数 是压缩图片的下界
#第二个参数 是压缩图片的上界
transform = A.ImageCompression(quality_lower=10,quality_upper=90)

img_8.png

GaussianBlur()

#高斯模糊
#第一个参数 : blur_limit   [0, inf)
#第二个参数 : sigma_limit [0, inf)
transform = A.GaussianBlur(blur_limit=(1, 7),sigma_limit=(1,8),p=1)

img_9.png

MedianBlur()

#中值模糊
#第一个参数 :模糊范围
#第二个参数 : 概率 p
transform = A.MedianBlur(blur_limit=9, p=1)

img_10.png

CoarseDropout()

#原函数是cutout,随机在图上裁剪出小方块
#第一个参数是 方块的大小
#第二个参数是 方块最大高度
#第三个参数是 方块最大宽度
transform = A.CoarseDropout(max_holes=3,max_height=100,max_width=100,p=1)

img_11.png

transform = A.RandomShadow(p = 1)

# 随机加阴影
transform = A.RandomShadow(p = 1)

img_12.png

ISONoise()

# 随机添加传感器噪声
transform = A.ISONoise(p=1)

img_13.png

Emboss()

# 浮雕
transform = A.Emboss(p = 1)

img_14.png

Sharpen()

# 锐化
transform = A.Sharpen(p=1)

img_15.png

[2021/11/24]

Downscale()

#以缩小再放大的形式降低图片的质量
transform = A.Downscale(scale_min=0.1,scale_max=0.95,p = 1)

CLAHE()

# 自适应直方图均衡化
transform = A.CLAHE(p = 1)

img_16.png

ChannelDropout()

# 随机丢弃通道
transform = A.ChannelDropout(p=1)

img_17.png

ChannelShuffle()

# 随机变换通道
transform = A.ChannelShuffle(p=1)

img_18.png

FromFloat()

#取一个输入数组,其中所有值都应位于 [0, 1.0] 范围内,将它们乘以 max_value,然后将结果值转换为 dtype 指定的类型。  如果 max_value 为 None 转换将尝试从 dtype 参数推断数据类型的最大值。
transform = A.FromFloat(max_value=random.randint(0, 10), p=1)

img_19.png

GaussNoise()

# 加入高斯噪声
transform = A.GaussNoise(var_limit=(10,1000),p=1)

GlassBlur()

# Glass模糊
transform = A.GlassBlur(max_delta=random.randint(1,5),p=1)

Flip()

# 水平、垂直、翻转图像
transform = A.Flip(p=1)

img_20.png

GridDropout()

# 添加网格
transform = A.GridDropout(unit_size_min=2,unit_size_max = random.randint(5,8),p=1,fill_value=random.randint(0,255),mask_fill_value=random.randint(0,100))

img_21.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kui9702

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值