Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Impulse, gaussian and salt and pepper noise with OpenCV

I'm studying Image Processing on the famous Gonzales "Digital Image Processing" and talking about image restoration a lot of examples are done with computer-generated noise (gaussian, salt and pepper, etc). In MATLAB there are some built-in functions to do it. What about OpenCV?

like image 293
nkint Avatar asked Jan 21 '13 09:01

nkint


People also ask

How do you remove salt and pepper noise from Opencv?

Median Filtering is very effective at eliminating salt and pepper noise, and preserving edges in an image after filtering out noise. The implementation of median filtering is very straightforward. Load the image, pass it through cv2.

Does Gaussian filter remove salt and pepper noise?

The salt-‐and-‐pepper noise, on the other hand, can be completely removed by a median filter (if it affects only a small fraction of the pixels in any given region), but not by a mean or Gaussian filter.

How do you add salt and pepper sound to an image?

By randomizing the noise values, the pixels can change to a white, black, or gray value, thus adding the salt and pepper colors. By randomizing which pixels are changed, the noise is scattered throughout the image. The combination of these randomizations creates the "salt and pepper" effect throughout the image.


1 Answers

As far as I know there are no convenient built in functions like in Matlab. But with only a few lines of code you can create those images yourself.

For example additive gaussian noise:

Mat gaussian_noise = img.clone(); randn(gaussian_noise,128,30); 

Salt and pepper noise:

Mat saltpepper_noise = Mat::zeros(img.rows, img.cols,CV_8U); randu(saltpepper_noise,0,255);  Mat black = saltpepper_noise < 30; Mat white = saltpepper_noise > 225;  Mat saltpepper_img = img.clone(); saltpepper_img.setTo(255,white); saltpepper_img.setTo(0,black); 
like image 114
sietschie Avatar answered Oct 23 '22 15:10

sietschie