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.
Description. J = imnoise( I ,'gaussian') adds zero-mean, Gaussian white noise with variance of 0.01 to grayscale image I . J = imnoise( I ,'gaussian', m ) adds Gaussian white noise with mean m and variance of 0.01. J = imnoise( I ,'gaussian', m , var_gauss ) adds Gaussian white noise with mean m and variance var_gauss ...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With