python3 image plus Gaussian noise

Gaussian noise

Gaussian noise refers to a type of noise whose probability density function obeys a Gaussian distribution (that is, a normal distribution). Common Gaussian noise includes fluctuation noise, cosmic noise, thermal noise and shot noise, etc.

In addition to the commonly used noise suppression methods, the Gaussian noise suppression methods often use mathematical statistics methods.

Gaussian white noise: If a noise, its amplitude distribution obeys Gaussian distribution, and its power spectral density is evenly distributed, it is called Gaussian white noise.

insert image description here

image noise

Image noise refers to unnecessary or redundant interference information existing in image data. The existence of noise seriously affects the quality of remote sensing images, so it must be corrected before image enhancement processing and classification processing.

Various factors in the image that hinder people from accepting its information can be called image noise.

Noise can be defined theoretically as "random errors that are unpredictable and can only be understood by probability and statistics methods". Therefore, it is appropriate to regard image noise as a multidimensional random process, so the method of describing noise can completely borrow the description of random process, that is, use its probability distribution function and probability density distribution function.

insert image description here

Gauss theorem

Gauss' law is also known as Gauss' flux theorem, or divergence theorem, Gauss divergence theorem, Gauss-Ostrogradsky formula, Austenitic theorem or high - Austrian formula (the Gauss theorem usually refers to this theorem, and there are other theorems with the same name).

insert image description here

python3 image plus Gaussian noise

  • rely

    • python 3.x
    • opencv2
    • numpy
  • main idea

    1. Normalize the pixel values ​​of the original image

    image = np.array(img / 255, dtype=float)
    

    2. Create an image matrix with mean value, variance sigma, and Gaussian distribution as image noise

    noise = np.random.normal(mean, sigma/255.0, image.shape)
    

    3. Add the noise and the normalized image to get the noised image

    out = image + noise
    
  • Code to achieve image plus Gaussian noise

    test.py:

    import numpy as np
    import cv2
    import os
    import sys
    import random
    
    def main(path):
        
        img = cv2.imread(path)
        gn_img = gauss_noise(img, 0, random.randint(15, 30))#这里加了随机值
        cv2.imwrite('gauss_noise.png', gn_img)
        
        
    def gauss_noise(img, mean=0, sigma=25):
        
        image = np.array(img / 255, dtype=float)  # 将原始图像的像素值进行归一化
        # 创建一个均值为mean,方差为sigma,呈高斯分布的图像矩阵
        noise = np.random.normal(mean, sigma/255.0, image.shape)
        out = image + noise  # 将噪声和原始图像进行相加得到加噪后的图像
        res_img = np.clip(out, 0.0, 1.0)
        res_img = np.uint8(res_img * 255.0) 
        
        return res_img
        
    if __name__ == '__main__':
        if len(sys.argv) == 2:
            main(sys.argv[1])
    
    
  • usage:

    python test.py img_path

  • test input
    insert image description here

  • Test renderings
    insert image description here

reference

1. Baidu Encyclopedia

Guess you like

Origin blog.csdn.net/zengNLP/article/details/128033497