contrib/brl/bbas/bsta/bsta_int_histogram_1d.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/bsta_int_histogram_1d.h
00002 #ifndef BSTA_INT_HISTOGRAM_1D_H_
00003 #define BSTA_INT_HISTOGRAM_1D_H_
00004 
00005 //-----------------------------------------------------------------------------
00006 //:
00007 // \file
00008 // \brief 1D integer Histograms with bucket width = 1
00009 //
00010 //  This simple histogram class is an integer version of gel/vifa/vifa_histogram.h
00011 //    which was a port from Targetjr.  Also borrowed from bsta_histogram.  Only the
00012 //    features needed for integer histograms of images with bucket_width = 1 are included.
00013 //    The class is defined to create a histogram with long int buckets (4 bytes).
00014 //
00015 //  The original Targetjr class had methods like ::scale(...) which were needed
00016 //    (for example) for the edgel strength algorithm in which bucket widths needed to
00017 //    be rescaled, etc, so all floats were used.  Here we just use integers.  Also
00018 //    included are some useful methods for finding properties of these histograms, like
00019 //    the min and max value, largest value, locations of these, etc.
00020 //
00021 //  It is initially placed in bbas/bsta for now.  If others think it useful, it can be
00022 //    moved to a permanent home later.
00023 //
00024 // \author James E. Green
00025 // \date   23 April, 2007
00026 //
00027 // \verbatim
00028 //  Modifications
00029 //   2007/04/23 Initial Version
00030 // \endverbatim
00031 //-----------------------------------------------------------------------------
00032 
00033 #include <vcl_vector.h>
00034 
00035 class bsta_int_histogram_1d
00036 {
00037  private:
00038   unsigned int nbins_;
00039   vcl_vector<long int> counts_;
00040 
00041  public:
00042 
00043  // default constructor that assumes all data values are positive
00044   // constructor parameters:
00045   //   nbins_      # bins to create in this histogram.  Note that for 2-byte data the number
00046   //                 could be 0-65,535, it is usually much smaller,  1-byte data ranges
00047   //                 0-255, but may be less. (so it's an unsigned int)
00048 
00049   bsta_int_histogram_1d(const unsigned int bins);
00050 
00051   // destructor
00052   ~bsta_int_histogram_1d();
00053 
00054   // The number of bins in the histogram
00055   unsigned int get_nbins() const { return nbins_;}
00056 
00057   //: min,max of total range
00058   unsigned int get_min_bin();
00059   unsigned int get_max_bin();
00060 
00061   //: Get total area under the histogram = total counts in histogram
00062   unsigned long int get_area();
00063 
00064   //: Get the count in a given bin
00065   long int get_count(unsigned int bin); // const??
00066 
00067   //: Set the count for a given bin
00068   void set_count(const unsigned int bin, const long int val);
00069 
00070   // Get highest value in histogram; returns max value; index of max is available in imax
00071   unsigned long int get_max_val(unsigned int &imax);
00072 
00073   // Trim off a fraction of the histogram at top and bottom ends.  Note that fractions
00074   //    should be less than 0.5, usually considerably less, eg usually 0.01 or less.
00075   void trim(float low_fract, float high_fract);
00076 
00077   // Zero out bottom n bins.
00078   void zero_low(unsigned n);
00079 
00080   // Zero out top n bins.
00081   void zero_high(unsigned n);
00082 
00083   //: Smooth the histogram with a Parzen window of sigma
00084   void parzen(const float sigma);
00085 
00086   // Find the "significant peaks & vallwys in a histogram.  Here "significant" means there is
00087   //   a specified difference in height between the peak and the previous valley, or vice versa.
00088   bool find_peaks( float perct, int &n_peaks, vcl_vector<unsigned int> &peaks);
00089 };
00090 
00091 #endif // BSTA_INT_HISTOGRAM_1D_H_