Here is a MATLAB program that adds salt and pepper noise to an input image:
main.m458 chars24 lines
In this program, we first read the input image and convert it to grayscale if it is a color image. We then set the probabilities pa
and pb
of the salt and pepper noise components, respectively. We generate a noise matrix of the same size as the input image using the rand()
function. We then add salt noise to the input image by setting all pixels in the noise matrix that are less than pa
to white (i.e., 255). We add pepper noise to the input image by setting all pixels in the noise matrix that are greater than 1 - pb
to black (i.e., 0). Finally, we save the noisy image as an output.
gistlibby LogSnag