Fawkes API  Fawkes Development Version
bayes_generator.h
1 
2 /**************************************************************************
3  * bayes_generator.h - generator for colormap using a bayesian method
4  *
5  * Created: Wed Mar 01 14:00:41 2006
6  * Copyright 2005-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ***************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef FIREVISION_MODELS_COLOR_BAYES_BAYES_GENERATOR__
25 #define FIREVISION_MODELS_COLOR_BAYES_BAYES_GENERATOR__
26 
27 #include <fvutils/colormap/generator.h>
28 
29 #include <map>
30 #include <vector>
31 
32 namespace firevision {
33 
34 class YuvColormap;
35 class BayesHistosToLut;
36 
37 class BayesColormapGenerator : public ColormapGenerator
38 {
39 public:
40  BayesColormapGenerator(unsigned int lut_depth = 1,
41  hint_t fg_object = H_UNKNOWN,
42  unsigned int lut_width = 256,
43  unsigned int lut_height = 256);
45 
46  virtual void set_fg_object(hint_t object);
47  virtual void set_buffer(unsigned char *buffer, unsigned int width, unsigned int height);
48  virtual YuvColormap *get_current();
49  virtual void consider();
50  virtual void calc();
51  virtual void undo();
52  virtual void reset();
53  virtual void reset_undo();
54 
55  virtual void set_selection(std::vector<fawkes::rectangle_t> region);
56 
57  virtual bool has_histograms();
58  virtual std::map<hint_t, Histogram *> *get_histograms();
59 
60  virtual void load_histograms(const char *filename);
61  virtual void save_histograms(const char *filename);
62 
63  void set_min_probability(float min_prob);
64 
65 private:
66  bool is_in_region(unsigned int x, unsigned int y);
67  void normalize_histos();
68 
69  typedef std::map<hint_t, Histogram *> HistogramMap;
70  HistogramMap fg_histos;
71  HistogramMap bg_histos;
72  HistogramMap histos;
73  HistogramMap::iterator histo_it;
74 
75  BayesHistosToLut *bhtl;
76  YuvColormap * cm;
77 
78  hint_t fg_object;
79 
80  unsigned int lut_width;
81  unsigned int lut_height;
82  unsigned int lut_depth;
83 
84  unsigned int image_width;
85  unsigned int image_height;
86 
87  unsigned int norm_size;
88 
89  unsigned char * buffer;
90  std::vector<fawkes::rectangle_t> region;
91  std::vector<fawkes::rectangle_t>::iterator rit;
92 
93  bool *selection_mask;
94 };
95 
96 } // end namespace firevision
97 
98 #endif
firevision::BayesColormapGenerator::set_buffer
virtual void set_buffer(unsigned char *buffer, unsigned int width, unsigned int height)
Set buffer.
Definition: bayes_generator.cpp:118
firevision::BayesColormapGenerator::reset_undo
virtual void reset_undo()
Reset undo.
Definition: bayes_generator.cpp:282
firevision::BayesColormapGenerator::get_histograms
virtual std::map< hint_t, Histogram * > * get_histograms()
Get histograms.
Definition: bayes_generator.cpp:310
firevision::BayesColormapGenerator::set_min_probability
void set_min_probability(float min_prob)
Set min probability.
Definition: bayes_generator.cpp:185
firevision::BayesHistosToLut
Definition: bayes_histos_to_lut.h:55
firevision::BayesColormapGenerator::load_histograms
virtual void load_histograms(const char *filename)
Load histogram from a file.
Definition: bayes_generator.cpp:319
firevision::YuvColormap
Definition: yuvcm.h:41
firevision::BayesColormapGenerator::set_fg_object
virtual void set_fg_object(hint_t object)
Set foreground object.
Definition: bayes_generator.cpp:97
firevision::BayesColormapGenerator::~BayesColormapGenerator
~BayesColormapGenerator()
Destructor.
Definition: bayes_generator.cpp:76
firevision::BayesColormapGenerator::has_histograms
virtual bool has_histograms()
Check if this color model uses histograms.
Definition: bayes_generator.cpp:301
firevision::BayesColormapGenerator::calc
virtual void calc()
Calculate.
Definition: bayes_generator.cpp:234
firevision::BayesColormapGenerator::undo
virtual void undo()
Undo last inclusion.
Definition: bayes_generator.cpp:242
firevision::BayesColormapGenerator::save_histograms
virtual void save_histograms(const char *filename)
Save histograms to a file.
Definition: bayes_generator.cpp:429
firevision::BayesColormapGenerator::set_selection
virtual void set_selection(std::vector< fawkes::rectangle_t > region)
Set selection.
Definition: bayes_generator.cpp:157
firevision::BayesColormapGenerator::consider
virtual void consider()
Consider current image.
Definition: bayes_generator.cpp:192
firevision::BayesColormapGenerator::BayesColormapGenerator
BayesColormapGenerator(unsigned int lut_depth=1, hint_t fg_object=H_UNKNOWN, unsigned int lut_width=256, unsigned int lut_height=256)
Constructor.
Definition: bayes_generator.cpp:53
firevision::BayesColormapGenerator::reset
virtual void reset()
Reset color model.
Definition: bayes_generator.cpp:259
firevision::BayesColormapGenerator::get_current
virtual YuvColormap * get_current()
Get current color model.
Definition: bayes_generator.cpp:137