Fawkes API  Fawkes Development Version
bayes_histos_to_lut.h
1 
2 /**************************************************************************
3  * bayes_histos_to_lut.h - This header defines a class
4  * that takes color histograms of objects as input,
5  * and, together with probabilities of objects,
6  * generates all the values for a lookup-table
7  * that maps from colors to objects
8  *
9  * Created: Mon Jun 27 14:16:52 2005
10  * Copyright 2005 Martin Heracles
11  * 2005-2008 Tim Niemueller [www.niemueller.de]
12  * 2007-2008 Daniel Beck
13  *
14  ***************************************************************************/
15 
16 /* This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version. A runtime exception applies to
20  * this software (see LICENSE.GPL_WRE file mentioned below for details).
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Library General Public License for more details.
26  *
27  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
28  */
29 
30 #ifndef _FIREVISION_COLORMODEL_BAYES_HISTOS_TO_LUT_H_
31 #define _FIREVISION_COLORMODEL_BAYES_HISTOS_TO_LUT_H_
32 
33 #include <fvutils/base/roi.h>
34 
35 #include <map>
36 #include <string>
37 
38 namespace firevision {
39 
40 class Histogram;
41 class YuvColormap;
42 
44 {
45 public:
46  BayesHistosToLut(std::map<hint_t, Histogram *> &histos,
47  unsigned int d = 1,
48  hint_t fg_object = H_UNKNOWN,
49  unsigned int w = 256,
50  unsigned int h = 256);
52 
53  std::string getName();
54 
55  float getObjectProb(hint_t object);
56 
57  float getAPrioriProb(unsigned int u, unsigned int v, hint_t object);
58  float getAPrioriProb(unsigned int y, unsigned int u, unsigned int v, hint_t object);
59 
60  float getAPosterioriProb(hint_t object, unsigned int u, unsigned int v);
61  float getAPosterioriProb(hint_t object, unsigned int y, unsigned int u, unsigned int v);
62 
63  hint_t getMostLikelyObject(unsigned int u, unsigned int v);
64  hint_t getMostLikelyObject(unsigned int y, unsigned int u, unsigned int v);
65 
66  void setMinProbability(float min_prob);
67  void setMinProbForColor(float min_prob, hint_t hint);
68 
70 
71  /* method "calculateLutValues" calculates lut values
72  following the bayesian approach */
73  void calculateLutValues(bool penalty = false);
74  /* method "calculateLutAllColors" calculates lut values
75  _without_ following the bayesian approach, but it can handle all colors
76  (not only "ball" and "background") */
77  void calculateLutAllColors();
78  void saveLut(char *file);
79  void save(std::string filename);
80 
81 private:
82  std::map<hint_t, Histogram *> &histograms;
83  std::map<hint_t, unsigned int> numberOfOccurrences;
84  std::map<hint_t, float> object_probabilities;
85 
86  YuvColormap *lut;
87  unsigned int width;
88  unsigned int height;
89  unsigned int depth;
90 
91  hint_t fg_object;
92 
93  float min_probability;
94 
95  // color thresholds:
96  float min_prob_ball;
97  float min_prob_green;
98  float min_prob_yellow;
99  float min_prob_blue;
100  float min_prob_white;
101  float min_prob_black;
102 };
103 
104 } // end namespace firevision
105 
106 #endif
firevision::BayesHistosToLut::calculateLutValues
void calculateLutValues(bool penalty=false)
Calculate LUT values.
Definition: bayes_histos_to_lut.cpp:363
firevision::BayesHistosToLut::saveLut
void saveLut(char *file)
Save LUT to file.
Definition: bayes_histos_to_lut.cpp:511
firevision::BayesHistosToLut::calculateLutAllColors
void calculateLutAllColors()
Calculate all LUT colors.
Definition: bayes_histos_to_lut.cpp:298
firevision::BayesHistosToLut
LUT generation by using Bayesian method on histograms.
Definition: bayes_histos_to_lut.h:44
firevision::YuvColormap
YUV Colormap.
Definition: yuvcm.h:36
firevision::BayesHistosToLut::save
void save(std::string filename)
Save LUT to file.
Definition: bayes_histos_to_lut.cpp:522
firevision::BayesHistosToLut::getMostLikelyObject
hint_t getMostLikelyObject(unsigned int u, unsigned int v)
Get most likely object.
Definition: bayes_histos_to_lut.cpp:245
firevision::BayesHistosToLut::BayesHistosToLut
BayesHistosToLut(std::map< hint_t, Histogram * > &histos, unsigned int d=1, hint_t fg_object=H_UNKNOWN, unsigned int w=256, unsigned int h=256)
Constructor.
Definition: bayes_histos_to_lut.cpp:61
firevision::BayesHistosToLut::getAPosterioriProb
float getAPosterioriProb(hint_t object, unsigned int u, unsigned int v)
P(object| u, v).
Definition: bayes_histos_to_lut.cpp:194
firevision::BayesHistosToLut::getAPrioriProb
float getAPrioriProb(unsigned int u, unsigned int v, hint_t object)
P(u, v| object).
Definition: bayes_histos_to_lut.cpp:162
firevision::BayesHistosToLut::get_colormap
YuvColormap * get_colormap()
Get generated color model.
Definition: bayes_histos_to_lut.cpp:562
firevision::BayesHistosToLut::setMinProbability
void setMinProbability(float min_prob)
Set min probability.
Definition: bayes_histos_to_lut.cpp:533
firevision::BayesHistosToLut::setMinProbForColor
void setMinProbForColor(float min_prob, hint_t hint)
Set min probability for color.
Definition: bayes_histos_to_lut.cpp:543
firevision::BayesHistosToLut::getObjectProb
float getObjectProb(hint_t object)
Get object probability.
Definition: bayes_histos_to_lut.cpp:104
firevision::BayesHistosToLut::getName
std::string getName()
Get name.
Definition: bayes_histos_to_lut.cpp:94
firevision::BayesHistosToLut::~BayesHistosToLut
~BayesHistosToLut()
Destructor.
Definition: bayes_histos_to_lut.cpp:85