clear all;

%I = imread('coins.png');
%I = imread('peppers.png');
%I = imread('../Images/stepFunction.png');
I = imread('../../Images/js.jpg');

g = rgb2gray(I);

% Last param is noise setting, % of pixels affected by noise.
gn = imnoise(g, 'salt & pepper', 0.1);
%gn = g;

% Create box and gaussian filters
h2 = ones(5,5) / 25;
h3 = fspecial('gaussian', [5, 5], 1);

% smooth the image
%I2 = imfilter(gn,h2, 'replicate');
I3 = imfilter(gn,h3, 'replicate');
I4 = medfilt2(gn,[5 5]);

imtool(g); 
imtool(gn); 
%imtool(I2); 
imtool(I3); 
imtool(I4); 


imwrite(gn, 'matt_salt.png');

if (0)
imwrite(g, 'gray_peppers.png');
imwrite(gn, 'gray_peppers_salt.png');
imwrite(I2, 'gray_peppers_salt_box.png');
imwrite(I3, 'gray_peppers_salt_gauss.png');
imwrite(I4, 'gray_peppers_salt_median.png');
end

