对PCB图像进行颜色亮度处理增强(未完)

对PCB图像的颜色进行增强 Color Augmentations

随机亮度RandomBrightness

随机更改输入图像的亮度。

参数:

limit ((float, float) or float): factor range for changing brightness.If limit is a single float, the range will be (-limit, limit). Default: (-0.2, 0.2).

更改亮度的系数范围,如果只写了一个的话,范围就是相反数到自己

p (float): probability of applying the transform. Default: 0.5.

进行变换的概率

aug = RandomBrightness((0.3,0.6),False,1)
img_RandomBrightness = aug(image=image)['image']
plt.subplot(1, 2, 1)
plt.imshow(image)
plt.subplot(1, 2, 2)
plt.imshow(img_RandomBrightness)
plt.show()

pcb电路板Opencv多点矫正_pcb电路板Opencv多点矫正

随机对比度RandomContrast

随机改变输入图像的对比度

参数:(和上面的随机亮度的参数一样)

aug = RandomContrast((0.2,0.8),False,1)
img_RandomContrast = aug(image=image)['image']
plt.subplot(1, 2, 1)
plt.imshow(image)
plt.subplot(1, 2, 2)
plt.imshow(img_RandomContrast)
plt.show()

pcb电路板Opencv多点矫正_pcb_02

随机Gamma RandomGamma

Gamma变换通过非线性变换提升了暗部细节。

一种提高图像亮度的方法,但是是非直线的变换,更加适合人眼的观察方式。

系数名

解释

gamma_limit (float or (float, float)):

If gamma_limit is a single float value,the range will be (-gamma_limit, gamma_limit). Default: (80, 120).

eps:

Deprecated.不推荐使用

always_apply

p

概率

aug = RandomGamma((80,120),eps=None,always_apply=False,p=1)
img_RandomGamma = aug(image=image)['image']
plt.subplot(1, 2, 1)
plt.imshow(image)
plt.subplot(1, 2, 2)
plt.imshow(img_RandomGamma)
plt.show()

pcb电路板Opencv多点矫正_pcb电路板Opencv多点矫正_03

对比度受限自适应直方图均衡 CLAHE

将对比度受限的自适应直方图均衡应用于输入图像

基本思想是通过图像的灰度分布直方图确定一条映射曲线,用来对图像进行灰度变换,以达到提高图像对比度的目的

系数名

解释

clip_limit (float or (float, float)):

upper threshold value for contrast limiting. If clip_limit is a single float value, the range will be (1, clip_limit). Default: (1, 4). 对比度限制的上阈值

tile_grid_size ((int, int))

size of grid for histogram equalization. Default: (8, 8).直方图均衡化的网格大小

always_apply

p (float)

probability of applying the transform. Default: 0.5.

aug = CLAHE(clip_limit=(1, 4), tile_grid_size=(8, 8), always_apply=False, p=1)
img_CLAHE = aug(image=image)['image']
plt.subplot(1, 2, 1)
plt.imshow(image)
plt.subplot(1, 2, 2)
plt.imshow(img_CLAHE)
plt.show()

参考博客

pcb电路板Opencv多点矫正_pcb电路板Opencv多点矫正_04

色调饱和度值 HueSaturationValue

随机更改输入图像的色相,饱和度和值

系数名

解释

hue_shift_limit ((int, int) or int)

range for changing hue. If hue_shift_limit is a single int, the rangewill be (-hue_shift_limit, hue_shift_limit). Default: (-20, 20).改变色调的范围

sat_shift_limit ((int, int) or int)

range for changing saturation. If sat_shift_limit is a single int,the range will be (-sat_shift_limit, sat_shift_limit). Default: (-30, 30).饱和度变化范围

val_shift_limit ((int, int) or int)

range for changing value. If val_shift_limit is a single int, the range will be (-val_shift_limit, val_shift_limit). Default: (-20, 20).变动值范围

always_apply

p (float):

probability of applying the transform. Default: 0.5.

饱和度是指色彩的鲜艳程度,也称色彩的纯度。饱和度取决于该色中含色成分和消色成分(灰色)的比例。含色成分越大,饱和度越大;消色成分越大,饱和度越小。纯的颜色都是高度饱和的,如鲜红,鲜绿。混杂上白色,灰色或其他色调的颜色,是不饱和的颜色,如绛紫,粉红,黄褐等。完全不饱和的颜色根本没有色调,如黑白之间的各种灰色。

色调指的是一幅画中画面色彩的总体倾向,是大的色彩效果。色调不是指颜色的性质,而是对一幅绘画作品的整体颜色的概括评价。色调是指一幅作品色彩外观的基本倾向。

aug = HueSaturationValue(hue_shift_limit=(10,30),sat_shift_limit=(10,30),val_shift_limit=20,always_apply=False,p=1)
img_HueSaturationValue = aug(image=image)['image']
plt.subplot(1, 2, 1)
plt.imshow(image)
plt.subplot(1, 2, 2)
plt.imshow(img_HueSaturationValue)
plt.show()

参考博客

pcb电路板Opencv多点矫正_pcb_05

综合使用上面的方法

def augment_flips_color(p=.5):
    return Compose([
        RandomBrightness((0.3,0.6),False,1),
        RandomContrast((0.4,0.8),False,1),
        RandomGamma((80,120),eps=None,always_apply=False,p=1),
        CLAHE(clip_limit=(1, 4), tile_grid_size=(8, 8), always_apply=False, p=1),
        HueSaturationValue(hue_shift_limit=(10, 30), sat_shift_limit=(10, 30), val_shift_limit=20, always_apply=False,
                           p=1)

    ], p=p)

aug = augment_flips_color(p=1)
img_augment_flips_color = aug(image=image)['image']
plt.subplot(1, 2, 1)
plt.imshow(image)
plt.subplot(1, 2, 2)
plt.imshow(img_augment_flips_color)
plt.show()

pcb电路板Opencv多点矫正_计算机视觉_06