# Assignment 4
# ELL715 - Digital Image Processing
## 1. Image De-Noising
```matlab
clc;
clear all;
close all;
no_of_bits=8;
L=2^(no_of_bits);
f_c = imread('cameraman.jpg');
f_l = imread('lenna.jpg');
f_l = rgb2gray(f_l);
f_c = imresize(f_c,2);
f_l = imresize(f_l,3);
I_l = double(f_l);
I_c = double(f_c);
figure;
subplot(1,2,1); imshow(f_c); title("Original Cameraman");
subplot(1,2,2); imshow(f_l); title("Original Lenna");
```
### 1.A Gaussian And Salt-&-Pepper Noise
**Add different noises i.e., Gaussian and Salt-and-pepper to both the images with different SNR values. Observe and give comments on the qualitative results on images.**
##### Code
```matlab
% Gaussian Noise
snr = [10 20 60];
figure;
subplot(2,2,4); imshow(f_l); title('Original');
for i = 1:numel(snr)
res = uint8(awgn(I_l,snr(i),'measured'));
str = string(snr(i));
name = strcat('SNR=',str,'dB');
subplot(2,2,i); imshow(res); title(name);
end
figure;
subplot(2,2,4); imshow(f_c); title('Original');
for i = 1:numel(snr)
res = uint8(awgn(I_c,snr(i),'measured'));
str = string(snr(i));
name = strcat('SNR=',str,'dB');
subplot(2,2,i); imshow(res); title(name);
end
```
It is noticed that for both cameraman.jpg and lenna.jpg: the lower the value of SNR for gaussian noise, the more intensely the image is corrupted with noise. At SNR ~ 60 dB, minimal difference is seen with respect to OG image.
```matlab
% Salt-and-Pepper Noise
snr = [10 20 60];
figure;
subplot(2,2,4); imshow(f_l); title('Original');
for i = 1:numel(snr)
nd = (10^(-snr(i)/10));
res = imnoise(f_l, 'salt & pepper', nd);
str = string(snr(i));
name = strcat('SNR=',str,'dB');
subplot(2,2,i); imshow(res); title(name);
end
figure;
subplot(2,2,4); imshow(f_c); title('Original');
for i = 1:numel(snr)
nd = (10^(-snr(i)/10));
res = imnoise(f_c, 'salt & pepper', nd);
str = string(snr(i));
name = strcat('SNR=',str,'dB');
subplot(2,2,i); imshow(res); title(name);
end
```
Results similar to that of Gaussian noise is seen when the images are corrupted with S&P noise for both cameraman.jpg and lenna.jpg. Lower the value of SNR for S&P: the greater the image is corrupted with noise.
### 1.B Poisson Noise
**Apply Poisson noise to the above images. Comment on why Poisson noise can’t be treated as the above two. .**
##### Code
```matlab
f_c_poisson = imnoise(f_c,'poisson');
f_l_poisson= imnoise(f_l,'poisson');
figure;
subplot(1,2,1); imshow(f_c_poisson); title("Poisson on Cameraman");
subplot(1,2,2); imshow(f_l_poisson); title("Poisson on Lenna");
```
We know that Poisson noise mainly arises due to defects in sensors. Poisson noise is not stationary. For an image, there is a correlation between the intensitiy of each pixel of the parent image, and the noise. Hence the noise is not additive and it is not multiplicative either, unlike gaussian noise - where we generate a noise matrix given a set of values (mean, variance) and then simply add this noise to the parent image. For the salt and pepper noise also: the intensities of the pixel of the original image is not factored while inserting the noise - the only parameter needed is the % of pixels that are corrupted and the ratio of salt:pepper components.
______________
### 1.C DWT Denoising
**De-noise the images using discrete wavelet transform (DWT). Apply three wavelets i.e., Haar, Daubechies (DB), and Symlets to denoise the images. Display only the best results for each image and each type of noise and wavelet.**
##### Code
```matlab
% Gaussian De-Noise
snr = [10 20 60];
figure;
for i = 1:numel(snr)
res = uint8(awgn(I_l,snr(i),'measured'));
denoised_h = wdenoise2(res,4,'Wavelet','haar');
aSNR_h = 20*log10((norm(I_l))/norm(I_l-double(denoised_h)));
str_h = string(aSNR_h);
denoised_db = wdenoise2(res,4,'Wavelet','db2');
aSNR_db = 20*log10((norm(I_l))/norm(I_l-double(denoised_db)));
str_db = string(aSNR_db);
denoised_s = wdenoise2(res,4,'Wavelet','sym3');
aSNR_s = 20*log10((norm(I_l))/norm(I_l-double(denoised_s)));
str_s = string(aSNR_s);
name_h = strcat('Haar SNR=',str_h,'dB');
name_db = strcat('Daubechies SNR=',str_db,'dB');
name_s = strcat('Symlets SNR=',str_s,'dB');
subplot(3,3,i); imshow(uint8(denoised_h)); title(name_h);
subplot(3,3,i+3); imshow(uint8(denoised_db)); title(name_db);
subplot(3,3,i+6); imshow(uint8(denoised_s)); title(name_s);
end
figure;
for i = 1:numel(snr)
res = uint8(awgn(I_c,snr(i),'measured'));
denoised_h = wdenoise2(res,4,'Wavelet','haar');
aSNR_h = 20*log10((norm(I_c))/norm(I_c-double(denoised_h)));
str_h = string(aSNR_h);
denoised_db = wdenoise2(res,4,'Wavelet','db2');
aSNR_db = 20*log10((norm(I_c))/norm(I_c-double(denoised_db)));
str_db = string(aSNR_db);
denoised_s = wdenoise2(res,4,'Wavelet','sym3');
aSNR_s = 20*log10((norm(I_c))/norm(I_c-double(denoised_s)));
str_s = string(aSNR_s);
name_h = strcat('Haar SNR=',str_h,'dB');
name_db = strcat('Daubechies SNR=',str_db,'dB');
name_s = strcat('Symlets SNR=',str_s,'dB');
subplot(3,3,i); imshow(uint8(denoised_h)); title(name_h);
subplot(3,3,i+3); imshow(uint8(denoised_db)); title(name_db);
subplot(3,3,i+6); imshow(uint8(denoised_s)); title(name_s);
end
% SnP De-Noise
snr = [10 20 60];
figure;
for i = 1:numel(snr)
nd = (10^(-snr(i)/10));
res = imnoise(f_l, 'salt & pepper', nd);
denoised_h = wdenoise2(res,4,'Wavelet','haar');
aSNR_h = 20*log10((norm(I_l))/norm(I_l-double(denoised_h)));
str_h = string(aSNR_h);
denoised_db = wdenoise2(res,4,'Wavelet','db2');
aSNR_db = 20*log10((norm(I_l))/norm(I_l-double(denoised_db)));
str_db = string(aSNR_db);
denoised_s = wdenoise2(res,4,'Wavelet','sym3');
aSNR_s = 20*log10((norm(I_l))/norm(I_l-double(denoised_s)));
str_s = string(aSNR_s);
name_h = strcat('Haar SNR=',str_h,'dB');
name_db = strcat('Daubechies SNR=',str_db,'dB');
name_s = strcat('Symlets SNR=',str_s,'dB');
subplot(3,3,i); imshow(uint8(denoised_h)); title(name_h);
subplot(3,3,i+3); imshow(uint8(denoised_db)); title(name_db);
subplot(3,3,i+6); imshow(uint8(denoised_s)); title(name_s);
end
figure;
for i = 1:numel(snr)
nd = (10^(-snr(i)/10));
res = imnoise(f_c, 'salt & pepper', nd);
denoised_h = wdenoise2(res,4,'Wavelet','haar');
aSNR_h = 20*log10((norm(I_c))/norm(I_c-double(denoised_h)));
str_h = string(aSNR_h);
denoised_db = wdenoise2(res,4,'Wavelet','db2');
aSNR_db = 20*log10((norm(I_c))/norm(I_c-double(denoised_db)));
str_db = string(aSNR_db);
denoised_s = wdenoise2(res,4,'Wavelet','sym3');
aSNR_s = 20*log10((norm(I_c))/norm(I_c-double(denoised_s)));
str_s = string(aSNR_s);
name_h = strcat('Haar SNR=',str_h,'dB');
name_db = strcat('Daubechies SNR=',str_db,'dB');
name_s = strcat('Symlets SNR=',str_s,'dB');
subplot(3,3,i); imshow(uint8(denoised_h)); title(name_h);
subplot(3,3,i+3); imshow(uint8(denoised_db)); title(name_db);
subplot(3,3,i+6); imshow(uint8(denoised_s)); title(name_s);
end
```
### 1.D Comparing Results
**De-noise the images using discrete wavelet transform (DWT). Apply three wavelets i.e., Haar, Daubechies (DB), and Symlets to denoise the images. Display only the best results for each image and each type of noise and wavelet.**
As can be observed, Symlets perform better denoising for images with Salt-and-Pepper Noise at all SNR values that we tested, i.e., 10dB, 20dB, and 60dB.
For Gaussian Noise, Symlets perform better denoising for lower SNR at 10dB. Daubechies perform better for mid-range noise such as 20dB and Haar is the best wavelets choice for low noises at 60dB SNR.
________
***Submitted by***
*Shauryasikt Jena-2018EE10500*
*Kushal Gowda-2018EE10304*
*Ayesha Kajol Rafi-2018EE30533*