% Create a script that: 
% ? reads in this image: AndreKertesz_Paris_ManOnBicycle_modified.jpg, 
% ? converts it to grayscale, 
% ? calls your histogram viewer on the input image, 
% ? calls you histogram stretcher on the input image, 
% ? calls your histogram viewer on the output of your histogram stretcher, 
% ? calls your histogram equalizer on the input image with 16 bins, 
% ? calls your histogram viewer on the output of your histogram equalizer, 
% ? shows the input image, the stretched and the equalized images as well, see images below:
% ? load another input image (AndreKertesz_Paris_ManOnBicycle_part.jpg), 
% ? create the noisy-variant of your input image (use the built-in imnoise with ‘salt & pepper’-type noise), 
% ? call your median filter on the noisy image, 
% ? show the input image, the noisy and the filtered versions as well, see below:

%% Histograms
im = imread('AndreKertesz_Paris_ManOnBicycle_modified.jpg');
if (size(im,3) ~= 1) 
    im = rgb2gray(im);
end
figure(1)

subplot(2,3,1)
imshow(im)
title('Original image')

subplot(2,3,4)
hist(im);

subplot(2,3,2)
imshow(stretch(im))
title('Stretched image')

subplot(2,3,5)
hist(stretch(im));

subplot(2,3,3)
imshow(equalize(im, 16))
title('Equalized image')

subplot(2,3,6)
hist(equalize(im, 16));

%% Median-filter
im = imread('AndreKertesz_Paris_ManOnBicycle_part.jpg');
if (size(im,3) ~= 1) 
    im = rgb2gray(im);
end
figure(2)

subplot(1,3,1)
imshow(im)
title('Original image')

subplot(1,3,2)
im_ps = imnoise(im, 'salt & pepper');
imshow(im_ps)
title('Noisy image')

subplot(1,3,3)
imshow(median_filter(im_ps, 3))
title('Median filtered image')
