Created
February 17, 2019 13:54
-
-
Save nimpy/cdd686b2cb08e61c87703a78aaeee466 to your computer and use it in GitHub Desktop.
Add Gaussian noise to an image of type np.uint8.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def add_gaussian_noise(image, mean=0, sigma=20): | |
"""Add Gaussian noise to an image of type np.uint8.""" | |
gaussian_noise = np.random.normal(mean, sigma, image.shape) | |
gaussian_noise = gaussian_noise.reshape(image.shape) | |
noisy_image = image + gaussian_noise | |
noisy_image = np.clip(noisy_image, 0, 255) | |
noisy_image = noisy_image.astype(np.uint8) | |
return noisy_image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment