bayes_generator.h

00001
00002 /**************************************************************************
00003  *  bayes_generator.h - generator for colormap using a bayesian method
00004  *
00005  *  Created: Wed Mar 01 14:00:41 2006
00006  *  Copyright  2005-2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ***************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #ifndef __FIREVISION_MODELS_COLOR_BAYES_BAYES_GENERATOR_
00025 #define __FIREVISION_MODELS_COLOR_BAYES_BAYES_GENERATOR_
00026 
00027 #include <fvutils/colormap/generator.h>
00028
00029 #include <vector>
00030 #include <map>
00031
00032 class YuvColormap;
00033 class BayesHistosToLut;
00034
00035 class BayesColormapGenerator : public ColormapGenerator
00036 {
00037
00038  public:
00039   BayesColormapGenerator( unsigned int lut_depth = 1,
00040                           hint_t fg_object = H_UNKNOWN,
00041                           unsigned int lut_width = 256, unsigned int lut_height = 256);
00042   ~BayesColormapGenerator();
00043
00044   virtual void                     set_fg_object(hint_t object);
00045   virtual void                     set_buffer(unsigned char *buffer,
00046                                               unsigned int width, unsigned int height);
00047   virtual YuvColormap *            get_current();
00048   virtual void                     consider();
00049   virtual void                     calc();
00050   virtual void                     undo();
00051   virtual void                     reset();
00052   virtual void                     reset_undo();
00053
00054   virtual void                     set_selection(std::vector< fawkes::rectangle_t > region);
00055
00056   virtual bool                     has_histograms();
00057   virtual std::map< hint_t, Histogram * > *  get_histograms();
00058
00059   virtual void                     load_histograms(const char *filename);
00060   virtual void                     save_histograms(const char *filename);
00061
00062   void set_min_probability(float min_prob);
00063
00064  private:
00065   bool is_in_region(unsigned int x, unsigned int y);
00066   void normalize_histos();
00067
00068   typedef std::map< hint_t, Histogram * > HistogramMap;
00069   HistogramMap fg_histos;
00070   HistogramMap bg_histos;
00071   HistogramMap histos;
00072   HistogramMap::iterator histo_it;
00073
00074   BayesHistosToLut      *bhtl;
00075   YuvColormap           *cm;
00076
00077   hint_t fg_object;
00078
00079   unsigned int lut_width;
00080   unsigned int lut_height;
00081   unsigned int lut_depth;
00082
00083   unsigned int image_width;
00084   unsigned int image_height;
00085
00086   unsigned int norm_size;
00087
00088   unsigned char *buffer;
00089   std::vector< fawkes::rectangle_t >  region;
00090   std::vector< fawkes::rectangle_t >::iterator  rit;
00091
00092   bool *selection_mask;
00093 };
00094
00095 #endif