#ifndef __HISTEQUALIZE_H__
#define __HISTEQUALIZE_H__

#include "image2d.h"
#include <iostream>
#include <iomanip>

/// histogram equalizing class for images
/**
 * this class is able to generate a equalization 
 * function for multiple tiled images
 */
class histequalize
{
 public:
  histequalize();
  ~histequalize();
  int init( int nbins );
  int del();

  /// add the image data to the histogram
  /**
   * image pixel values should be [0,1]
   */
  int addimage( image2d *im );

  /// add the image data to the histogram using only pixels marked by mask image
  /**
   * image pixel values should be [0,1]
   */
  int addimage( image2d *im, image2d *mask );

  /// apply histogram equalization to image
  /**
   * this applies the histogram equalizetion function
   * calculated with the histogram of images presented 
   * with the addimage function.
   */
  int equalize( image2d *im );

  int printR();

 private:
  double *hist;
  double *mapping;
  double npixels;
  int nbins;
  int mappingdone;
};

#endif
