function [ intensity ] = hist( image_matrix )
% Create a function that: 
% ? realizes a histogram viewer, 
% ? parameters of this function should be as follows: 
%     ? input: image matrix, 
%     ? no output, 
% ? it should work with grayscale images (check if this holds), 
% ? it should raise a new figure (please use figure command) showing the 
% histogram of the input image, use the built-in bar command to plot the column-diagram.

if (size(image_matrix,3) ~= 1)
    error 'This picture is not grayscale!'
end

intensity = zeros(1,256);
for k = 1:size(image_matrix, 1)
    for l = 1: size(image_matrix, 2)
        intensity(image_matrix(k,l) + 1) = intensity(image_matrix(k,l) + 1) + 1;
    end
end

scale = linspace(0, 255, 256);

figure(1)
bar(scale, intensity)
xlim([0 255])
title('Image histogram')
xlabel('Intensity values')
ylabel('Number of occurences')

end

