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

ltiRobustEstimator.h

00001 /*
00002  * Copyright (C) 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-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiRobustEstimator.h
00027  * authors ....: Claudia Goenner
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 6.4.2004
00030  * revisions ..: $Id: ltiRobustEstimator.h,v 1.7 2006/02/08 11:46:46 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_ROBUST_ESTIMATOR_H_
00034 #define _LTI_ROBUST_ESTIMATOR_H_
00035 
00036 #include "ltiFunctor.h"
00037 #include "ltiMatrix.h"
00038 #include "ltiPointSetNormalization.h"
00039 #include "ltiPointSetNormalizationType.h"
00040 
00041 namespace lti {
00042 
00043   /**
00044    * A parent class for estimating a transform from sets of points in a robust
00045    * manner. This is archived be a Monte Carlo estimator for outlier removal
00046    * or iterative refinement of the transform to reduce the effects of noisy
00047    * input data (comming up soon).
00048    *
00049    * The Monte Carlo estimators work for any transformation estimation
00050    * algorithms whereas iterative refinenment will be defined for least
00051    * squares estimators only.
00052    *
00053    * @see lti::monteCarloEstimator, lti::ransacEstimator,
00054    * lti::transformEstimator
00055    */
00056   class robustEstimator : public functor {
00057   public:
00058     /**
00059      * The parameters for the class robustEstimator
00060      */
00061     class parameters : public functor::parameters {
00062 
00063       //some protected attributes must be accessed by the parent class
00064       friend class robustEstimator;
00065 
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       /**
00104        * Returns a pointer to a clone of the parameters
00105        */
00106       virtual functor::parameters* clone() const;
00107 
00108       /**
00109        * Write the parameters in the given ioHandler
00110        * @param handler the ioHandler to be used
00111        * @param complete if true (the default) the enclosing begin/end will
00112        *        be also written, otherwise only the data block will be written.
00113        * @return true if write was successful
00114        */
00115       virtual bool write(ioHandler& handler,const bool complete=true) const;
00116 
00117       /**
00118        * Read the parameters from the given ioHandler
00119        * @param handler the ioHandler to be used
00120        * @param complete if true (the default) the enclosing begin/end will
00121        *        be also written, otherwise only the data block will be written.
00122        * @return true if write was successful
00123        */
00124       virtual bool read(ioHandler& handler,const bool complete=true);
00125 
00126 #     ifdef _LTI_MSC_6
00127       /**
00128        * This function is required by MSVC only, as a workaround for a
00129        * very awful bug, which exists since MSVC V.4.0, and still by
00130        * V.6.0 with all bugfixes (so called "service packs") remains
00131        * there...  This method is also public due to another bug, so please
00132        * NEVER EVER call this method directly: use read() instead
00133        */
00134       bool readMS(ioHandler& handler,const bool complete=true);
00135 
00136       /**
00137        * This function is required by MSVC only, as a workaround for a
00138        * very awful bug, which exists since MSVC V.4.0, and still by
00139        * V.6.0 with all bugfixes (so called "service packs") remains
00140        * there...  This method is also public due to another bug, so please
00141        * NEVER EVER call this method directly: use write() instead
00142        */
00143       bool writeMS(ioHandler& handler,const bool complete=true) const;
00144 #     endif
00145 
00146       // ------------------------------------------------
00147       // the parameters
00148       // ------------------------------------------------
00149 
00150       /**
00151        * The number of iterations that are performed.
00152        *
00153        * Default: 50.
00154        */
00155       int numIterations;
00156 
00157       /**
00158        * Sets a new normalization method.
00159        * @param name the normalization method to be used.
00160        */
00161       void setNormalization(ePointSetNormalizationType name);
00162 
00163       /**
00164        * Sets a new normalization method. A copy of the functor will be
00165        * done (so it is useless to change the parameters of the given
00166        * functor instance, because the internal functor will never notice
00167        * the changes done to its "parent").
00168        * @param method the normalization method to be used.
00169        */
00170       void setNormalization(const pointSetNormalization& method);
00171 
00172       /**
00173        * Is a normalization method allocated ?
00174        * @return true is a normalization method is allocated
00175        * and false otherwise.
00176        */
00177       bool existsNormalization() const;
00178 
00179       /**
00180        * Gets the normalization method. If no method is allocated
00181        * an exception is thrown.
00182        */
00183       const pointSetNormalization& getNormalization() const;
00184 
00185     protected:
00186  
00187       /**
00188        * The method used to normalize the data.
00189        *
00190        * Default: homography8Dof. Caution: May change in the near future.
00191        */
00192       pointSetNormalization *normalization;
00193 
00194     };
00195 
00196     /**
00197      * Default constructor
00198      */
00199     robustEstimator();
00200 
00201     /**
00202      * Construct a functor using the given parameters
00203      */
00204     robustEstimator(const parameters& par);
00205 
00206     /**
00207      * Copy constructor
00208      * @param other the object to be copied
00209      */
00210     robustEstimator(const robustEstimator& other);
00211 
00212     /**
00213      * Destructor
00214      */
00215     virtual ~robustEstimator();
00216 
00217     /**
00218      * Returns the name of this type ("robustEstimator")
00219      */
00220     virtual const char* getTypeName() const;
00221 
00222     /**
00223      * Estimates a transform from the supplied point sets.
00224      *
00225      * All points of one point set give a matrix row, whereas all elements
00226      * of a specifec correspondence stand in a matrix column.
00227      *
00228      * @param src  matrix<fpoint> with the point sets.
00229      * @param dest fector the estimated transform.
00230      * @return true if apply successful or false otherwise.
00231      */
00232     virtual bool apply(const matrix<fpoint>& src,
00233                        fvector& dest) const = 0;
00234 
00235     /**
00236      * Estimates a transform from the supplied point sets.
00237      *
00238      * All points of one point set give a matrix row, whereas all elements
00239      * of a specifec correspondence stand in a matrix column.
00240      *
00241      * @param src  matrix<fpoint> with the point sets.
00242      * @param dest fvector the estimated transform.
00243      * @param error fvector containing the deviation of each point from the
00244      *              estimated transform. Usually this is the residual, also a
00245      *              if a squared residual is computed inside the transform
00246      *              estimator.
00247      * @return true if apply successful or false otherwise.
00248      */
00249     virtual bool apply(const matrix<fpoint>& src,
00250                        fvector& dest, fvector& error) const = 0;
00251 
00252     /**
00253      * Estimates a transform from the supplied point sets.
00254      *
00255      * All points of one point set give a matrix row, whereas all elements
00256      * of a specifec correspondence stand in a matrix column.
00257      *
00258      * @param src  matrix<dpoint> with the point sets.
00259      * @param dest dvector the estimated transform.
00260      * @return true if apply successful or false otherwise.
00261      */
00262     virtual bool apply(const matrix<dpoint>& src,
00263                        dvector& dest) const = 0;
00264 
00265     /**
00266      * Estimates a transform from the supplied point sets.
00267      *
00268      * All points of one point set give a matrix row, whereas all elements
00269      * of a specifec correspondence stand in a matrix column.
00270      *
00271      * @param src  matrix<dpoint> with the point sets.
00272      * @param dest dvector the estimated transform.
00273      * @param error fvector containing the deviation of each point from the
00274      *              estimated transform. Usually this is the residual, also a
00275      *              if a squared residual is computed inside the transform
00276      *              estimator.
00277      * @return true if apply successful or false otherwise.
00278      */
00279     virtual bool apply(const matrix<dpoint>& src,
00280                        dvector& dest, dvector& error) const = 0;
00281 
00282     /**
00283      * Copy data of "other" functor.
00284      * @param other the functor to be copied
00285      * @return a reference to this functor object
00286      */
00287     robustEstimator& copy(const robustEstimator& other);
00288 
00289     /**
00290      * Alias for copy member
00291      * @param other the functor to be copied
00292      * @return a reference to this functor object
00293      */
00294     robustEstimator& operator=(const robustEstimator& other);
00295 
00296     /**
00297      * Returns a pointer to a clone of this functor.
00298      */
00299     virtual functor* clone() const = 0;
00300 
00301     /**
00302      * Returns used parameters
00303      */
00304     const parameters& getParameters() const;
00305 
00306     /**
00307      * Set the paramters of the transform estimator used internally.
00308      * @param theParams the new normalization parameters, which will
00309      *                  be copied.
00310      * @return true on success and false otherwise, e.g. if the internal
00311      *         normalization method and the given parameters do not match.
00312      */
00313     virtual bool 
00314       setParameters(const pointSetNormalization::parameters& theParams);
00315 
00316     /**
00317      * Set the paramters of the robust estimator.
00318      * @param theParams the new parameters, which will be copied.
00319      * @return true on success and false otherwise.
00320      */
00321     bool setParameters(const parameters& theParams);
00322 
00323   protected:
00324     /**
00325      * Returns used parameters.
00326      */
00327     parameters& getWritableParameters();
00328 
00329   };
00330 }
00331 
00332 #endif

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