contrib/gel/vifa/vifa_histogram.h
Go to the documentation of this file.
00001 // This is gel/vifa/vifa_histogram.h
00002 #ifndef VIFA_HISTOGRAM_H
00003 #define VIFA_HISTOGRAM_H
00004 
00005 //-----------------------------------------------------------------------------
00006 //:
00007 // \file
00008 // \brief General Purpose Histogram
00009 //
00010 //  This histogram is mainly a port from the old histogram class in TargetJr
00011 //  which resided in GeneralUtility/Basics.  In this initial version, not all
00012 //  the functionality is ported but it is intended to be useful.
00013 //  It is placed in vsrl right now because it is not determined yet where it
00014 //  should permanently live.
00015 //
00016 // \author Glen W. Brooksby
00017 // \date   14 April, 2003
00018 //
00019 // \verbatim
00020 //  Modifications
00021 //   2003/04/14 Initial Version
00022 //   2003/06/02 MPP Moved to vifa, since it's the only user for now...
00023 //
00024 // \endverbatim
00025 //-----------------------------------------------------------------------------
00026 
00027 #include <vbl/vbl_ref_count.h>
00028 #include <vbl/vbl_smart_ptr.h>
00029 #include <vul/vul_timestamp.h>
00030 
00031 class vifa_histogram : public vul_timestamp,
00032                        public vbl_ref_count
00033 {
00034   enum histogram_type{HISTOGRAM=0, CONTRAST_HIST, NUM_TYPES};
00035  protected:
00036   char delimiter;   // text delimiter for writing out histograms.
00037   float* vals;      // histogram of x array (value = midpoint of the buckets.
00038   float* counts;    // histogram of y array; counts[i] is the # of pixels
00039                     // with value within range of bucket i.
00040   int num;          // Number of indices.
00041   float delta;      // Width of the bins
00042   float vmax, vmin; // Max & Min plots on the histogram.
00043   mutable float mean; // Mean value of the distribution
00044   mutable float standard_dev; // Standard Deviation of the distribution
00045 
00046   virtual int GetIndex(float i) const;
00047 
00048  public:
00049   // Constructors
00050   vifa_histogram();
00051   vifa_histogram(int, float, float);
00052   vifa_histogram(float*, float*, int);
00053   vifa_histogram(const vifa_histogram& h); // copy X-tor
00054   // Resampling Constructor
00055   vifa_histogram(vifa_histogram const*, float width, bool preserveCounts=false);
00056   // Destructor
00057   virtual ~vifa_histogram();
00058 
00059   // Formative function(s)
00060   vifa_histogram* Scale(float scale_factor);
00061   vifa_histogram* Cumulative();
00062   vifa_histogram* NonMaximumSupress(int radius = 1, bool cyclic = false);
00063 
00064   // Misc. Methods
00065   void RemoveFlatPeaks(int nbins, float* cnts, bool cyclic);
00066   float CompareToHistogram(vifa_histogram* h);
00067 
00068   // Attribute accessors
00069   void  UpCount(float newval);
00070   void  UpCount(float newval,bool useNewIndexMethod);
00071   int   GetNumSamples() const;
00072   float GetCount(float uval) const;
00073   float SetCount(float pixelval, float count);
00074 
00075   float GetMinVal() const;
00076   float GetMaxVal() const;
00077   float GetMaxCount() const;
00078   float GetMean() const;
00079   float GetStandardDev() const;
00080   float GetMedian() const;
00081   int GetValIndex(float val) const;
00082 
00083   float* GetVals() const
00084   {
00085     stats_consistent = 0; // Values might change.
00086     return vals;
00087   }
00088 
00089   float* GetCounts() const
00090   {
00091     stats_consistent = 0; // Counts might change.
00092     return counts;
00093   }
00094 
00095   int GetRes() const { return num; }
00096 
00097   float GetBucketSize() const { return delta; }
00098 
00099   float* GetMinValAddr() const { return vals+GetIndex(GetMinVal());  }
00100 
00101   float* GetMinCountAddr() const { return counts+GetIndex(GetMinVal());  }
00102 
00103   // Other useful functions
00104   char GetDelimiter() const {return delimiter;}
00105   void SetDelimiter(char d) {delimiter = d;}
00106   float ComputeArea(float low, float high) const;// bounded area
00107   float ComputeArea() const;//total area
00108 
00109   //Find bounds that clip off a given percent of the area
00110   float LowClipVal(float clip_fraction);
00111   float HighClipVal(float clip_fraction);
00112 
00113   void Print();
00114   void Dump(char *);
00115   int  WritePlot(const char* fname);
00116 
00117  private:
00118   mutable int stats_consistent;  // A 2 bit state flag  Mean = 1 | StandDev = 2
00119 };
00120 
00121 typedef vbl_smart_ptr<vifa_histogram> vifa_histogram_sptr;
00122 
00123 
00124 #endif // VIFA_HISTOGRAM_H