Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Histogram1D.hh
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21 #ifndef __Histogram1D_hh__
22 #define __Histogram1D_hh__
23 
24 #include <bias_config.h>
25 
26 #include <Base/Debug/Debug.hh>
27 #include <Base/Debug/Error.hh>
28 
29 #include <vector>
30 
31 namespace BIAS {
32 
33  /** @class Histogram1D
34  * @ingroup g_mathalgo
35  @brief Simple one dimensional histogram computation. Only defined for T=float|double
36  @author woelk 01/2008 (c) www.vision-n.de */
37  template <class T>
38  class BIASMathAlgo_EXPORT Histogram1D
39  : public Debug
40  {
41  public:
42  Histogram1D();
43 
44  ~Histogram1D();
45 
46  inline void Clear() { Data_.clear(); }
47 
48  void AddData(const std::vector<T>& data);
49 
50  void AddData(const T& data);
51 
52  int GetHistogram(std::vector<T>& bin_center, std::vector<unsigned>& hist);
53 
54  /**
55  * \return the bin center with the maximum number of entries
56  * \author ischiller
57  */
58  T GetBinCenterWithMaxEntries();
59 
60  inline void SetHistogramBoundaries(const T &min_val, const T &max_val)
61  { BIASASSERT(min_val<max_val); MinValue_=min_val; MaxValue_=max_val; }
62 
63  inline void SetAutoScale(const bool val)
64  { AutoScale_ = val; }
65 
66  inline void SetNumBins(const unsigned val)
67  { BIASASSERT(val>0); NumBins_ = val; }
68 
69  protected:
70  std::vector<T> Data_;
71  unsigned NumBins_;
72  T MinValue_, MaxValue_, BinSize_;
73  bool AutoScale_; ///< compute min and max value automatically
74 
75  inline int GetBinNum_(const T& data){
76  if (data<MinValue_ || data>MaxValue_) return -1;
77  return int((data-MinValue_)/BinSize_);
78  }
79 
80  void InitInternalsFromData_();
81 
82  void InitInternals_();
83 
84  void ComputeBinCenters_(std::vector<T>& center) const;
85  };
86 
87 }
88 
89 
90 #endif // __Histogram1D_hh__
int GetBinNum_(const T &data)
Definition: Histogram1D.hh:75
void SetHistogramBoundaries(const T &min_val, const T &max_val)
Definition: Histogram1D.hh:60
void SetAutoScale(const bool val)
Definition: Histogram1D.hh:63
Simple one dimensional histogram computation.
Definition: Histogram1D.hh:38
bool AutoScale_
compute min and max value automatically
Definition: Histogram1D.hh:73
std::vector< T > Data_
Definition: Histogram1D.hh:70
void SetNumBins(const unsigned val)
Definition: Histogram1D.hh:66