% 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 image = image_thresholding(image, min=0, max=255, valueMin=0, valueMax=255)
	if min > max
		error('min > max');
	end
	if valueMin > valueMax
		error('valueMin > valueMax');
	end
	
	[rows, columns] = size(image);
	
	for row = 1 : rows
		for column = 1 : columns
			if image(row,column) < min
				image(row,column) = valueMin;
			elseif image(row,column) > max
				image(row,column) = valueMax;
			end
		end
	end
end
