latest version v1.9 - last update 10 Apr 2010 |
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 .......: ltiMonteCarloEstimator.h 00027 * authors ....: Claudia Goenner 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 6.4.2004 00030 * revisions ..: $Id: ltiMonteCarloEstimator.h,v 1.3 2006/02/07 19:20:12 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_MONTE_CARLO_ESTIMATOR_H_ 00034 #define _LTI_MONTE_CARLO_ESTIMATOR_H_ 00035 00036 #include "ltiRobustEstimator.h" 00037 #include "ltiTransformEstimator.h" 00038 #include "ltiTransformEstimatorType.h" 00039 00040 namespace lti { 00041 00042 /** 00043 * A parent class for estimating a transform from point sets while 00044 * detecting and discarding outliers. To archive this a random set of 00045 * samples is drawn from the input data to estimate their transform. Common 00046 * Monte Carlo estimators are e.g. RANSAC and least median of squares 00047 * algorithm. 00048 * 00049 * @see lti::ransacEstimator, lti::transformEstimator 00050 */ 00051 class monteCarloEstimator : public robustEstimator { 00052 public: 00053 /** 00054 * The parameters for the class monteCarloEstimator 00055 */ 00056 class parameters : public robustEstimator::parameters { 00057 00058 //some protected attributes must be accessed by the parent class 00059 friend class monteCarloEstimator; 00060 00061 public: 00062 /** 00063 * Default constructor 00064 */ 00065 parameters(); 00066 00067 /** 00068 * Copy constructor 00069 * @param other the parameters object to be copied 00070 */ 00071 parameters(const parameters& other); 00072 00073 /** 00074 * Destructor 00075 */ 00076 ~parameters(); 00077 00078 /** 00079 * Returns name of this type 00080 */ 00081 const char* getTypeName() const; 00082 00083 /** 00084 * Copy the contents of a parameters object 00085 * @param other the parameters object to be copied 00086 * @return a reference to this parameters object 00087 */ 00088 parameters& copy(const parameters& other); 00089 00090 /** 00091 * Copy the contents of a parameters object 00092 * @param other the parameters object to be copied 00093 * @return a reference to this parameters object 00094 */ 00095 parameters& operator=(const parameters& other); 00096 00097 00098 /** 00099 * Returns a pointer to a clone of the parameters 00100 */ 00101 virtual functor::parameters* clone() const; 00102 00103 /** 00104 * Write the parameters in the given ioHandler 00105 * @param handler the ioHandler to be used 00106 * @param complete if true (the default) the enclosing begin/end will 00107 * be also written, otherwise only the data block will be written. 00108 * @return true if write was successful 00109 */ 00110 virtual bool write(ioHandler& handler,const bool complete=true) const; 00111 00112 /** 00113 * Read the parameters from the given ioHandler 00114 * @param handler the ioHandler to be used 00115 * @param complete if true (the default) the enclosing begin/end will 00116 * be also written, otherwise only the data block will be written. 00117 * @return true if write was successful 00118 */ 00119 virtual bool read(ioHandler& handler,const bool complete=true); 00120 00121 # ifdef _LTI_MSC_6 00122 /** 00123 * This function is required by MSVC only, as a workaround for a 00124 * very awful bug, which exists since MSVC V.4.0, and still by 00125 * V.6.0 with all bugfixes (so called "service packs") remains 00126 * there... This method is also public due to another bug, so please 00127 * NEVER EVER call this method directly: use read() instead 00128 */ 00129 bool readMS(ioHandler& handler,const bool complete=true); 00130 00131 /** 00132 * This function is required by MSVC only, as a workaround for a 00133 * very awful bug, which exists since MSVC V.4.0, and still by 00134 * V.6.0 with all bugfixes (so called "service packs") remains 00135 * there... This method is also public due to another bug, so please 00136 * NEVER EVER call this method directly: use write() instead 00137 */ 00138 bool writeMS(ioHandler& handler,const bool complete=true) const; 00139 # endif 00140 00141 // ------------------------------------------------ 00142 // the parameters 00143 // ------------------------------------------------ 00144 00145 /** 00146 * The maximum error for a single correspondence or the averaged 00147 * size of the residual. Depending on the parameter settings the 00148 * monteCarloEstimator normalizes the correspondences. This maximum error 00149 * is not adjusted to the scaled data automatically. Thus supplying a 00150 * meaningful value is left to the user. 00151 * 00152 * Default: .8. 00153 */ 00154 double maxError; 00155 00156 /** 00157 * Sets a new estimated transform. 00158 * @param name the transform to be estimated. 00159 */ 00160 void setTransform(eTransformEstimatorType name); 00161 00162 /** 00163 * Sets a new estimated transform. A copy of the functor will be 00164 * done (so it is useless to change the parameters of the given 00165 * functor instance, because the internal functor will never notice 00166 * the changes done to its "parent"). 00167 * @param estimator the transform to be estimated. 00168 */ 00169 void setTransform(const transformEstimator& estimator); 00170 00171 /** 00172 * Is a transform estimator allocated ? 00173 * @return true is a transform estimator is allocated 00174 * and false otherwise. 00175 */ 00176 bool existsTransform() const; 00177 00178 /** 00179 * Gets the transform to be estimated. If no estimator is allocated 00180 * an exception is thrown. 00181 */ 00182 const transformEstimator& getTransform() const; 00183 00184 protected: 00185 /** 00186 * The transform to be estimated. 00187 * 00188 * Default: homography8Dof. Caution: May change in the near future. 00189 */ 00190 transformEstimator *transform; 00191 }; 00192 00193 /** 00194 * Default constructor 00195 */ 00196 monteCarloEstimator(); 00197 00198 /** 00199 * Construct a functor using the given parameters 00200 */ 00201 monteCarloEstimator(const parameters& par); 00202 00203 /** 00204 * Copy constructor 00205 * @param other the object to be copied 00206 */ 00207 monteCarloEstimator(const monteCarloEstimator& other); 00208 00209 /** 00210 * Destructor 00211 */ 00212 virtual ~monteCarloEstimator(); 00213 00214 /** 00215 * Returns the name of this type ("monteCarloEstimator") 00216 */ 00217 virtual const char* getTypeName() const; 00218 00219 /** 00220 * Estimates a transform from the supplied point sets. 00221 * 00222 * All points of one point set give a matrix row, whereas all elements 00223 * of a specifec correspondence stand in a matrix column. 00224 * 00225 * @param src matrix<fpoint> with the point sets. 00226 * @param dest fector the estimated transform. 00227 * @return true if apply successful or false otherwise. 00228 */ 00229 virtual bool apply(const matrix<fpoint>& src, 00230 fvector& dest) const = 0; 00231 00232 /** 00233 * Estimates a transform from the supplied point sets. 00234 * 00235 * All points of one point set give a matrix row, whereas all elements 00236 * of a specifec correspondence stand in a matrix column. 00237 * 00238 * @param src matrix<fpoint> with the point sets. 00239 * @param dest fvector the estimated transform. 00240 * @param error fvector containing the deviation of each point from the 00241 * estimated transform. Usually this is the residual, also a 00242 * if a squared residual is computed inside the transform 00243 * estimator. 00244 * @return true if apply successful or false otherwise. 00245 */ 00246 virtual bool apply(const matrix<fpoint>& src, 00247 fvector& dest, fvector& error) const = 0; 00248 00249 /** 00250 * Estimates a transform from the supplied point sets. 00251 * 00252 * All points of one point set give a matrix row, whereas all elements 00253 * of a specifec correspondence stand in a matrix column. 00254 * 00255 * @param src matrix<dpoint> with the point sets. 00256 * @param dest dvector the estimated transform. 00257 * @return true if apply successful or false otherwise. 00258 */ 00259 virtual bool apply(const matrix<dpoint>& src, 00260 dvector& dest) const = 0; 00261 00262 /** 00263 * Estimates a transform from the supplied point sets. 00264 * 00265 * All points of one point set give a matrix row, whereas all elements 00266 * of a specifec correspondence stand in a matrix column. 00267 * 00268 * @param src matrix<dpoint> with the point sets. 00269 * @param dest dvector the estimated transform. 00270 * @param error fvector containing the deviation of each point from the 00271 * estimated transform. Usually this is the residual, also a 00272 * if a squared residual is computed inside the transform 00273 * estimator. 00274 * @return true if apply successful or false otherwise. 00275 */ 00276 virtual bool apply(const matrix<dpoint>& src, 00277 dvector& dest, dvector& error) const = 0; 00278 00279 /** 00280 * Copy data of "other" functor. 00281 * @param other the functor to be copied 00282 * @return a reference to this functor object 00283 */ 00284 monteCarloEstimator& copy(const monteCarloEstimator& other); 00285 00286 /** 00287 * Alias for copy member 00288 * @param other the functor to be copied 00289 * @return a reference to this functor object 00290 */ 00291 monteCarloEstimator& operator=(const monteCarloEstimator& other); 00292 00293 /** 00294 * Returns a pointer to a clone of this functor. 00295 */ 00296 virtual functor* clone() const = 0; 00297 00298 /** 00299 * Returns used parameters 00300 */ 00301 const parameters& getParameters() const; 00302 00303 /** 00304 * Set the paramters of the transform estimator used internally. 00305 * @param theParams the new transform estimator parameters, which will 00306 * be copied. 00307 * @return true on success and false otherwise, e.g. if the internal 00308 * transform estimator and the given parameters do not match. 00309 */ 00310 virtual bool 00311 setParameters(const transformEstimator::parameters& theParams); 00312 00313 /** 00314 * Set the paramters of the transform estimator used internally. 00315 * @param theParams the new normalization parameters, which will 00316 * be copied. 00317 * @return true on success and false otherwise, e.g. if the internal 00318 * normalization method and the given parameters do not match. 00319 */ 00320 virtual bool 00321 setParameters(const pointSetNormalization::parameters& theParams); 00322 00323 /** 00324 * Set the paramters of the Monte Carlo estimator. 00325 * @param theParams the new parameters, which will be copied. 00326 * @return true on success and false otherwise. 00327 */ 00328 bool setParameters(const parameters& theParams); 00329 00330 protected: 00331 /** 00332 * Returns used parameters. 00333 */ 00334 parameters& getWritableParameters(); 00335 00336 }; 00337 } 00338 00339 #endif