function HistResol=tu_and_ctu_histogram_resolution(base,NBposition,flag)
% Calculates the number of texture units for a given configuration M and N
% Inputs: 
%         M: Spectral resolution
%         N: Spatial resolution
%
%         flag: takes values 1 or 2
%              flag = 1 : ordered texture units (original) are calculated
%              flag = 2 : non ordered texture units (CTU) are calculated

% Copyright 2015 Abdelmounaime Safia
% Last Revision January, 4, 2015

if flag==1 % Texture unit case
    HistResol=base^NBposition;
elseif flag==2 % Compact texture unit case
    HistResol=factorial(base+NBposition-1)/(factorial(NBposition)*factorial(base-1));
else
   error('Invalid algorithm flag value') ;
end