当前位置:   article > 正文

Python_albumentations常用的图像增强方法详解_albumentations python

albumentations python

albumentations库源

亮度和对比度

物体在图像中的清晰度取决于场景照明和相机灵敏度。通过随机增加或减少图像亮度来增加输入图像的虚拟变化,改善了网络的照明不变形。对比度就是图像中最暗和最亮区域之间的分隔。通过随机增强来增加这个范围有助于增加对阴影的不变形,并且通常会提高网络在低光照条件下的性能。

from albumentations import (
    Compose,
    RandomBrightnessContrast
)

aug = Compose([RandomBrightnessContrast(brightness_limit=(0, 0.4), contrast_limit=(0, 0.4), p=1)])

augmented = aug(image=image, mask=gt)
image_bright_contrast = augmented['image']
gt_bright_contrast = augmented['mask']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在这里插入图片描述

色调和饱和度

色调的取值范围是0-360度,用来表示颜色的类别,其中红色是0度,绿色是120度,蓝色是240度。饱和度高,颜色则深而艳。

from albumentations import (
    Compose,
    HueSaturationValue
)

aug = Compose([HueSaturationValue(hue_shift_limit=20,
                                  sat_shift_limit=30,
                                  val_shift_limit=20,
                                  p=1)])

augmented = aug(image=image, mask=gt)
image_hsv = augmented['image']
gt_hsv = augmented['mask']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

在这里插入图片描述

运动模糊

对图像进行模糊可以模拟部分拍摄场景的运动模糊,让网络对模糊图像的边界也具有较强的识别能力。

from albumentations import (
    Compose,
    MotionBlur
)

aug = Compose([MotionBlur(blur_limit=7, p=1.0)])

augmented = aug(image=image, mask=gt)
image_MotionBlur = augmented['image']
gt_MotionBlur = augmented['mask']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在这里插入图片描述

颜色抖动

向每个RGB像素添加小的随机噪声有助于获得对一些相机失真的不变形。

from albumentations import (
    Compose,
    RGBShift
)

aug = Compose([RGBShift(r_shift_limit=20,
                        g_shift_limit=20,
                        b_shift_limit=20,
                        p=1.0)])

augmented = aug(image=image, mask=gt)
image_rgbshift = augmented['image']
gt_rgbshift = augmented['mask']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

在这里插入图片描述

超像素

随机将图像上某个超像素块内的颜色替换为超像素的均值。

from albumentations import Compose
from albumentations.imgaug.transforms import IAASuperpixels

aug = Compose([IAASuperpixels(p_replace=0.1,
                              n_segments=500,
                              p=1)])

augmented = aug(image=image, mask=gt)
image_Superpixels = augmented['image']
gt_Superpixels = augmented['mask']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在这里插入图片描述

锐化

增强图像细节。

from albumentations import Compose
from albumentations.imgaug.transforms import IAASharpen

aug = Compose([IAASharpen(p=1)])

augmented = aug(image=image, mask=gt)
image_Sharpen = augmented['image']
gt_Sharpen = augmented['mask']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/327360
推荐阅读
相关标签
  

闽ICP备14008679号