%% Noise reduction via averaging for images

I = imread('coins.png');

m=100;

Iavg=0;

for ind=1:m
    %Ino{ind}=im2double(imnoise(I,'gaussian',0.2));
    Ino{ind}=im2double(imnoise(I,'salt & pepper',0.5));
    
    Iavg=Iavg+Ino{ind}/m;
    
end



%Iavg=Iavg/m;

figure(1)
imshow(I);
title('Original')

figure(2)
imshow(Ino{1});
title('With Noise')

figure(3)
imshow(Iavg);
title('Average')




%% Linear Filter for images

I = imread('coins.png');
Ino=imnoise(I,'salt & pepper',0.1);
Ino=imnoise(I,'gaussian',0.1);


c=3;

h = ones(c,c)/(c^2);

I2 = imfilter(Ino,h);



figure(4);
imshow(I), title('Original Image');

figure(5);
imshow(Ino), title('Image with noise');

figure(6);
imshow(I2), title('Filtered Image')

%% Median Filter for images


I = imread('coins.png');
Ino=imnoise(I,'salt & pepper',0.3);
Ino=imnoise(I,'gaussian',0.1);


c=3;

I2 = medfilt2(Ino,[c c]);



figure(7);
imshow(I), title('Original Image');

figure(8);
imshow(Ino), title('Image with noise');

figure(9);
imshow(I2), title('Filtered Image')




