Let's go back to our holiday in Rome picture. We will add different types of noise to it and then filter the noisy result with our blurring kernels:
>> img = imread('holiday_image2.bmp'),
>> gauss = imnoise(img,'gaussian'), >> poiss = imnoise(img,'poisson'), >> speck = imnoise(img,'speckle'), >> snp = imnoise(img,'salt & pepper'),
DenoiseAndPlot.m
:function DenoiseAndPlot(original,distorted,type) % Function that performs filtering of the distorted image with % three different kernels and displays the results % Inputs: % original - Original image % distorted – Image distorted by noise % type – Type of noise % (1: Gaussian, 2: Poisson, 3: speckle, 4: Salt & Pepper) switch type case 1 message = 'Noisy image (Gaussian)'; case 2 message = 'Noisy image (Poisson)'; case 3 message = 'Noisy image (speckle)'; case 4 message = 'Noisy image (Salt & Pepper)'; end f1 = BlurImage(distorted,1,2,1); f2 = BlurImage(distorted,2,[5,5],1); f3 = BlurImage(distorted,3,[5,5,2],1); subplot(2,3,1),imshow(original),title('Original image') subplot(2,3,2),imshow(distorted),title(message) subplot(2,3,4),imshow(f1),title('Filtered by disk kernel') subplot(2,3,5),imshow(f2),title('Filtered by averaging kernel') subplot(2,3,6),imshow(f3),title('Filtered by Gaussian kernel')
>> DenoiseAndPlot(img,gauss,1);
>> DenoiseAndPlot(img,poiss,2);
>> DenoiseAndPlot(img,poiss,3);
>> DenoiseAndPlot(img,snp,4);
First of all, we made a very wise choice by writing a function that performs the repeating parts of our code, which were quite lengthy. The only thing that changed according to our choice of filter was the title of the noisy image. Hence, we included a switch
clause to change our message depending on the type of noise. All other lines in our function are pretty straightforward. We passed the noisy image through all of our filters using the BlurImage
function we made earlier and displayed all the results in the same figure as the original and noisy images.
The results we got were decent for all cases, except the case of salt & pepper noise. Nothing exceptional and perfect, but the resulting images were generally an improvement over the noisy ones.
Hence, these three filters can be used for denoising purposes in cases of:
However, the case of noise added by A/D (Analog to Digital) conversion or by errors in image data bits during transmission cannot be handled very effectively by these filters. This is why we will now visit another very important filtering method, called median filtering.