Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IntegralHistogram.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __INTEGRALHISTOGRAM_HH__
27 #define __INTEGRALHISTOGRAM_HH__
28 
29 #include <Base/Common/BIASpragmaStart.hh>
30 
31 #include <vector>
32 #include <Base/Image/Image.hh>
33 #include <Base/Math/Math.hh>
34 #include <Base/Math/Vector.hh>
35 #include "ColorHistogram.hh"
36 
37 
38 #define D_INT_HIST (1<<0)
39 
40 namespace BIAS{
41 
42  /**
43  @class IntegralHistogram
44  @ingroup g_image
45  This Class handels Integral Histograms on HSL Images
46  It represents an integral image histogram and offers basic methods
47  on histograms.
48  @author Ingo Schiller
49  @status untested
50  @date 25.Oktober 2004
51  */
52 
53  class BIASImage_EXPORT IntegralHistogram
54  {
55  public:
56  ///
59 
60 
61  /**
62  Deletes ALL current Histogram information
63  */
64  void Clear();
65 
66  /**
67  set the binsize (must be divideable by 2pown)
68  */
69  void SetBinSize(int binsize);
70 
71  /**
72  set minsat_, which defines the minimum saturation
73  */
74  void SetMinSat(int minsat);
75 
76  /**
77  sets Lambda, which is used to calculate the dist
78  in CalcSimilarity
79  */
80  void SetLambda(int lambda);
81 
82  /**
83  sets expDist_ true or false, used to calculate the dist
84  in CalcSimilarity
85  */
86  void SetExpDist(bool expdist);
87 
88 
89  /**
90  GetBinSize
91  */
92  inline int GetBinSize() const {return nBinsize_;}
93 
94  /**
95  GetBinSizeSat
96  */
97  inline int GetBinSizeSat() const {return nBinsizeSat_;}
98 
99  /**
100  Get Histogram
101  @param roi = the Region in which the histogram should be created
102  @return = Vector which holds the Histogram, structure:
103  binsizeSat * binsizeHue elements(hue and sat )
104  + binsizeSat elements(luminance)
105  + totalNumber of entries (last element)
106  */
107  Vector<int> GetHistogram(int ux,int uy,int lx, int ly);
108 
109 
110  /**
111  calcluates the histogram from the picture and fills the data structs
112  @author Schiller
113  @param image = the image
114  */
115  int GenerateIntegralHist(BIAS::Image<unsigned char>& image,
116  int nBinsize);
117 
118 
119  /**
120  calcluates the histogram from the picture and fills the data structs
121  @author Schiller
122  @param image = the image
123  @param nBinsizeHue = binsize in hue direction
124  @param nBinsizeSat = binsize in sat direction
125  */
126  int GenerateIntegralHistDiffBin(BIAS::Image<unsigned char>& image,
127  int nBinsizeHue, int nBinsizeSat);
128  /**
129  Calculates the Bhattacharyya similarity Coeiffient^2
130  which is the distance or difference of 2 colorhistograms.
131  @param chist = the colorHistogram we compare with
132  @param roi = the roi to compare with: upperx, uppery, lowerx, lowery
133  @return double value, which indicates the similarity. 1 if similar.
134  @author Schiller oktober 2004
135  */
136  double CalcSimilarity(ColorHistogram<unsigned char> &chist,
137  int ux,int uy,int lx, int ly);
138 
139  /** Calculates the Bhattacharyya similarity Coeiffient^2
140  which is the distance or difference of 2 colorhistograms.
141  The similarity is calculated for two image regions/histograms
142  the resulting probability is the weighted sum of both.
143  @return double value, which indicates the similarity. 1 if equal.
144  @author grest Oct 2005
145  */
146  double CalcSimilarity(ColorHistogram<unsigned char> &chist1,
147  int ux1,int uy1,int lx1, int ly1,
149  int ux2,int uy2,int lx2, int ly2,
150  double weightSecond= 0.5);
151 
152  /**
153  dumps information on histogram
154  @param os = the outstream, default std::cout
155  @author Schiller
156  */
157  void Dump(std::ostream& os, int y, int x);
158 
159  protected:
160  //this is the major datastruct
161  //access via [][], has BIAS::Vector which holds H,S,L in binsize each
162  // + bincount as last element in vector
164  std::vector<std::vector<double> > m_cHSData;
165  std::vector<double> m_cLData;
166 
167  int nMinSat_;
168  int nLambda_;
169  bool bExpDist_;
174 
175  int nShift_; // used to shift the pixel to correct position
177  inline void CopyNoCheck(const BIAS::Vector<int>& src,
178  BIAS::Vector<int>& dst){
179  //BIASASSERT(src.size() == dst.size());
180  register int *srcData = src.GetData(), *dstData = dst.GetData();
181  const int *end = srcData + src.size();
182  while (srcData<end){
183  *dstData++ = *srcData++;
184  }
185  }
186  }; // class
187 
188 
189 } // namespace BIAS
190 
191 #include <Base/Common/BIASpragmaEnd.hh>
192 
193 #endif // __INTEGRALHISTOGRAM_HH__
int GetBinSize() const
GetBinSize.
std::vector< double > m_cLData
TNT::Matrix< BIAS::Vector< int > > mHists_
int GetBinSizeSat() const
GetBinSizeSat.
void CopyNoCheck(const BIAS::Vector< int > &src, BIAS::Vector< int > &dst)
std::vector< std::vector< double > > m_cHSData
T * GetData() const
get the pointer to the data array of the vector (for faster direct memory access) ...
Definition: Vector.hh:219
This Class handels Integral Histograms on HSL Images It represents an integral image histogram and of...
Subscript size() const
Definition: vec.h:262