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?
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.
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.
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.
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);
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