function [f1] = log_adj(f0,K,L);
% Color Map for Logarithmic Adjustment
% [f1] = log_adj(f0,K,L)
%
% Logarithmic Adjustment: f1 = log(1+(e^K - 1)*f0)/K
% 
% f1, f0: Indexed images (uint8 between 0 and L-1)
%      K: Logarithmic Adjustment parameter
%      L: Number of index levels
%

%if isind(f0) == 1
    f0 = mat2gray(double(f0),[0,L-1]);
%else
%    error('*** f0 must be an indexed (uint8) image ***');
%end

if K < 0
    error('*** K must >= 0 ***');
elseif K == 0
    f1 = f0;
else
    f1 = log(1+(exp(K)-1)*f0)/K;
end

f1 = uint8(f1*(L-1));