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

ltiRansacEstimator.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 .......: ltiRansacEstimator.h
00027  * authors ....: Claudia Goenner
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 14.4.2004
00030  * revisions ..: $Id: ltiRansacEstimator.h,v 1.6 2006/02/08 11:43:34 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_RANSAC_ESTIMATOR_H_
00034 #define _LTI_RANSAC_ESTIMATOR_H_
00035 
00036 #include "ltiMonteCarloEstimator.h"
00037 
00038 namespace lti {
00039 
00040   /**
00041    * This class estimates a transform using the Ransac algorithm. The
00042    * Ransac algorithm maximizes the number of inliers. At each
00043    * iteration a subset of points/correspondences is drawn from which the
00044    * transform is computed.
00045    *
00046    * Theoretically the Ransac algorithm copes with up to 90% outliers. It is
00047    * advised though, to verify the estimated transform and repeat the
00048    * ransac estimation in case of a bad estimation. For the homography
00049    * estimators this may be performed by the homographyVerfication
00050    * (coming up soon).
00051    *
00052    */
00053   class ransacEstimator : public monteCarloEstimator {
00054   public:
00055     /**
00056      * The parameters for the class ransacEstimator
00057      */
00058     class parameters : public monteCarloEstimator::parameters {
00059     public:
00060       /**
00061        * Default constructor
00062        */
00063       parameters();
00064 
00065       /**
00066        * Copy constructor
00067        * @param other the parameters object to be copied
00068        */
00069       parameters(const parameters& other);
00070 
00071       /**
00072        * Destructor
00073        */
00074       ~parameters();
00075 
00076       /**
00077        * Returns name of this type
00078        */
00079       const char* getTypeName() const;
00080 
00081       /**
00082        * Copy the contents of a parameters object
00083        * @param other the parameters object to be copied
00084        * @return a reference to this parameters object
00085        */
00086       parameters& copy(const parameters& other);
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& operator=(const parameters& other);
00094 
00095 
00096       /**
00097        * Returns a pointer to a clone of the parameters
00098        */
00099       virtual functor::parameters* clone() const;
00100 
00101       /**
00102        * Write the parameters in the given ioHandler
00103        * @param handler the ioHandler to be used
00104        * @param complete if true (the default) the enclosing begin/end will
00105        *        be also written, otherwise only the data block will be written.
00106        * @return true if write was successful
00107        */
00108       virtual bool write(ioHandler& handler,const bool complete=true) const;
00109 
00110       /**
00111        * Read the parameters from the given ioHandler
00112        * @param handler the ioHandler to be used
00113        * @param complete if true (the default) the enclosing begin/end will
00114        *        be also written, otherwise only the data block will be written.
00115        * @return true if write was successful
00116        */
00117       virtual bool read(ioHandler& handler,const bool complete=true);
00118 
00119 #     ifdef _LTI_MSC_6
00120       /**
00121        * This function is required by MSVC only, as a workaround for a
00122        * very awful bug, which exists since MSVC V.4.0, and still by
00123        * V.6.0 with all bugfixes (so called "service packs") remains
00124        * there...  This method is also public due to another bug, so please
00125        * NEVER EVER call this method directly: use read() instead
00126        */
00127       bool readMS(ioHandler& handler,const bool complete=true);
00128 
00129       /**
00130        * This function is required by MSVC only, as a workaround for a
00131        * very awful bug, which exists since MSVC V.4.0, and still by
00132        * V.6.0 with all bugfixes (so called "service packs") remains
00133        * there...  This method is also public due to another bug, so please
00134        * NEVER EVER call this method directly: use write() instead
00135        */
00136       bool writeMS(ioHandler& handler,const bool complete=true) const;
00137 #     endif
00138 
00139       // ------------------------------------------------
00140       // the parameters
00141       // ------------------------------------------------
00142 
00143       /**
00144        * Adjust the degree of contamination after each successfull guess.
00145        * The contamination is only decreased and never increased.
00146        * This parameter effects the number of iterations performed.
00147        * The functor will always terminate after at most the maximum iterations
00148        * specified in the parameters, though.
00149        *
00150        * If adaptive contamination is on, the applies return true even if the
00151        * detected inliers suggest a contamination above the parametrized
00152        * contamination.
00153        *
00154        * Default: false.
00155        */
00156       bool adaptiveContamination;
00157 
00158       /**
00159        * The number of correspondences drawn at each trial to estimate the
00160        * transform. Literature advises to use the minimum number
00161        * correspondences that are required which is proved optimal under a
00162        * statistical context.
00163        *
00164        * Default: true.
00165        */
00166       int numCorrespondencesPerTrial;
00167 
00168       /**
00169        * If true the algorithm stops as soon as a transformation is found,
00170        * whose number of outliers is below the expected contamination. The
00171        * expected contamination is supplied as a parameter and not changed
00172        * adaptively.
00173        *
00174        * Default: true.
00175        */
00176       bool checkStop;
00177 
00178       /**
00179        * The expected degree of contamination.
00180        *
00181        * Default: .5
00182        */
00183       float contamination;
00184 
00185       /**
00186        * The number of trials in adaptive mode depends on the estimated
00187        * contamination and the confidence, under which the result is correct.
00188        *
00189        * Default: .99
00190        */
00191       float confidence;
00192 
00193       /**
00194        * If true the minimum required number of points/correspondences is
00195        * used no matter which value numCorrespondencesPerTrial has.
00196        *
00197        * Default: true.
00198        */
00199       bool useMinCorrespondences;
00200 
00201     };
00202 
00203     /**
00204      * Default constructor
00205      */
00206     ransacEstimator();
00207 
00208     /**
00209      * Construct a functor using the given parameters
00210      */
00211     ransacEstimator(const parameters& par);
00212 
00213     /**
00214      * Copy constructor
00215      * @param other the object to be copied
00216      */
00217     ransacEstimator(const ransacEstimator& other);
00218 
00219     /**
00220      * Destructor
00221      */
00222     virtual ~ransacEstimator();
00223 
00224     /**
00225      * Returns the name of this type ("ransacEstimator")
00226      */
00227     virtual const char* getTypeName() const;
00228 
00229     /**
00230      * Estimates a transform from the supplied point sets.
00231      *
00232      * All points of one point set give a matrix row, whereas all elements
00233      * of a specifec correspondence stand in a matrix column.
00234      *
00235      * @param src  std::vector<vector<dpoint> > with the point sets.
00236      * @param dest fvector the estimated transform.
00237      * @return true if apply successful or false otherwise.
00238      */
00239     virtual bool apply(const matrix<fpoint>& src,
00240                        fvector& dest) const;
00241 
00242     /**
00243      * Estimates a transform from the supplied point sets.
00244      *
00245      * All points of one point set give a matrix row, whereas all elements
00246      * of a specifec correspondence stand in a matrix column.
00247      *
00248      * @param src  std::vector<vector<dpoint> > with the point sets.
00249      * @param dest fvector the estimated transform.
00250      * @param error fvector containing the deviation of each point from the
00251      *              estimated transform. Usually this is the residual, also a
00252      *              if a squared residual is computed inside the transform
00253      *              estimator.
00254      * @return true if apply successful or false otherwise.
00255      */
00256     virtual bool apply(const matrix<fpoint>& src,
00257                        fvector& dest, fvector& error) const;
00258 
00259     /**
00260      * Estimates a transform from the supplied point sets.
00261      *
00262      * All points of one point set give a matrix row, whereas all elements
00263      * of a specifec correspondence stand in a matrix column.
00264      *
00265      * @param src  std::vector<vector<dpoint> > with the point sets.
00266      * @param dest dvector the estimated transform.
00267      * @return true if apply successful or false otherwise.
00268      */
00269     virtual bool apply(const matrix<dpoint>& src,
00270                        dvector& dest) const;
00271 
00272     /**
00273      * Estimates a transform from the supplied point sets.
00274      *
00275      * All points of one point set give a matrix row, whereas all elements
00276      * of a specifec correspondence stand in a matrix column.
00277      *
00278      * @param src  std::vector<vector<dpoint> > with the point sets.
00279      * @param dest dvector the estimated transform.
00280      * @param error fvector containing the deviation of each point from the
00281      *              estimated transform. Usually this is the residual, also a
00282      *              if a squared residual is computed inside the transform
00283      *              estimator.
00284      * @return true if apply successful or false otherwise.
00285      */
00286     virtual bool apply(const matrix<dpoint>& src,
00287                        dvector& dest, dvector& error) const;
00288 
00289     /**
00290      * Copy data of "other" functor.
00291      * @param other the functor to be copied
00292      * @return a reference to this functor object
00293      */
00294     ransacEstimator& copy(const ransacEstimator& other);
00295 
00296     /**
00297      * Alias for copy member
00298      * @param other the functor to be copied
00299      * @return a reference to this functor object
00300      */
00301     ransacEstimator& operator=(const ransacEstimator& other);
00302 
00303     /**
00304      * Returns a pointer to a clone of this functor.
00305      */
00306     virtual functor* clone() const;
00307 
00308     /**
00309      * Returns used parameters
00310      */
00311     const parameters& getParameters() const;
00312     
00313   };
00314 }
00315 
00316 #endif

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