% SCALES REAL MATRICES INTO 0 TO 255 (or other) RANGE
% WITH LOG SCALE
%
% Y = scaler2(B);  % scales B to go from 0 to 255
%
% Y = scaler2(B,16) % scales B to go from 0 to 15
% Y = scaler2(B,10) % gives matrix of single digit integers
%
% Y = scaler2(B,256,max(max(B))/100); % values < 1/100 of peak set to 1/100 peak
%
% See also scaler2.m

function Y = dummy_name(X,levels_per_pixel,threshold)

if nargin < 2
  levels_per_pixel = 256;
end%if

if nargin == 3
  error('You should try using ``clip.m'''', this not working too well now')
  %threshold = threshold*max(max(X)); %unnormalize(threshold is normalized 0..1)
  X = X.*(X>threshold) + threshold*(X<=threshold); % un normalized, eg
                                                   % suppose X has neg. values
end%if

minX=min(min(X));
X = log(X - minX + eps);

minX=min(min(X));
maxX=max(max(X));

Y = round( (X-minX)*(levels_per_pixel-1)/(maxX-minX) );

