% License Creative Commons 0 (like the public domain)
% Use, study, modify and share!
% Even if you are not forced with copyleft, do not forget to respect freedom of others.
% For more informations : https://www.gnu.org/philosophy/free-sw.html
% If you modify it and use it with MATLAB (that is proprietary), please check compatibility with GNU Octave (that is free/libre software that has only few differences).
% This program is provided with no warranty.
% Names of contributors must not be used to endorse or promote products derived from this software without specific prior written permission.
% @author Spanti Nicola (RyDroid)


function histogram = image_to_gray_histogram(image, step = 1)
	if step < 0
		error('step must be positive');
	end
	if step == 0
		error('step must not be null');
	end
	
	histogram = zeros(256 / step);
	[rows, columns] = size(image);
	
	for i = 1 : rows
		for j = 1 : columns
			colorPlusOneDividedByStep = (image(i,j) + 1) / step;
			histogram(colorPlusOneDividedByStep) = histogram(colorPlusOneDividedByStep) +1;
		end
	end
end
