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

ltiKullbackContrast.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 .......: ltiKullbackContrast.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 16.3.2001
00030  * revisions ..: $Id: ltiKullbackContrast.h,v 1.8 2006/02/08 11:21:18 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_KULLBACK_CONTRAST_H_
00034 #define _LTI_KULLBACK_CONTRAST_H_
00035 
00036 #include "ltiStatisticsFunctor.h"
00037 #include "ltiImage.h"
00038 #include "ltiGaussianPyramid.h"
00039 
00040 namespace lti {
00041   /**
00042    * Calculate the Kullback-Constrast for a channel, as described in:
00043    * Jagersand, Martin.  "Saliency Maps and Attention Selection in
00044    * Scale and Spatial Coordinates: An Information Theoretic
00045    * Approach", 5th Int. Conf. on Computer Vision, 1995, pp. 195-202
00046    *
00047    * The given channel will be analized at different resolutions
00048    * (given through the parameters).  The output vector contains the
00049    * constrast for each size, where the evaluated size corresponds to
00050    * 2^(vector index).
00051    *
00052    * Note that if one of the distributions contains a zero (p(x_i) = 0) and
00053    * q(x_i) != 0, the Kullback constrast will be infinite!
00054    *
00055    * With the parameter <code>useHistogram</code> an approximation for
00056    * the probability distribution of the intensity of a channel will
00057    * be done in form of a histogram.  Please note that this will option is
00058    * ignored when comparing vectors.
00059    */
00060   class kullbackContrast : public statisticsFunctor {
00061   public:
00062     /**
00063      * the parameters for the class kullbackContrast
00064      */
00065     class parameters : public statisticsFunctor::parameters {
00066     public:
00067       /**
00068        * default constructor
00069        */
00070       parameters();
00071 
00072       /**
00073        * copy constructor
00074        * @param other the parameters object to be copied
00075        */
00076       parameters(const parameters& other);
00077 
00078       /**
00079        * destructor
00080        */
00081       ~parameters();
00082 
00083       /**
00084        * returns name of this type
00085        */
00086       const char* getTypeName() const;
00087 
00088       /**
00089        * copy the contents of a parameters object
00090        * @param other the parameters object to be copied
00091        * @return a reference to this parameters object
00092        */
00093       parameters& copy(const parameters& other);
00094 
00095       /**
00096        * copy the contents of a parameters object
00097        * @param other the parameters object to be copied
00098        * @return a reference to this parameters object
00099        */
00100       parameters& operator=(const parameters& other);
00101 
00102       /**
00103        * returns a pointer to a clone of the parameters
00104        */
00105       virtual functor::parameters* clone() const;
00106 
00107       /**
00108        * write the parameters in the given ioHandler
00109        * @param handler the ioHandler to be used
00110        * @param complete if true (the default) the enclosing begin/end will
00111        *        be also written, otherwise only the data block will be written.
00112        * @return true if write was successful
00113        */
00114       virtual bool write(ioHandler& handler,const bool complete=true) const;
00115 
00116       /**
00117        * write the parameters in the given ioHandler
00118        * @param handler the ioHandler to be used
00119        * @param complete if true (the default) the enclosing begin/end will
00120        *        be also written, otherwise only the data block will be written.
00121        * @return true if write was successful
00122        */
00123       virtual bool read(ioHandler& handler,const bool complete=true);
00124 
00125 #     ifdef _LTI_MSC_6
00126       /**
00127        * this function is required by MSVC only, as a workaround for a
00128        * very awful bug, which exists since MSVC V.4.0, and still by
00129        * V.6.0 with all bugfixes (so called "service packs") remains
00130        * there...  This method is also public due to another bug, so please
00131        * NEVER EVER call this method directly: use read() instead
00132        */
00133       bool readMS(ioHandler& handler,const bool complete=true);
00134 
00135       /**
00136        * this function is required by MSVC only, as a workaround for a
00137        * very awful bug, which exists since MSVC V.4.0, and still by
00138        * V.6.0 with all bugfixes (so called "service packs") remains
00139        * there...  This method is also public due to another bug, so please
00140        * NEVER EVER call this method directly: use write() instead
00141        */
00142       bool writeMS(ioHandler& handler,const bool complete=true) const;
00143 #     endif
00144 
00145       // ------------------------------------------------
00146       // the parameters
00147       // ------------------------------------------------
00148 
00149       //TODO: comment the parameters of your functor
00150       // If you add more parameters manually, do not forget to do following:
00151       // 1. indicate in the default constructor the default values
00152       // 2. make sure that the copy member also copy your new parameters
00153       // 3. make sure that the read and write members also read and
00154       //    write your parameters
00155 
00156       /**
00157        * Number of resolutions to be evaluated (Default 7 => 128 pixel)
00158        */
00159       int resolutions;
00160 
00161       /**
00162        * if useGaussian is true, a gaussian filter will be used, with
00163        * the size and variance given in gaussianSize and gaussianVariance.
00164        * Otherwise a squareFilter will approximate the filter pyramid.
00165        * Default: true
00166        */
00167       bool useGaussian;
00168 
00169       /**
00170        * Size for the gaussian kernel used in the image diffusion
00171        * (Default: 5)
00172        */
00173       int gaussianSize;
00174 
00175       /**
00176        * Variance for the gaussian kernel used in the image diffusion.
00177        * (Default: 1.0)
00178        */
00179       double gaussianVariance;
00180 
00181       /**
00182        * if false, the channel contents will be directly used as a probability
00183        * distribution.  If true, a histogram of the channel will be generated
00184        * to approximate the probability distribution.  The number of bins can
00185        * be specified using the parameters histogramSize
00186        * (Default: false)
00187        */
00188       bool useHistogram;
00189 
00190       /**
00191        * indicates how many bins the histogram will have.
00192        * (Default: 256)
00193        */
00194       int histogramSize;
00195     };
00196 
00197     /**
00198      * default constructor
00199      */
00200     kullbackContrast();
00201 
00202     /**
00203      * copy constructor
00204      * @param other the object to be copied
00205      */
00206     kullbackContrast(const kullbackContrast& other);
00207 
00208     /**
00209      * destructor
00210      */
00211     virtual ~kullbackContrast();
00212 
00213     /**
00214      * returns the name of this type ("kullbackContrast")
00215      */
00216     virtual const char* getTypeName() const;
00217 
00218     /**
00219      * The Kullback contrast of the channel src will be calculated as the
00220      * Kullback contrast between two adjacent resolutions of the gaussian
00221      * pyramid for that channel, where the pixel value normalized with the sum
00222      * of all pixels will be considered as a probability p(x,y).  (for more
00223      * details see the paper:
00224      * Jagersand, Martin.  "Saliency Maps and Attention Selection in
00225      * Scale and Spatial Coordinates: An Information Theoretic  Approach",
00226      * 5th Int. Conf. on Computer Vision, 1995, pp. 195-202
00227      * operates on a copy of the given %parameters.
00228      *
00229      * @param src channel with the source data.
00230      * @param dest channel where the result will be left.  The i-th entry in
00231      *             the vector will contain the Kullback contrast for objects
00232      *             with a diameter of 2^i pixels.
00233      * @result a reference to the <code>dest</code>.
00234      */
00235     vector<float>& apply(const channel& src,vector<float>& dest) const;
00236 
00237     /**
00238      * The Kullback contrast of the channel src will be calculated as the
00239      * Kullback contrast between two adjacent resolutions of the gaussian
00240      * pyramid for that channel, where the pixel value normalized with the sum
00241      * of all pixels will be considered as a probability p(x,y).  (for more
00242      * details see the paper:
00243      * Jagersand, Martin.  "Saliency Maps and Attention Selection in
00244      * Scale and Spatial Coordinates: An Information Theoretic  Approach",
00245      * 5th Int. Conf. on Computer Vision, 1995, pp. 195-202
00246      * operates on a copy of the given %parameters.
00247      *
00248      * @param src channel with the source data.
00249      * @param dest channel where the result will be left.  The i-th entry in
00250      *             the vector will contain the Kullback contrast for objects
00251      *             with a diameter of 2^i pixels.
00252      * @param pyr the gaussian pyramid of the given channel
00253      * @param pyr2 the upsampled gaussian pyramid (pyr2.size() == pyr.size()-1)
00254      * @result a reference to the <code>dest</code>.
00255      */
00256     vector<float>& apply(const channel& src,
00257                                vector<float>& dest,
00258                                gaussianPyramid<channel>& pyr,
00259                                gaussianPyramid<channel>& pyr2) const;
00260 
00261 
00262     /**
00263      * calculates the Kullback contrast between q and p, defined as
00264      * \f[ K[Q,P] = \int_x p(x) \log \frac{p(x)}{q(x)} dx \f]
00265      *
00266      * operates on a copy of the given %parameters.  The input channels
00267      * do not need to be "normalized".  This will be done here, in an
00268      * efficient way.
00269      * @param q channel with the source data q(x).
00270      * @param p channel with the source data p(x).
00271      * @param dest channel where the result will be left.
00272      * @result a reference to the <code>dest</code>.
00273      */
00274     float& apply(const channel& q,
00275                  const channel& p,
00276                        float& dest) const;
00277 
00278     /*
00279      * calculates a channel where the local Kullback constrast is presented
00280      * using some local averaging.
00281      */
00282     //channel& apply(const channel& q,
00283     //               const channel& p,
00284     //                     channel& dest) const;
00285 
00286     /**
00287      * calculates the Kullback contrast between q and p, defined as
00288      * \f[ K[Q,P] = \int_x p(x) \log \frac{p(x)}{q(x)} dx \f]
00289      *
00290      * operates on a copy of the given %parameters.
00291      * @param q vector with the source data q(x).
00292      * @param p vector with the source data p(x).
00293      * @param dest vector<float> where the result will be left.
00294      * @result a reference to the <code>dest</code>.
00295      */
00296     float& apply(const vector<float>& q,
00297                  const vector<float>& p,
00298                        float& dest) const;
00299 
00300     /**
00301      * copy data of "other" functor.
00302      * @param other the functor to be copied
00303      * @return a reference to this functor object
00304      */
00305     kullbackContrast& copy(const kullbackContrast& other);
00306 
00307     /**
00308      * returns a pointer to a clone of this functor.
00309      */
00310     virtual functor* clone() const;
00311 
00312     /**
00313      * returns used parameters
00314      */
00315     const parameters& getParameters() const;
00316 
00317   protected:
00318     /**
00319      * make an histogram of the src channel in hist.  The number of bin
00320      * is the number of elements in hist.
00321      */
00322     void makeHistogram(const channel& src,vector<double>& hist) const;
00323 
00324   };
00325 }
00326 
00327 #endif

Generated on Sat Apr 10 15:25:43 2010 for LTI-Lib by Doxygen 1.6.1