Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpHistogram.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Gray level histogram manipulation.
32  *
33  * Author:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
38 
39 
47 #ifndef vpHistogram_h
48 #define vpHistogram_h
49 
50 #include <sstream>
51 
52 #include <visp3/core/vpImage.h>
53 #include <visp3/core/vpHistogramPeak.h>
54 #include <visp3/core/vpHistogramValey.h>
55 #include <visp3/core/vpColor.h>
56 
57 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
58 # include <visp3/core/vpList.h>
59 #endif
60 
61 #include <list>
62 
113 class VISP_EXPORT vpHistogram
114 {
115 public:
116  vpHistogram();
117  vpHistogram(const vpHistogram &h);
119  virtual ~vpHistogram();
120 
121  vpHistogram & operator=(const vpHistogram &h);
122 
143  inline unsigned operator[](const unsigned char level) const
144  {
145  if (level < size) {
146  return histogram[level];
147  }
148 
149  std::stringstream ss;
150  ss << "Level is > to size (" << size << ") !";
151  throw vpException(vpException::dimensionError, ss.str().c_str());
152  };
173  inline unsigned operator()(const unsigned char level) const
174  {
175  if(level < size) {
176  return histogram[level];
177  }
178 
179  std::stringstream ss;
180  ss << "Level is > to size (" << size << ") !";
181  throw vpException(vpException::dimensionError, ss.str().c_str());
182  };
203  inline unsigned get(const unsigned char level) const
204  {
205  if(level < size) {
206  return histogram[level];
207  }
208 
209  std::stringstream ss;
210  ss << "Level is > to size (" << size << ") !";
211  throw vpException(vpException::dimensionError, ss.str().c_str());
212  };
213 
231  inline void set(const unsigned char level, unsigned int value)
232  {
233  if(level < size) {
234  histogram[level] = value;
235  } else {
236  std::stringstream ss;
237  ss << "Level is > to size (" << size << ") !";
238  throw vpException(vpException::dimensionError, ss.str().c_str());
239  }
240  };
241 
242  void calculate(const vpImage<unsigned char> &I, const unsigned int nbins=256, const unsigned int nbThreads=1);
243 
244  void display(const vpImage<unsigned char> &I, const vpColor &color=vpColor::white, const unsigned int thickness=2,
245  const unsigned int maxValue_=0);
246 
247  void smooth(const unsigned int fsize = 3);
248  unsigned getPeaks(std::list<vpHistogramPeak> & peaks);
249  unsigned getPeaks(unsigned char dist,
250  vpHistogramPeak & peak1,
251  vpHistogramPeak & peak2);
252  bool getPeaks(unsigned char dist,
253  vpHistogramPeak & peakl,
254  vpHistogramPeak & peakr,
255  vpHistogramValey & valey);
256  unsigned getValey(std::list<vpHistogramValey> & valey);
257  bool getValey(const vpHistogramPeak & peak1,
258  const vpHistogramPeak & peak2,
259  vpHistogramValey & valey);
260  unsigned getValey(unsigned char dist,
261  const vpHistogramPeak & peak,
262  vpHistogramValey & valeyl,
263  vpHistogramValey & valeyr);
264  unsigned sort(std::list<vpHistogramPeak> & peaks);
265 
266  bool write(const std::string &filename);
267  bool write(const char *filename);
268 
277  inline unsigned getSize() const
278  {
279  return size;
280  };
281 
303  inline unsigned * getValues()
304  {
305  return histogram;
306  };
307 
308 private:
309  void init(unsigned size = 256);
310 
311  unsigned int *histogram;
312  unsigned size; // Histogram size (max allowed 256)
313 };
314 
315 
316 
317 #endif
318 
319 /*
320  * Local variables:
321  * c-basic-offset: 2
322  * End:
323  */
unsigned getSize() const
Definition: vpHistogram.h:277
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
error that can be emited by ViSP classes.
Definition: vpException.h:73
Class to compute a gray level image histogram.
Definition: vpHistogram.h:113
Declaration of the peak (maximum value) in a gray level image histogram.
unsigned operator[](const unsigned char level) const
Definition: vpHistogram.h:143
unsigned operator()(const unsigned char level) const
Definition: vpHistogram.h:173
static const vpColor white
Definition: vpColor.h:158
Declaration of the valey (minimum value) in a gray level image histogram.
void set(const unsigned char level, unsigned int value)
Definition: vpHistogram.h:231
unsigned * getValues()
Definition: vpHistogram.h:303