We will start in the usual way and try to remove the salt & pepper noise from our image, using the median filtering function offered by MATLAB.
Let's load our image and add salt & pepper noise to it:
>> img = imread('holiday_image2.bmp'); >> snp = imnoise(img,'salt & pepper');
Now, let's filter it and show the results:
>> denoised = medfilt2(snp,[5,5]);figure >> subplot(1,3,1),imshow(img),title('Original image') >> subplot(1,3,2),imshow(snp),title('Noisy image (Salt&Pepper)') >> subplot(1,3,3),imshow(denoised),title('Denoised image')
This is much better. It seems that we have found our preferred filtering solution for the case of salt and pepper noise. The only thing we did was to apply median filtering to our image that was distorted by salt and pepper noise, using a 5x5 kernel.