% scales and displays a greyscale image on log scale; returns nothing
%
% displays NaN as red
%
% use: tvslog(A)                     % default threshold is .001
%      tvslog(A,threshold)
%      tvslog(A,threshold,negative)  % supply any 3rd argument to save toner
%
%      output_image = tvslog(A)      % return image instead of displaying it

function output_image = like_PVwave(A,threshold,anything_you_like)
     % usually returns nothing

if nargin == 1 
  disp('tvslog: using default threshold of .001 (60dB down)')
  threshold = .001;
end%if

if threshold <= 0
  disp('tvslog: threshold must be positive')
  disp('      : exiting...')
  return
end%if

Amin = min2nan(A);
Amax = max2nan(A);
% normalize on [0,1] to have a meaningful threshold
Asc = (A-Amin)/(Amax-Amin);
clear A
Alog = log(Asc+threshold);
clear Asc
if nargout == 0
  tvs((-1)^(nargin==3)*Alog)
else%if
  output_image = (-1)^(nargin==3)*Alog;
end%if

