bayes_histos_to_lut.h

00001
00002 /**************************************************************************
00003  *  bayes_histos_to_lut.h - This header defines a class
00004  *                          that takes color histograms of objects as input,
00005  *                          and, together with probabilities of objects,
00006  *                          generates all the values for a lookup-table
00007  *                          that maps from colors to objects
00008  *
00009  *  Created: Mon Jun 27 14:16:52 2005
00010  *  Copyright  2005       Martin Heracles
00011  *             2005-2008  Tim Niemueller [www.niemueller.de]
00012  *             2007-2008  Daniel Beck
00013  *
00014  ***************************************************************************/
00015
00016 /*  This program is free software; you can redistribute it and/or modify
00017  *  it under the terms of the GNU General Public License as published by
00018  *  the Free Software Foundation; either version 2 of the License, or
00019  *  (at your option) any later version. A runtime exception applies to
00020  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00021  *
00022  *  This program is distributed in the hope that it will be useful,
00023  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00024  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025  *  GNU Library General Public License for more details.
00026  *
00027  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00028  */
00029
00030 #ifndef __FIREVISION_COLORMODEL_BAYES_HISTOS_TO_LUT_H_
00031 #define __FIREVISION_COLORMODEL_BAYES_HISTOS_TO_LUT_H_
00032 
00033 #include <fvutils/base/roi.h>
00034
00035 #include <map>
00036 #include <string>
00037
00038 class Histogram;
00039 class YuvColormap;
00040
00041 class BayesHistosToLut
00042 {
00043  public:
00044   BayesHistosToLut(std::map< hint_t, Histogram * > &histos,
00045                    unsigned int d = 1,
00046                    hint_t fg_object = H_UNKNOWN,
00047                    unsigned int w = 256,
00048                    unsigned int h = 256);
00049   ~BayesHistosToLut();
00050
00051   std::string getName();
00052
00053   float getObjectProb(hint_t object);
00054
00055   float getAPrioriProb( unsigned int u,
00056                         unsigned int v,
00057                         hint_t object );
00058   float getAPrioriProb( unsigned int y,
00059                         unsigned int u,
00060                         unsigned int v,
00061                         hint_t object );
00062
00063   float getAPosterioriProb( hint_t object,
00064                             unsigned int u,
00065                             unsigned int v );
00066   float getAPosterioriProb( hint_t object,
00067                             unsigned int y,
00068                             unsigned int u,
00069                             unsigned int v );
00070
00071   hint_t getMostLikelyObject( unsigned int u,
00072                               unsigned int v );
00073   hint_t getMostLikelyObject( unsigned int y,
00074                               unsigned int u,
00075                               unsigned int v );
00076
00077   void setMinProbability( float min_prob );
00078   void setMinProbForColor( float min_prob, hint_t hint );
00079
00080   YuvColormap * get_colormap();
00081
00082   /* method "calculateLutValues" calculates lut values
00083      following the bayesian approach */
00084   void calculateLutValues( bool penalty = false );
00085   /* method "calculateLutAllColors" calculates lut values
00086      _without_ following the bayesian approach, but it can handle all colors
00087      (not only "ball" and "background") */
00088   void calculateLutAllColors();
00089   void saveLut(char *file);
00090   void save(std::string filename);
00091
00092  private:
00093   std::map<hint_t, Histogram*>  &histograms;
00094   std::map<hint_t, unsigned int> numberOfOccurrences;
00095   std::map<hint_t, float>        object_probabilities;
00096
00097   YuvColormap *lut;
00098   unsigned int width;
00099   unsigned int height;
00100   unsigned int depth;
00101
00102   hint_t fg_object;
00103
00104   float   min_probability;
00105
00106   // color thresholds:
00107   float min_prob_ball;
00108   float min_prob_green;
00109   float min_prob_yellow;
00110   float min_prob_blue;
00111   float min_prob_white;
00112   float min_prob_black;
00113 };
00114
00115 #endif