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

ltiPdmGenerator.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  * project ....: LTI Digital Image/Signal Processing Library
00025  * file .......: ltiPdmGenerator.h
00026  * authors ....: Benjamin Winkler
00027  * organization: LTI, RWTH Aachen
00028  * creation ...: 26.4.2001
00029  * revisions ..: $Id: ltiPdmGenerator.h,v 1.9 2006/09/05 10:25:10 ltilib Exp $
00030  */
00031 
00032 #ifndef _LTI_PDM_GENERATOR_H_
00033 #define _LTI_PDM_GENERATOR_H_
00034 
00035 
00036 #include "ltiActiveShapeModel.h"
00037 #include "ltiFunctor.h"
00038 #include "ltiEigenSystem.h"
00039 #include "ltiSTLIoInterface.h"
00040 
00041 
00042 namespace lti {
00043   /**
00044    * This class creates a pointDistributionModel (PDM) given a set of shapes
00045    * of type pointDistributionModel::shape.
00046    *
00047    * All shapes must have an equal number of points. These are ordered and
00048    * should ideally have a fixed correspondence across different shapes.
00049    *
00050    *
00051    */
00052   class pdmGenerator : public functor {
00053   public:
00054     /**
00055      * the parameters for the class pdmGenerator
00056      */
00057     class parameters : public functor::parameters {
00058     public:
00059       /**
00060        * default constructor
00061        */
00062       parameters();
00063 
00064       /**
00065        * copy constructor
00066        * @param other the parameters object to be copied
00067        */
00068       parameters(const parameters& other);
00069 
00070       /**
00071        * destructor
00072        */
00073       ~parameters();
00074 
00075       /**
00076        * returns name of this type
00077        */
00078       const char* getTypeName() const;
00079 
00080       /**
00081        * copy the contents of a parameters object
00082        * @param other the parameters object to be copied
00083        * @return a reference to this parameters object
00084        */
00085       parameters& copy(const parameters& other);
00086 
00087       /**
00088        * copy the contents of a parameters object
00089        * @param other the parameters object to be copied
00090        * @return a reference to this parameters object
00091        */
00092       parameters& operator=(const parameters& other);
00093 
00094 
00095       /**
00096        * returns a pointer to a clone of the parameters
00097        */
00098       virtual functor::parameters* clone() const;
00099 
00100       /**
00101        * write the parameters in the given ioHandler
00102        * @param handler the ioHandler to be used
00103        * @param complete if true (the default) the enclosing begin/end will
00104        *        be also written, otherwise only the data block will be written.
00105        * @return true if write was successful
00106        */
00107       virtual bool write(ioHandler& handler,const bool complete=true) const;
00108 
00109       /**
00110        * write the parameters in the given ioHandler
00111        * @param handler the ioHandler to be used
00112        * @param complete if true (the default) the enclosing begin/end will
00113        *        be also written, otherwise only the data block will be written.
00114        * @return true if write was successful
00115        */
00116       virtual bool read(ioHandler& handler,const bool complete=true);
00117 
00118 #     ifdef _LTI_MSC_6
00119       /**
00120        * this function is required by MSVC only, as a workaround for a
00121        * very awful bug, which exists since MSVC V.4.0, and still by
00122        * V.6.0 with all bugfixes (so called "service packs") remains
00123        * there...  This method is also public due to another bug, so please
00124        * NEVER EVER call this method directly: use read() instead
00125        */
00126       bool readMS(ioHandler& handler,const bool complete=true);
00127 
00128       /**
00129        * this function is required by MSVC only, as a workaround for a
00130        * very awful bug, which exists since MSVC V.4.0, and still by
00131        * V.6.0 with all bugfixes (so called "service packs") remains
00132        * there...  This method is also public due to another bug, so please
00133        * NEVER EVER call this method directly: use write() instead
00134        */
00135       bool writeMS(ioHandler& handler,const bool complete=true) const;
00136 #     endif
00137 
00138       // ------------------------------------------------
00139       // the parameters
00140       // ------------------------------------------------
00141 
00142       //TODO: comment the parameters of your functor
00143       // If you add more parameters manually, do not forget to do following:
00144       // 1. indicate in the default constructor the default values
00145       // 2. make sure that the copy member also copy your new parameters
00146       // 3. make sure that the read and write members also read and
00147       //    write your parameters
00148 
00149       /**
00150        * This %parameter is an upper limit to the number of eigenvectors to consider.
00151        *
00152        * Eigenvectors are ordered by magnitude of eigenvalue, so that the ones
00153        * with high eigenvalues are chosen first. All others are discarded.
00154        *
00155        * Only the first 2*maxNumberOfWeights eigenVectors are taken into account
00156        * from a total of 2*N, where N is the number of points in one shape.
00157        * Reasonable values lie between 0 and N.
00158        *
00159        * If set to 0 (default), all eigenVectors will be used.
00160        */
00161       int maxNumberOfWeights;
00162 
00163       /**
00164        * This %parameter is a lower limit to the number of eigenvectors to consider.
00165        *
00166        * At least the first K eigenVectors are taken into account, for which holds:
00167        * (eigenValue[0] + ... + eigenValue[K-1]) / sum(eigenValue) >= maxRelativeWeights
00168        * reasonable values range from 0.0 (none) to 1.0 (all).
00169        */
00170       float maxRelativeWeights;
00171 
00172     };
00173 
00174 
00175     /**
00176      * default constructor
00177      */
00178     pdmGenerator();
00179 
00180     /**
00181      * copy constructor
00182      * @param other the object to be copied
00183      */
00184     pdmGenerator(const pdmGenerator& other);
00185 
00186     /**
00187      * destructor
00188      */
00189     virtual ~pdmGenerator();
00190 
00191     /**
00192      * returns the name of this type ("pdmGenerator")
00193      */
00194     virtual const char* getTypeName() const;
00195 
00196     /**
00197      * copy data of "other" functor.
00198      * @param other the functor to be copied
00199      * @return a reference to this functor object
00200      */
00201     pdmGenerator& copy(const pdmGenerator& other);
00202 
00203     /**
00204      * returns a pointer to a clone of this functor.
00205      */
00206     virtual functor* clone() const;
00207 
00208     /**
00209      * returns used parameters
00210      */
00211     const parameters& getParameters() const;
00212 
00213     /** @name Training shape set
00214      *  These members are for managing the training shape set.
00215      */
00216       //@{
00217 
00218       /**
00219        * clear all considered shapes
00220        */
00221       void clear();
00222 
00223       /**
00224        * take shape into consideration
00225        */
00226       void consider(const pointDistributionModel::shape &theShape);
00227 
00228       /**
00229        * take list of shapes into consideration
00230        */
00231       void consider(const std::list<pointDistributionModel::shape> &theShapes);
00232 
00233       /**
00234        * return number of shapes considered so far (not the number of points!).
00235        */
00236       int getN() const;
00237 
00238       //@}
00239 
00240     /**
00241      * generate pointDistributionModel for the given dimension
00242      * @return a pointDistributionModel
00243      */
00244     pointDistributionModel apply();
00245 
00246 
00247   private:
00248 
00249     /**
00250      * generate model
00251      */
00252     void generate(pointDistributionModel &theModel);
00253 
00254     /**
00255      * calculate center
00256      */
00257 //    tpoint<float> calculateShapeCenter(const pointDistributionModel::shape &theShape) const;
00258 
00259     /**
00260      * calculate size
00261      */
00262 //    float calculateShapeSize(const pointDistributionModel::shape &theShape) const;
00263 
00264     /**
00265      * normalize shape (i.e. move to (0,0), scale to 1.0)
00266      */
00267     void normalizeShape(pointDistributionModel::shape &theShape) const;
00268 
00269     /**
00270      * - align all shapes to cog=(0,0), meanDistance=1.0
00271      * - create mean shape
00272      * - align all shapes iteratively to the mean shape
00273      * @return the mean shape
00274      */
00275     pointDistributionModel::shape alignShapes();
00276 
00277     /**
00278      * create mean shape
00279      */
00280     pointDistributionModel::shape createMeanShape() const;
00281 
00282     /**
00283      * sum of outerproducts of shape-vectors divided by number of shapes
00284      */
00285     matrix<double> calculateCovarianceMatrix(const pointDistributionModel::shape &meanShape) const;
00286 
00287     /**
00288      * create eigenmatrix and vector of eigenvalues
00289      */
00290     void createEigenSystem(const matrix<double> &covarMatrix,
00291                            matrix<double> &eigenVectorMatrix,
00292                            vector<double> &eigenValues) const;
00293 
00294     /**
00295      * create shape vector (x1, y1, x2, y2, ...)
00296      */
00297     vector<double> buildVector(const pointDistributionModel::shape &src) const;
00298 
00299 
00300     /**
00301      * list of considered shapes
00302      */
00303     std::list<pointDistributionModel::shape> shapes;
00304 
00305     /**
00306      * needed to align the given shapes
00307      */
00308     activeShapeModel theASM;
00309 
00310     /**
00311      * shape size
00312      */
00313     int shapeSize;
00314   };
00315 }
00316 
00317 #endif

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