Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnColourHistogram.h
1 /*****************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnColourHistogram.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 **
11 *****************************************************************************/
12 
13 #pragma once
14 
15 #include <vector>
16 
17 #include "cv.h"
18 
19 // drwnColourHistogram ------------------------------------------------------
20 
41 
43  protected:
44  unsigned _channelBits;
45  unsigned char _mask;
46  double _pseudoCounts;
47  vector<double> _histogram;
48  double _totalCounts;
49 
50  public:
52  drwnColourHistogram(double pseudoCounts = 1.0, unsigned channelBits = 3);
54  drwnColourHistogram(const drwnColourHistogram& histogram);
56  ~drwnColourHistogram() { /* do nothing */ }
57 
59  size_t size() const { return _histogram.size(); }
60 
62  void clear() { clear(_pseudoCounts); }
64  void clear(double pseudoCounts);
65 
66  // i/o
67  const char *type() const { return "drwnColourHistogram"; }
68  drwnColourHistogram *clone() const { return new drwnColourHistogram(*this); }
69  bool save(drwnXMLNode& xml) const;
70  bool load(drwnXMLNode& xml);
71 
73  void accumulate(unsigned char red, unsigned char green, unsigned char blue);
75  void accumulate(const cv::Vec3b& colour) {
76  accumulate(colour.val[2], colour.val[1], colour.val[0]);
77  }
79  void accumulate(const cv::Scalar& colour) {
80  accumulate(colour.val[2], colour.val[1], colour.val[0]);
81  }
82 
84  double probability(unsigned char red, unsigned char green, unsigned char blue) const;
86  double probability(const cv::Vec3b& colour) const {
87  return probability(colour.val[2], colour.val[1], colour.val[0]);
88  }
90  double probability(const cv::Scalar& colour) const {
91  return probability(colour.val[2], colour.val[1], colour.val[0]);
92  }
93 
95  cv::Mat visualize() const;
96 
97  // operators
98  const double& operator[](size_t indx) const { return _histogram[indx]; }
99 };
bool load(drwnXMLNode &xml)
read object from XML node (see also read)
Definition: drwnColourHistogram.cpp:66
drwnColourHistogram * clone() const
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
Definition: drwnColourHistogram.h:68
bool save(drwnXMLNode &xml) const
write object to XML node (see also write)
Definition: drwnColourHistogram.cpp:54
cv::Mat visualize() const
visualization
Definition: drwnColourHistogram.cpp:107
double probability(const cv::Scalar &colour) const
return probability of a cv::Scalar colour sample
Definition: drwnColourHistogram.h:90
void clear()
clear the histogram counts
Definition: drwnColourHistogram.h:62
void accumulate(const cv::Vec3b &colour)
accumulate a cv::Vec3b colour sample
Definition: drwnColourHistogram.h:75
drwnColourHistogram(double pseudoCounts=1.0, unsigned channelBits=3)
constructor
Definition: drwnColourHistogram.cpp:25
double _totalCounts
sum of histogram counts
Definition: drwnColourHistogram.h:48
size_t size() const
returns histogram size
Definition: drwnColourHistogram.h:59
unsigned char _mask
mask for channel bits
Definition: drwnColourHistogram.h:45
double probability(unsigned char red, unsigned char green, unsigned char blue) const
return probability of an RGB colour sample
Definition: drwnColourHistogram.cpp:97
void accumulate(const cv::Scalar &colour)
accumulate a cv::Scalar colour sample
Definition: drwnColourHistogram.h:79
double probability(const cv::Vec3b &colour) const
return probability of a cv::Vec3b colour sample
Definition: drwnColourHistogram.h:86
const char * type() const
returns object type as a string (e.g., Foo::type() { return "Foo"; })
Definition: drwnColourHistogram.h:67
vector< double > _histogram
the histogram counts (with interpolation)
Definition: drwnColourHistogram.h:47
~drwnColourHistogram()
destructor
Definition: drwnColourHistogram.h:56
double _pseudoCounts
psuedo counts for dirchelet prior
Definition: drwnColourHistogram.h:46
unsigned _channelBits
number of bits for each colour channel
Definition: drwnColourHistogram.h:44
Specialized histogram for quantized 3-channel colour values (e.g., RGB).
Definition: drwnColourHistogram.h:42
void accumulate(unsigned char red, unsigned char green, unsigned char blue)
accumulate an RGB colour sample
Definition: drwnColourHistogram.cpp:82
standard Darwin object interface (cloneable and writeable)
Definition: drwnInterfaces.h:72