latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2001, 2002, 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 .......: ltiProbabilityMap.h 00027 * authors ....: Benjamin Winkler 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 30.1.2001 00030 * revisions ..: $Id: ltiProbabilityMap.h,v 1.16 2006/02/08 11:40:06 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_PROBABILITY_MAP_H_ 00034 #define _LTI_PROBABILITY_MAP_H_ 00035 00036 00037 #include "ltiProbabilityMapBase.h" 00038 00039 namespace lti { 00040 /** 00041 * Probability Map based on 3D non-parametric (color) models. 00042 * 00043 * Creates a probability map given two color histogram, one 00044 * modelling the %object color and the other modeling the 00045 * non-object colors. 00046 * 00047 * The probability of a specified color \e rgb is calculated according to 00048 * the 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 * In case you provide only the object probability histogram, the non-object 00062 * histogram will be assumed to be uniform distributed, i.e. all colors can 00063 * be non-object with the same probability. 00064 */ 00065 class probabilityMap : public probabilityMapBase { 00066 public: 00067 /** 00068 * The parameters for the class probabilityMap 00069 */ 00070 class parameters : public probabilityMapBase::parameters { 00071 public: 00072 /** 00073 * Default constructor 00074 */ 00075 parameters(); 00076 00077 /** 00078 * Copy constructor 00079 * @param other the parameters object to be copied 00080 */ 00081 parameters(const parameters& other); 00082 00083 /** 00084 * Destructor 00085 */ 00086 ~parameters(); 00087 00088 /** 00089 * returns name of this type 00090 */ 00091 const char* getTypeName() const; 00092 00093 /** 00094 * Copy the contents of a parameters object 00095 * @param other the parameters object to be copied 00096 * @return a reference to this parameters object 00097 */ 00098 parameters& copy(const parameters& other); 00099 00100 /** 00101 * Copy the contents of a parameters object 00102 * @param other the parameters object to be copied 00103 * @return a reference to this parameters object 00104 */ 00105 parameters& operator=(const parameters& other); 00106 00107 /** 00108 * returns a pointer to a clone of the parameters 00109 */ 00110 virtual functor::parameters* clone() const; 00111 00112 /** 00113 * Check if the object color model is valid. 00114 * 00115 * Valid means that the model has already been set 00116 * (with setObjectColorModel) and that the dimensionality of the model 00117 * is 3. 00118 * 00119 * @return true if valid, false otherwise. 00120 */ 00121 virtual bool isObjectColorModelValid() const; 00122 00123 /** 00124 * Check if the non-object color model is valid 00125 * 00126 * Valid means that the model has already been set 00127 * (with setObjectColorModel) and that the dimensionality of the model 00128 * is 3. 00129 * 00130 * @return true if valid, false otherwise. 00131 */ 00132 virtual bool isNonObjectColorModelValid() const; 00133 }; 00134 00135 /** 00136 * default constructor 00137 */ 00138 probabilityMap(); 00139 00140 /** 00141 * constructor 00142 * @param theParams the parameters to be used 00143 */ 00144 probabilityMap(const parameters& theParams); 00145 00146 /** 00147 * copy constructor 00148 * @param other the object to be copied 00149 */ 00150 probabilityMap(const probabilityMap& other); 00151 00152 /** 00153 * destructor 00154 */ 00155 virtual ~probabilityMap(); 00156 00157 /** 00158 * returns the name of this type ("probabilityMap") 00159 */ 00160 virtual const char* getTypeName() const; 00161 00162 /** 00163 * Creates an object probability channel of an image (values range from 0.0 00164 * to 1.0). 00165 * @param src image with the source data. 00166 * @param dest channel where the result will be left. 00167 * @return true is successful, false otherwise 00168 */ 00169 virtual bool apply(const image& src,channel& dest) const; 00170 00171 00172 /** 00173 * creates an object probability channel of an image (values range from 0.0 00174 * to 1.0). 00175 * 00176 * @param src image with the source data. 00177 * @param dest channel where the result will be left. 00178 * @param apriori By using this parameter it is possible to include a given 00179 * position-dependent apriori object probability channel in 00180 * the computation of the object probability channel. 00181 * A value of 0.5 at a point indicates equal probabilities 00182 * for object and non-object values. 00183 * Any bigger value (< 1.0) indicates a higher probability 00184 * for object values, any smaller value (> 0) indicates a 00185 * lower probability. 00186 * The apriori-channel should have the same size as the 00187 * input image. 00188 * @return true is successful, false otherwise 00189 */ 00190 virtual bool apply(const image& src,channel& dest, 00191 const channel &apriori) const; 00192 00193 /** 00194 * Returns the object probability for an rgb color value (values range 00195 * from 0.0 to 1.0). 00196 * 00197 * This method uses the given vector to compute the index of the histogram. 00198 * It \b MUST be preinitialized with a size of 3, or the method will crash. 00199 * 00200 * The idea is to externally provide an ivector in order to spare some 00201 * creation time. 00202 * 00203 * @param src rgbPixel with the source color. 00204 * @param theBin index vector computed by the method to the histogram 00205 * entry. 00206 * 00207 * @return the object probability 00208 */ 00209 virtual float apply(const rgbPixel &src,ivector& theBin) const; 00210 00211 /** 00212 * Returns the object probability for an rgb color value (values range 00213 * from 0.0 to 1.0). 00214 * 00215 * This method is thread safe, but much slower than the other one. 00216 * 00217 * @param src rgbPixel with the source color. 00218 * @return the object probability 00219 */ 00220 virtual float apply(const rgbPixel &src) const; 00221 00222 /** 00223 * Copy data of "other" functor. 00224 * @param other the functor to be copied 00225 * @return a reference to this functor object 00226 */ 00227 probabilityMap& copy(const probabilityMap& other); 00228 00229 /** 00230 * Copy data of "other" functor. 00231 * @param other the functor to be copied 00232 * @return a reference to this functor object 00233 */ 00234 probabilityMap& operator=(const probabilityMap& other); 00235 00236 /** 00237 * Returns a pointer to a clone of this functor. 00238 */ 00239 virtual functor* clone() const; 00240 00241 /** 00242 * Returns used parameters 00243 */ 00244 const parameters& getParameters() const; 00245 00246 /** 00247 * Read the functor from the given ioHandler. 00248 * 00249 * The default implementation is to read just the parameters object. 00250 * 00251 * Since this virtual method needs to know the exact type of the 00252 * parameters to call the proper read method, it will just assume that the 00253 * current functor instance has a valid parameter set. If this is not 00254 * the case, you need to reimplement the read method to set first a dummy 00255 * parameter object. 00256 * 00257 * @param handler the ioHandler to be used 00258 * @param complete if true (the default) the enclosing begin/end will 00259 * be also written, otherwise only the data block will be written. 00260 * @return true if write was successful 00261 */ 00262 virtual bool read(ioHandler& handler,const bool complete=true); 00263 00264 00265 protected: 00266 00267 /** 00268 * Compute the second and up iterations of a probability map 00269 * using the given apriori probabilites per pixel. 00270 */ 00271 void computeMap(const image& img, 00272 channel& aPrioriDest) const; 00273 00274 }; 00275 } 00276 00277 #endif