%N heqcg %F $MIR/src/subs/cgsubs.for
%D Histogram equalize an image
%P nebk
%: plotting
%B
      subroutine heqcg (pixr, n, nimage, image, nbins, his, cumhis)

      integer nbins, n, nimage(n), his(nbins)
      real image(n), pixr(2), cumhis(nbins)
  ---------------------------------------------------------------------
  Apply histogram equalization to an image directly.  128 bins
  are used in the histogram.

  Input
   pixr   Display intensity range
   n      Number of pixels
   nimage Normalization image
   nbins  Number of bins in histogram
  Input/output
   image  Image
   his    Image histogram
   cumhis Cumulative histogram.  Values for each bin are
          the intensities assigned to the image.  Thus
          if an image pixel ended up in cumhis bin idx, then
          its new value is cumhis(idx)
