Reputation: 115
I'm new at Python and I'd like to add a gaussian noise in a grey scale image. I'm already converting the original image into a grey scale to test some morphological methods to denoise (using PyMorph) but I have no idea how to add noise to it.
Upvotes: 8
Views: 25269
Reputation: 33542
You did not provide a lot of info about the current state of your code and what exact kind of noise you want. But usually one would use numpy-based images and then it's simply adding some random-samples based on some distribution.
Example:
import numpy as np
# ...
img = ... # numpy-array of shape (N, M); dtype=np.uint8
# ...
mean = 0.0 # some constant
std = 1.0 # some constant (standard deviation)
noisy_img = img + np.random.normal(mean, std, img.shape)
noisy_img_clipped = np.clip(noisy_img, 0, 255) # we might get out of bounds due to noise
Upvotes: 22