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