0
点赞
收藏
分享

微信扫一扫

【OpenCV 完整例程】93. 噪声模型的直方图

【OpenCV 完整例程】93. 噪声模型的直方图


2. 噪声模型

数字图像中的噪声源主要来自图像获取和传输过程。在获取图像时,光照水平和传感器温度影响图像中的噪声。在传输图像时,传输信道中的干扰对图像产生污染。


2.7 图像噪声小结

上述噪声模型为各种图像噪声的建模提供了有效的工具。例如:

高斯噪声:常用于电子电路及传感器噪声(光照不足和/或高温引起)等因素所导致噪声的建模;

瑞利噪声:常用于距离成像中的噪声建模;

指数噪声和伽马噪声:常用于激光成像中的噪声建模;

冲激噪声:常用于在成像期间的快速瞬变(如开关故障)的噪声建模;

均匀噪声:是对实际情况最基本描述,也是数字图像处理中各种随机数发生器的基础。


例程 9.7:各种噪声模型的直方图分布

# OpenCVdemo09.py
# Demo09 of OpenCV
# 9. 图像复原与重建
# Copyright 2021 Youcans, XUPT
# Crated:2021-01-30    

    # # 9.7:各种噪声模型的直方图分布
    img = cv2.imread("../images/Fig0503.tif", 0)  # flags=0 读取为灰度图像

    mu, sigma = 0.0, 20.0
    noiseGause = np.random.normal(mu, sigma, img.shape)
    imgGaussNoise = img + noiseGause
    imgGaussNoise = np.uint8(cv2.normalize(imgGaussNoise, None, 0, 255, cv2.NORM_MINMAX))  # 归一化为 [0,255]

    a = 30.0
    noiseRayleigh = np.random.rayleigh(a, size=img.shape)
    imgRayleighNoise = img + noiseRayleigh
    imgRayleighNoise = np.uint8(cv2.normalize(imgRayleighNoise, None, 0, 255, cv2.NORM_MINMAX))  # 归一化为 [0,255]

    a, b = 10.0, 2.5
    noiseGamma = np.random.gamma(shape=b, scale=a, size=img.shape)
    imgGammaNoise = img + noiseGamma
    imgGammaNoise = np.uint8(cv2.normalize(imgGammaNoise, None, 0, 255, cv2.NORM_MINMAX))  # 归一化为 [0,255]

    a = 10.0
    noiseExponent = np.random.exponential(scale=a, size=img.shape)
    imgExponentNoise = img + noiseExponent
    imgExponentNoise = np.uint8(cv2.normalize(imgExponentNoise, None, 0, 255, cv2.NORM_MINMAX))  # 归一化为 [0,255]

    mean, sigma = 10, 100
    a = 2 * mean - np.sqrt(12 * sigma)  # a = -14.64
    b = 2 * mean + np.sqrt(12 * sigma)  # b = 54.64
    noiseUniform = np.random.uniform(a, b, img.shape)
    imgUniformNoise = img + noiseUniform
    imgUniformNoise = np.uint8(cv2.normalize(imgUniformNoise, None, 0, 255, cv2.NORM_MINMAX))  # 归一化为 [0,255]

    ps, pp = 0.05, 0.02
    mask = np.random.choice((0, 0.5, 1), size=img.shape[:2], p=[pp, (1-ps-pp), ps])
    imgChoiceNoise = img.copy()
    imgChoiceNoise[mask==1] = 255
    imgChoiceNoise[mask==0] = 0

    plt.figure(figsize=(12, 8))
    plt.subplot(231), plt.title("Gauss noise")
    histNP, bins = np.histogram(imgGaussNoise.flatten(), bins=255, range=[0, 255], density=True)
    plt.bar(bins[:-1], histNP[:])
    plt.subplot(232), plt.title("Rayleigh noise")
    histNP, bins = np.histogram(imgRayleighNoise.flatten(), bins=255, range=[0, 255], density=True)
    plt.bar(bins[:-1], histNP[:])
    plt.subplot(233), plt.title("Gamma noise")
    histNP, bins = np.histogram(imgGammaNoise.flatten(), bins=255, range=[0, 255], density=True)
    plt.bar(bins[:-1], histNP[:])
    plt.subplot(234), plt.title("Exponential noise")
    histNP, bins = np.histogram(imgExponentNoise.flatten(), bins=255, range=[0, 255], density=True)
    plt.bar(bins[:-1], histNP[:])
    plt.subplot(235), plt.title("Uniform noise")
    histNP, bins = np.histogram(imgUniformNoise.flatten(), bins=255, range=[0, 255], density=True)
    plt.bar(bins[:-1], histNP[:])
    plt.subplot(236), plt.title("Salt-pepper noise")
    histNP, bins = np.histogram(imgChoiceNoise.flatten(), bins=255, range=[0, 255], density=True)
    plt.bar(bins[:-1], histNP[:])
    plt.tight_layout()
    plt.show()

在这里插入图片描述


(本节完)


版权声明:

youcans@xupt 原创作品,转载必须标注原文链接

Copyright 2021 youcans, XUPT

Crated:2022-2-1


举报

相关推荐

0 条评论