contrib/brl/bbas/bsta/bsta_int_histogram_2d.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/bsta_int_histogram_2d.h
00002 #ifndef bsta_int_histogram_2d_h_
00003 #define bsta_int_histogram_2d_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \brief 1D and 2D integer Histograms with bucket width = 1
00008 //
00009 //  This simple histogram class is an integer version of gel/vifa/vifa_histogram.h
00010 //    which was a port from Targetjr.  Also borrowed from bsta_histogram.  Only the
00011 //    features needed for integer histograms of images with bucket_width = 1 are included.
00012 //    The class is defined to create a histogram with long int buckets (4 bytes).
00013 //
00014 //  Note that the 2D version is lacking some of the 1D methods because it isn't obvious
00015 //    that they would be of any use for a 2D histogram
00016 //
00017 //  The 2D histogram is a special case useful for isolating similarly colored regions
00018 //    of an image.  Probably not very generally useful to the vxl community.  But here
00019 //    it is anyway
00020 //
00021 //  This 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 #include <vcl_cassert.h>
00035 #include <bsta/bsta_int_histogram_1d.h>
00036 
00037 class bsta_int_histogram_2d
00038 {
00039  private:
00040   unsigned int nbins_x_;
00041   unsigned int nbins_y_;
00042   unsigned int diag_;                               // # buckets in diagonal 1D hist
00043   vcl_vector<vcl_vector<long int> > counts_;        // the histogram buckets
00044 
00045  public:
00046 
00047   //:default constructor that assumes all data values are positive constructor parameters:
00048   // \param nbins_x, \param nbins_y      # bins to create in this 2D histogram.
00049   bsta_int_histogram_2d(const unsigned int nbins_x, const unsigned int nbins_y);
00050 
00051   // destructor
00052   ~bsta_int_histogram_2d() ;
00053 
00054   // The number of bins in the histogram
00055   unsigned int nbins_x() const { return nbins_x_;}
00056   unsigned int nbins_y() const { return nbins_y_;}
00057 
00058   //: get the count in a given bin
00059   long int get_count(const unsigned int binx, const unsigned int biny)
00060   { assert(binx < nbins_x_ && biny < nbins_y_); return counts_[biny][binx]; }
00061 
00062   //: set the count in a given bin
00063   void set_count(const unsigned int binx, const unsigned int biny, const long int count)
00064   { if (binx<nbins_x_ && biny<nbins_y_) counts_[biny][binx] = count; }
00065 
00066   //: Total area under the histogram = total counts in histogram
00067   unsigned long int get_area();
00068 
00069   // get highest value in histogram; returns max value; index of max is available in imax
00070   unsigned long int get_max_val(unsigned int &imax_x, unsigned int &imax_y);
00071 
00072   //: Smooth the 2D histogram with a Parzen window of sigma
00073   void parzen(const float sigma);
00074 
00075   //: Form a "profile" histogram along the diagonal with max value normal to diagonal in buckets
00076   void profile_histogram( bsta_int_histogram_1d &phist,
00077                           bsta_int_histogram_1d &phist_x,
00078                           bsta_int_histogram_1d &phist_y );
00079 
00080   //: Find where peak drops to X% along normal on either front or rear edge of diagonal slope.
00081   //  Here the "front" is the top edge, "rear" is the bottom edge
00082   bool find_edge( unsigned int peak_y, unsigned int peak_x,
00083                   float newslope, float edgepct,
00084                   unsigned int &edge_x, unsigned int &edge_y,
00085                   bool front);
00086 };
00087 
00088 #endif // bsta_int_histogram_2d_h_