function S = equalize_spectrogram(S,dir,ddt,dwd,fsmp)
  % Attempts to adjust the values of a spectrogram {S} so that
  % they lie in [0_1] and have maximum constrast without 
  % affecting their relative values too much.
  % 
  % If {dir} is 0, normalizes each column; if {dir} is 1, normalizes
  % each row; if {dir} is in between, uses a combination of the two.
  % 
  % Wants the window width {dwd} and the displacement {ddt} between 
  % successive windows, as well as the sampling frequency {fsmp}.
  close all
  M = size(S,1);
  N = size(S,2);
  % Compute rms value for each row and column:
  vrow = zeros(M,1);
  for ii = 1:M
    vrow(ii,1) = norm(vec(S(ii,:)))/sqrt(N);
  end
  vcol = zeros(1,N);
  for jj = 1:N
    vcol(1,jj) = norm(S(:,jj))/sqrt(M);
  end
  % Normalize by geometric mean of the two:
  for ii = 1:M
    for jj = 1:N
      S(ii,jj) = 0.30*S(ii,jj)*(dir/vrow(ii,1) + (1-dir)/vcol(1,jj));
    end
  end
  % imshow(S, 'xdata', [0,N*ddt/fsmp], 'ydata', [(M-1)*fsmp/dwd,0]);