latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiProbabilityMap2D.h 00027 * authors ....: Florian Bley 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 26.3.2003 00030 * revisions ..: $Id: ltiProbabilityMap2D.h,v 1.7 2006/02/08 11:40:30 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_PROBABILITY_MAP_2D_H_ 00034 #define _LTI_PROBABILITY_MAP_2D_H_ 00035 00036 00037 #include "ltiProbabilityMapBase.h" 00038 00039 namespace lti { 00040 /** 00041 * Probability Map based on 2D non-parametric (color) models. 00042 * 00043 * Creates a probability map given two chromacity histogram, one 00044 * modelling the %object color and the other modeling the 00045 * non-object colors. 00046 * 00047 * The probability of a specified color rgb is calculated according to the 00048 * Bayes formula: 00049 * 00050 * \f[ 00051 * p(obj|rgb) = \frac{p(rgb|obj) \cdot p(obj)} 00052 * {(p(rgb|obj) \cdot p(obj) + p(rgb|nonobj) \cdot p(nonobj))} 00053 * \f] 00054 * 00055 * where p(obj) is the overall objectProbability, 00056 * p(nonobj) := 1 - p(obj). 00057 * 00058 * \f$p(rgb|obj)\f$ and \f$p(rgb|nonobj)\f$ are read from the given object 00059 * and non-object models. 00060 */ 00061 class probabilityMap2D : public probabilityMapBase { 00062 public: 00063 /** 00064 * the parameters for the class probabilityMap2D 00065 */ 00066 class parameters : public probabilityMapBase::parameters { 00067 public: 00068 /** 00069 * default constructor 00070 */ 00071 parameters(); 00072 00073 /** 00074 * copy constructor 00075 * @param other the parameters object to be copied 00076 */ 00077 parameters(const parameters& other); 00078 00079 /** 00080 * destructor 00081 */ 00082 ~parameters(); 00083 00084 /** 00085 * returns name of this type 00086 */ 00087 const char* getTypeName() const; 00088 00089 /** 00090 * copy the contents of a parameters object 00091 * @param other the parameters object to be copied 00092 * @return a reference to this parameters object 00093 */ 00094 parameters& copy(const parameters& other); 00095 00096 /** 00097 * copy the contents of a parameters object 00098 * @param other the parameters object to be copied 00099 * @return a reference to this parameters object 00100 */ 00101 parameters& operator=(const parameters& other); 00102 00103 /** 00104 * returns a pointer to a clone of the parameters 00105 */ 00106 virtual functor::parameters* clone() const; 00107 00108 /** 00109 * check if the object color model is valid. 00110 * 00111 * Valid means that the model has already been set 00112 * (with setObjectColorModel) and that the dimensionality of the model 00113 * is 2. 00114 * 00115 * @return true if valid, false otherwise. 00116 */ 00117 virtual bool isObjectColorModelValid() const; 00118 00119 /** 00120 * check if the non-object color model is valid 00121 * 00122 * Valid means that the model has already been set 00123 * (with setObjectColorModel) and that the dimensionality of the model 00124 * is 2. 00125 * 00126 * @return true if valid, false otherwise. 00127 */ 00128 virtual bool isNonObjectColorModelValid() const; 00129 }; 00130 00131 /** 00132 * default constructor 00133 */ 00134 probabilityMap2D(); 00135 00136 /** 00137 * constructor 00138 * @param theParams the parameters to be used 00139 */ 00140 probabilityMap2D(const parameters& theParams); 00141 00142 /** 00143 * copy constructor 00144 * @param other the object to be copied 00145 */ 00146 probabilityMap2D(const probabilityMap2D& other); 00147 00148 /** 00149 * destructor 00150 */ 00151 virtual ~probabilityMap2D(); 00152 00153 /** 00154 * returns the name of this type ("probabilityMap2D") 00155 */ 00156 virtual const char* getTypeName() const; 00157 00158 /** 00159 * creates a object probability channel of an image (values range from 0.0 00160 * to 1.0). 00161 * @param src1 channel with the first chromacity band. 00162 * @param src2 channel with the second chromacity band. 00163 * @param dest channel where the result will be left. 00164 * @result true is successful, false otherwise 00165 */ 00166 virtual bool apply(const channel8& src1, const channel8& src2, channel& dest) const; 00167 00168 /** 00169 * returns the object probability for a chromacity color value (values range 00170 * from 0.0 to 1.0). 00171 * 00172 * This method uses the given vector to compute the index of the histogram. 00173 * It \b MUST be preinitialized with a size of 2, or the method will crash. 00174 * 00175 * The idea is to externally provide an ivector in order to spare some 00176 * creation time. 00177 * 00178 * @param value1 pixel' value int the first chromacity band. 00179 * @param value2 pixel' value int the second chromacity band. 00180 * @param theBin index vector computed by the method to the histogram 00181 * entry. 00182 * 00183 * @result the object probability 00184 */ 00185 virtual float apply(const ubyte &value1, const ubyte &value2, ivector& theBin) const; 00186 00187 /** 00188 * returns the object probability for a chromacity value (values range 00189 * from 0.0 to 1.0). 00190 * 00191 * This method is thread safe, but much slower than the other one. 00192 * 00193 * @param value1 pixel' value int the first chromacity band. 00194 * @param value2 pixel' value int the second chromacity band. 00195 * @result the object probability 00196 */ 00197 virtual float apply(const ubyte &value1, const ubyte &value2) const; 00198 00199 /** 00200 * copy data of "other" functor. 00201 * @param other the functor to be copied 00202 * @return a reference to this functor object 00203 */ 00204 probabilityMap2D& copy(const probabilityMap2D& other); 00205 00206 /** 00207 * copy data of "other" functor. 00208 * @param other the functor to be copied 00209 * @return a reference to this functor object 00210 */ 00211 probabilityMap2D& operator=(const probabilityMap2D& other); 00212 00213 /** 00214 * returns a pointer to a clone of this functor. 00215 */ 00216 virtual functor* clone() const; 00217 00218 /** 00219 * returns used parameters 00220 */ 00221 const parameters& getParameters() const; 00222 00223 /** 00224 * Read the functor from the given ioHandler. 00225 * 00226 * The default implementation is to read just the parameters object. 00227 * 00228 * Since this virtual method needs to know the exact type of the 00229 * parameters to call the proper read method, it will just assume that the 00230 * current functor instance has a valid parameter set. If this is not 00231 * the case, you need to reimplement the read method to set first a dummy 00232 * parameter object. 00233 * 00234 * @param handler the ioHandler to be used 00235 * @param complete if true (the default) the enclosing begin/end will 00236 * be also written, otherwise only the data block will be written. 00237 * @return true if write was successful 00238 */ 00239 virtual bool read(ioHandler& handler,const bool complete=true); 00240 00241 /** 00242 * compute the second and up iterations of a probability map 00243 * using the given aPriori probabilites per pixel. 00244 */ 00245 bool computeMap(const channel8& src1, const channel8& src2, 00246 channel& aPrioriDest) const; 00247 00248 }; 00249 00250 } 00251 #endif