LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiProbabilityMapBase.h

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 .......: ltiProbabilityMapBase.h
00027  * authors ....: Benjamin Winkler, Florian Bley
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 30.1.2001
00030  * revisions ..: $Id: ltiProbabilityMapBase.h,v 1.12 2006/09/05 10:26:09 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_PROBABILITY_MAP_BASE_H_
00034 #define _LTI_PROBABILITY_MAP_BASE_H_
00035 
00036 
00037 #include "ltiTransform.h"
00038 #include "ltiImage.h"
00039 #include "ltiHistogram.h"
00040 
00041 namespace lti {
00042   /**
00043    * base class for all probability map classes, e.g. using 2D or
00044    * 3D color histograms.
00045    */
00046   class probabilityMapBase : public transform {
00047   public:
00048     /**
00049      * the parameters for the class probabilityMapBase
00050      */
00051     class parameters : public transform::parameters {
00052     public:
00053       /**
00054        * default constructor
00055        */
00056       parameters();
00057 
00058       /**
00059        * copy constructor
00060        * @param other the parameters object to be copied
00061        */
00062       parameters(const parameters& other);
00063 
00064       /**
00065        * destructor
00066        */
00067       ~parameters();
00068 
00069       /**
00070        * returns name of this type
00071        */
00072       const char* getTypeName() const;
00073 
00074       /**
00075        * copy the contents of a parameters object
00076        * @param other the parameters object to be copied
00077        * @return a reference to this parameters object
00078        */
00079       parameters& copy(const parameters& other);
00080 
00081       /**
00082        * copy the contents of a parameters object, except the histograms.
00083        *
00084        * @param other the parameters object to be copied
00085        * @return a reference to this parameters object
00086        */
00087       parameters& copyAllButHistograms(const parameters& other);
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& operator=(const parameters& other);
00095 
00096       /**
00097        * write the parameters in the given ioHandler
00098        * @param handler the ioHandler to be used
00099        * @param complete if true (the default) the enclosing begin/end will
00100        *        be also written, otherwise only the data block will be written.
00101        * @return true if write was successful
00102        */
00103       virtual bool write(ioHandler& handler,const bool complete=true) const;
00104 
00105       /**
00106        * write the parameters in the given ioHandler
00107        * @param handler the ioHandler to be used
00108        * @param complete if true (the default) the enclosing begin/end will
00109        *        be also written, otherwise only the data block will be written.
00110        * @return true if write was successful
00111        */
00112       virtual bool read(ioHandler& handler,const bool complete=true);
00113 
00114 #     ifdef _LTI_MSC_6
00115       /**
00116        * this function is required by MSVC only, as a workaround for a
00117        * very awful bug, which exists since MSVC V.4.0, and still by
00118        * V.6.0 with all bugfixes (so called "service packs") remains
00119        * there...  This method is also public due to another bug, so please
00120        * NEVER EVER call this method directly: use read() instead
00121        */
00122       bool readMS(ioHandler& handler,const bool complete=true);
00123 
00124       /**
00125        * this function is required by MSVC only, as a workaround for a
00126        * very awful bug, which exists since MSVC V.4.0, and still by
00127        * V.6.0 with all bugfixes (so called "service packs") remains
00128        * there...  This method is also public due to another bug, so please
00129        * NEVER EVER call this method directly: use write() instead
00130        */
00131       bool writeMS(ioHandler& handler,const bool complete=true) const;
00132 #     endif
00133 
00134       // ------------------------------------------------
00135       // the parameters
00136       // ------------------------------------------------
00137 
00138       /**
00139        * overall object probability (default is 0.5)
00140        */
00141       float objectProbability;
00142 
00143       /**
00144        * set object color model.
00145        *
00146        * A copy of the object will be done.
00147        */
00148       void setObjectColorModel(const thistogram<double> &objModel);
00149 
00150       /**
00151        * returns a reference to the object color model
00152        */
00153       const thistogram<double> &getObjectColorModel() const;
00154 
00155       /**
00156        * check if the object color model is valid.
00157        *
00158        * Valid means that the model has already been set
00159        * (with setObjectColorModel) and that the dimensionality of the model
00160        * fits with the dimension which the derived class requires.
00161        *
00162        * @return true if valid, false otherwise.
00163        */
00164       virtual bool isObjectColorModelValid() const = 0;
00165 
00166       /**
00167        * set non-object color model
00168        *
00169        * A copy of the object will be done.
00170        */
00171       void setNonObjectColorModel(const thistogram<double> &nonObjModel);
00172 
00173       /**
00174        * returns a reference to the non-object color model
00175        */
00176       const thistogram<double> &getNonObjectColorModel() const;
00177 
00178       /**
00179        * check if the non-object color model is valid
00180        *
00181        * Valid means that the model has already been set
00182        * (with setObjectColorModel) and that the dimensionality of the model
00183        * fits with the dimension which the derived class requires.
00184        *
00185        * @return true if valid, false otherwise.
00186        */
00187       virtual bool isNonObjectColorModelValid() const = 0;
00188 
00189       /**
00190        * Number of Iterations.
00191        *
00192        * Default value: 1
00193        *
00194        * This member should be always greater than 1. If zero or negative
00195        * values are given, then 1 will be assumed.  At this time, the functor
00196        * requires BOTH models (object AND non-object) to compute more than
00197        * one iteration.
00198        *
00199        * The first iteration will always compute the probability map,
00200        * assuming that for all pixels in the color image the <em>a
00201        * priori</em> probability for it to be part of the object is given by
00202        * the <code>objectProbability</code>.
00203        *
00204        * Each following iteration will compute the <em>a priori</em> for each
00205        * pixel as some averaging of the probabilities in the neighbourhood of
00206        * pixel computed in the previous iteration.  The available averaging
00207        * operators are gaussian filters or square filters.  The size of the
00208        * neighbourhood will be specified by the <code>windowSize</code>
00209        * attribute.
00210        */
00211       int iterations;
00212 
00213       /**
00214        * If true, a gaussian averaging filter will be used.  If false, a
00215        * square filter will be used.
00216        *
00217        * Default value: false (use a square kernel)
00218        */
00219       bool gaussian;
00220 
00221       /**
00222        * Size for the gaussian kernel or the square kernel used to compute
00223        * the average probability to be used as <em>a priori</em> probability in
00224        * the next iteration.
00225        *
00226        * Default value: 5 (use a 5x5 kernel)
00227        */
00228       int windowSize;
00229 
00230       /**
00231        * In case the averaging operator is a gaussian kernel, this is the
00232        * variance to be used.
00233        *
00234        * Default value: -1 (meaning the lti::gaussKernel1D should compute a
00235        *                    default variance)
00236        */
00237       double variance;
00238 
00239     protected:
00240       /**
00241        * specify if the histograms are administrated by this class or not.
00242        */
00243       bool ownModels;
00244 
00245       /**
00246        * internal pointer to non-object color model
00247        */
00248       const thistogram<double>* nonObjectColorModel;
00249 
00250       /**
00251        * internal pointer to object color model
00252        */
00253       const thistogram<double>* objectColorModel;
00254 
00255     };
00256 
00257     /**
00258      * default constructor
00259      */
00260     probabilityMapBase();
00261 
00262     /**
00263      * copy constructor
00264      * @param other the object to be copied
00265      */
00266     probabilityMapBase(const probabilityMapBase& other);
00267 
00268     /**
00269      * destructor
00270      */
00271     virtual ~probabilityMapBase();
00272 
00273     /**
00274      * returns the name of this type ("probabilityMapBase")
00275      */
00276     virtual const char* getTypeName() const;
00277 
00278     /**
00279      * updateParameters was overloaded to avoid reloading the
00280      * histograms every time apply is called.
00281      */
00282     virtual bool updateParameters();
00283 
00284     /**
00285      * This method is similar to setParameters, but the histograms are
00286      * leaved untouched.  It assumes that some parameters were already set. 
00287      * Otherwise it will return false.
00288      *
00289      * This means, all attributes in the given histograms will be copied, 
00290      * except the histograms themselves.
00291      *
00292      * This is necessary in time critical situations, where some of the
00293      * attributes have to be modified except the probabilistic models, which
00294      * are large and require some time to be copied.
00295      */
00296     virtual bool 
00297     setParametersKeepingHistograms(const parameters &theParams);
00298 
00299     /**
00300      * copy data of "other" functor.
00301      * @param other the functor to be copied
00302      * @return a reference to this functor object
00303      */
00304     probabilityMapBase& copy(const probabilityMapBase& other);
00305 
00306     /**
00307      * copy data of "other" functor.
00308      * @param other the functor to be copied
00309      * @return a reference to this functor object
00310      */
00311     probabilityMapBase& operator=(const probabilityMapBase& other);
00312 
00313     /**
00314      * returns a pointer to a clone of this functor.
00315      */
00316     virtual functor* clone() const = 0;
00317 
00318     /**
00319      * returns used parameters
00320      */
00321     const parameters& getParameters() const;
00322 
00323     /**
00324      * Read the functor from the given ioHandler. 
00325      *
00326      * The default implementation is to read just the parameters object.
00327      *
00328      * Since this virtual method needs to know the exact type of the
00329      * parameters to call the proper read method, it will just assume that the
00330      * current functor instance has a valid parameter set.  If this is not
00331      * the case, you need to reimplement the read method to set first a dummy
00332      * parameter object.
00333      *
00334      * @param handler the ioHandler to be used
00335      * @param complete if true (the default) the enclosing begin/end will
00336      *        be also written, otherwise only the data block will be written.
00337      * @return true if write was successful
00338      */
00339     virtual bool read(ioHandler& handler,const bool complete=true)=0;
00340 
00341   protected:
00342 
00343     /**
00344      * generate probability histogram.
00345      *
00346      * This is automatically called in the setParameters method.
00347      *
00348      * The generate method initialize the probabilityHistogram method which
00349      * contain the pre-computations based on the bayes-theorem to compute
00350      * a probability of a pixel to be an object or not.
00351      */
00352     virtual bool generate();
00353 
00354     /**
00355      * generate probability histogram from one histogram.
00356      */
00357     virtual bool generate(const thistogram<double> &objectModel);
00358 
00359     /**
00360      * generate probability histogram from two histograms.
00361      */
00362     virtual bool generate(const thistogram<double> &objectModel,
00363                           const thistogram<double> &nonObjectModel);
00364 
00365     /**
00366      * probability histogram
00367      *
00368      * This histogram contains already the computations for the first iteration
00369      * of the color map.
00370      */
00371     thistogram<double> probabilityHistogram;
00372 
00373     /**
00374      * generate lookup table for faster histogram element access
00375      */
00376     void generateLookupTable(const ivector &dimensions);
00377 
00378     /**
00379      * element lookup table
00380      */
00381     matrix<ubyte> lookupTable;
00382   };
00383 }
00384 
00385 #endif

Generated on Sat Apr 10 15:26:00 2010 for LTI-Lib by Doxygen 1.6.1