In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "python how to use opencv to add noise to the image", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how python uses opencv to add noise to the image.
Original picture:
1. Gaussian noise
Gaussian noise is to add a noise that obeys Gaussian distribution to the picture. The degree of added noise can be controlled by adjusting the standard deviation of Gaussian distribution (sigma). The larger the sigma, the more noise the picture is damaged.
# read the picture img = cv2.imread ("demo.png") # set the mean and variance of the Gaussian distribution mean = set the standard deviation of the Gaussian distribution sigma = 2 generate noise that conforms to the Gaussian distribution according to the mean and standard deviation gauss = np.random.normal (img_height,img_width Img_channels) # add Gaussian noise to the picture noisy_img = image + gauss# set the range of pixel values after adding Gaussian noise noisy_img = np.clip (noisy_img,a_min=0,a_max=255) # Save the picture cv2.imwrite ("noisy_img.png", noise_img)
2. Salt and pepper noise
Salt and pepper noise is to add black and white noise to the picture. Pepper refers to black noise (0re0 and 0). Salt refers to white noise (255255255). Set amount to control the proportion of noise added. The higher the value, the more noise is added, and the image damage is more serious.
# read the picture img = cv2.imread ("demo.png") # set the ratio of the number of salt and pepper noise added s_vs_p = 0.1 set the number of noise image pixels amount = 0.04noisy_img = np.copy (image) # add salt noise num_salt = np.ceil (amount * image.size * s_vs_p) # set the coordinate position coords = [np.random.randint (0L I-1) Int (num_salt)) for i in image.shape] noisy_ img [coincidences] = 25mm add pepper noise num_pepper = np.ceil (amount * image.size * (1.-s_vs_p)) # set the coordinate position of adding noise coords = [np.random.randint (0int I-1, int (num_pepper)) for i in image.shape] noisy_ img [coincidences] = save image cv2.imwrite ("noisy_img.png", noise_img)
3. Poisson noise # read picture img = cv2.imread ("demo.png") # calculate the distribution range of image pixels vals = len (np.unique (image)) vals = 2 * * np.ceil (np.log2 (vals)) # add Poisson noise noisy_img = np.random.poisson (image * vals) / float (vals) # Save image cv2.imwrite ("noisy_img.png", noise_img)
4. Speckle noise # read the picture img = cv2.imread ("demo.png") # randomly generate a distributed noise gauss = np.random.randn (img_height,img_width,img_channels) # add speckle noise to the picture noisy_img = image + image * gauss# normalized image pixel value noisy_img = np.clip (noisy_img,a_min=0,a_max=255) # Save the picture cv2.imwrite ("noisy_img.png", noise_img)
At this point, I believe you have a deeper understanding of "how python uses opencv to add noise to the image". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.