Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add gaussian noise in an image in Python using PyMorph

Tags:

python

image

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.

like image 881
rmstringhini Avatar asked Apr 29 '17 18:04

rmstringhini


People also ask

How do I add Gaussian noise to a photo?

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 ...


1 Answers

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
like image 85
sascha Avatar answered Oct 12 '22 06:10

sascha