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

ltiTransformEstimator.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 .......: ltiTransformEstimator.h
00027  * authors ....: Claudia Goenner
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 25.3.2004
00030  * revisions ..: $Id: ltiTransformEstimator.h,v 1.10 2006/02/08 11:57:32 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_TRANSFORM_ESTIMATOR_H_
00034 #define _LTI_TRANSFORM_ESTIMATOR_H_
00035 
00036 
00037 #include "ltiFunctor.h"
00038 #include "ltiPoint.h"
00039 #include "ltiMatrix.h"
00040 
00041 namespace lti {
00042   /**
00043    * A parent class for estimating a transform from sets of points.
00044    *
00045    * For automtic outlier detection please use one of the
00046    * Monte Carlo estimators, which call a transform estimator in their main
00047    * loop. The Monte Carlo estimators perform data normalization on request,
00048    * whereas this class does not.
00049    *
00050    * If you derive a class please remember to support the paramter for
00051    * returning a squared error measure (e.g. squared residual) instead of
00052    * the error (e.g. residual), and thus spare taking the square root.
00053    *
00054    * @see  lti::homography8DOFEstimator, lti::homography9DOFEstimator,
00055    * lti::fMatrixEstimator, lti::monteCarloEstimator
00056    *
00057    * Also planned: 
00058    * - estimating a homography together with a radial distortion
00059    */
00060   class transformEstimator : public functor {
00061   public:
00062     /**
00063      * The parameters for the class transformEstimator
00064      */
00065     class parameters : public functor::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       /**
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        * For runtime efficiency a squared error (e.g. elementwise squared
00152        * residual) may be computed, which spares taking the square root.
00153        *
00154        * Default: false.
00155        */
00156       bool computeSqError;
00157     };
00158 
00159     /**
00160      * Default constructor
00161      */
00162     transformEstimator();
00163 
00164     /**
00165      * Construct a functor using the given parameters
00166      */
00167     transformEstimator(const parameters& par);
00168 
00169     /**
00170      * Copy constructor
00171      * @param other the object to be copied
00172      */
00173     transformEstimator(const transformEstimator& other);
00174 
00175     /**
00176      * Destructor
00177      */
00178     virtual ~transformEstimator();
00179 
00180     /**
00181      * Returns the name of this type ("transformEstimator")
00182      */
00183     virtual const char* getTypeName() const;
00184 
00185     /**
00186      * Estimates a transform from the supplied point sets, where all
00187      * points are considered. Please implement efficient code using
00188      * iterators here. Not all robust estimators use a random sampling
00189      * approach. Some estimators consider all input points and weight them
00190      * according to their deviation from the transform computed at the prior
00191      * iteration.
00192      *
00193      * All points of one point set give a matrix row, whereas all elements
00194      * of a specifec correspondence stand in a matrix column.
00195      *
00196      * @param src  matrix<ipoint> with the point sets. All points of the same
00197      *    image stand in a row. The correspondences in another image stand in
00198      *    the according columns.
00199      * @param dest fvector the estimated transform.
00200      * @return true if the transform could be estimated and false otherwise.
00201      */
00202     virtual bool apply(const matrix<ipoint>& src,
00203                        fvector& dest) const = 0;
00204 
00205     /**
00206      * Estimates a transform from the supplied point sets, where all
00207      * points are considered. Usually this method calls the apply without
00208      * the residual first, and then computes the residual.
00209      * @param src  matrix<ipoint> with the point sets. All points of the same
00210      *             image stand in a row. The correspondences in another image
00211      *             stand in the according columns.  All points of one point
00212      *             set give a matrix row, whereas all elements of a specific
00213      *             correspondence stand in a matrix column.
00214      * @param dest fvector the estimated transform.
00215      * @param error fvector containing the deviation of each point from the
00216      *              estimated transform. Usually this is the residual or
00217      *              elementwise squared residual.
00218      * @return true if the transform could be estimated and false otherwise.
00219      */
00220     virtual bool apply(const matrix<ipoint>& src,
00221                        fvector& dest, fvector& error) const = 0;
00222 
00223     /**
00224      * Estimates a transform from the supplied point sets, whereby only
00225      * the points specified in the index vector are considered. This method
00226      * is used by robost estimators using a monte carlo approach.
00227      *
00228      * All points of one point set give a matrix row, whereas all elements
00229      * of a specifec correspondence stand in a matrix column.
00230      *
00231      * @param src  matrix<ipoint> with the point sets. All points of the same
00232      *    image stand in a row. The correspondences in another image stand in
00233      *    the according columns.
00234      * @param dest fvector the estimated transform.
00235      * @param indices ivector with the indices of the relevant points.
00236      * @param numCorrespondences the first numCorrespondences indices are
00237      *                            considered.
00238      * @return true if the transform could be estimated and false otherwise.
00239      */
00240     virtual bool apply(const matrix<ipoint>& src,
00241                        fvector& dest,
00242                        const ivector& indices,
00243                        int numCorrespondences) const = 0;
00244 
00245     /**
00246      * Estimates a transform from the supplied point sets, whereby only
00247      * the points specified in the index vector are considered. Usually this
00248      * method calls the apply without the residual first, and then computes
00249      * the residual.
00250      *
00251      * All points of one point set give a matrix row, whereas all elements
00252      * of a specifec correspondence stand in a matrix column.
00253      *
00254      * @param src  matrix<ipoint> with the point sets. All points of the same
00255      *    image stand in a row. The correspondences in another image stand in
00256      *    the according columns.
00257      * @param dest fvector the estimated transform.
00258      * @param error fvector containing the deviation of each point from the
00259      *              estimated transform. Usually this is the residual or
00260      *              elementwise squared residual. All correspondences are
00261      *              considered, discarding the valid indices.
00262      * @param indices ivector with the indices of the relevant points.
00263      * @param numCorrespondences the first numCorrespondences indices are
00264      *                            considered.
00265      * @return true if the transform could be estimated and false otherwise.
00266      */
00267     virtual bool apply(const matrix<ipoint>& src,
00268                        fvector& dest, fvector& error,
00269                        const ivector& indices,
00270                        int numCorrespondences) const = 0;
00271 
00272     /**
00273      * Estimates a transform from the supplied point sets, where all
00274      * points are considered. Please implement efficient code using
00275      * iterators here. Not all robust estimators use a random sampling
00276      * approach. Some estimators consider all input points and weight them
00277      * according to their deviation from the transform computed at the prior
00278      * iteration.
00279      *
00280      * All points of one point set give a matrix row, whereas all elements
00281      * of a specifec correspondence stand in a matrix column.
00282      *
00283      * @param src  matrix<fpoint> with the point sets. All points of the same
00284      *    image stand in a row. The correspondences in another image stand in
00285      *    the according columns.
00286      * @param dest fvector the estimated transform.
00287      * @return true if the transform could be estimated and false otherwise.
00288      */
00289     virtual bool apply(const matrix<fpoint>& src,
00290                        fvector& dest) const = 0;
00291 
00292     /**
00293      * Estimates a transform from the supplied point sets, where all
00294      * points are considered. Usually this method calls the apply without
00295      * the residual first, and then computes the residual.
00296      * @param src  matrix<fpoint> with the point sets. All points of the same
00297      *             image stand in a row. The correspondences in another image 
00298      *             stand in the according columns.
00299      *             All points of one point set give a matrix row, whereas all
00300      *             elements of a specific correspondence stand in a matrix
00301      *             column.
00302      * @param dest fvector the estimated transform.
00303      * @param error fvector containing the deviation of each point from the
00304      *              estimated transform. Usually this is the residual or
00305      *              elementwise squared residual.
00306      * @return true if the transform could be estimated and false otherwise.
00307      */
00308     virtual bool apply(const matrix<fpoint>& src,
00309                        fvector& dest, fvector& error) const = 0;
00310 
00311     /**
00312      * Estimates a transform from the supplied point sets, whereby only
00313      * the points specified in the index vector are considered. This method
00314      * is used by robost estimators using a monte carlo approach.
00315      *
00316      * All points of one point set give a matrix row, whereas all elements
00317      * of a specifec correspondence stand in a matrix column.
00318      *
00319      * @param src  matrix<dpoint> with the point sets. All points of the same
00320      *    image stand in a row. The correspondences in another image stand in
00321      *    the according columns.
00322      * @param dest fvector the estimated transform.
00323      * @param indices ivector with the indices of the relevant points.
00324      * @param numCorrespondences the first numCorrespondences indices are
00325      *                            considered.
00326      * @return true if the transform could be estimated and false otherwise.
00327      */
00328     virtual bool apply(const matrix<fpoint>& src,
00329                        fvector& dest,
00330                        const ivector& indices,
00331                        int numCorrespondences) const = 0;
00332 
00333     /**
00334      * Estimates a transform from the supplied point sets, whereby only
00335      * the points specified in the index vector are considered. Usually this
00336      * method calls the apply without the residual first, and then computes
00337      * the residual.
00338      *
00339      * All points of one point set give a matrix row, whereas all elements
00340      * of a specifec correspondence stand in a matrix column.
00341      *
00342      * @param src  matrix<fpoint> with the point sets. All points of the same
00343      *    image stand in a row. The correspondences in another image stand in
00344      *    the according columns.
00345      * @param dest fvector the estimated transform.
00346      * @param error fvector containing the deviation of each point from the
00347      *              estimated transform. Usually this is the residual or
00348      *              elementwise squared residual. All correspondences are
00349      *              considered, discarding the valid indices.
00350      * @param indices ivector with the indices of the relevant points.
00351      * @param numCorrespondences the first numCorrespondences indices are
00352      *                            considered.
00353      * @return true if the transform could be estimated and false otherwise.
00354      */
00355     virtual bool apply(const matrix<fpoint>& src,
00356                        fvector& dest, fvector& error,
00357                        const ivector& indices,
00358                        int numCorrespondences) const = 0;
00359 
00360     /**
00361      * Estimates a transform from the supplied point sets, where all
00362      * points are considered. Please implement efficient code using
00363      * iterators here. Not all robust estimators use a random sampling
00364      * approach. Some estimators consider all input points and weight them
00365      * according to their deviation from the transform computed at the prior
00366      * iteration.
00367      *
00368      * All points of one point set give a matrix row, whereas all elements
00369      * of a specifec correspondence stand in a matrix column.
00370      *
00371      * @param src  matrix<dpoint> with the point sets. All points of the same
00372      *    image stand in a row. The correspondences in another image stand in
00373      *    the according columns.
00374      * @param dest dvector the estimated transform.
00375      * @return true if the transform could be estimated and false otherwise.
00376      */
00377     virtual bool apply(const matrix<dpoint>& src,
00378                        dvector& dest) const = 0;
00379 
00380     /**
00381      * Estimates a transform from the supplied point sets, where all
00382      * points are considered. Usually this method calls the apply without
00383      * the residual first, and then computes the residual.
00384      *
00385      * All points of one point set give a matrix row, whereas all elements
00386      * of a specifec correspondence stand in a matrix column.
00387      *
00388      * @param src  matrix<dpoint> with the point sets. All points of the same
00389      *    image stand in a row. The correspondences in another image stand in
00390      *    the according columns.
00391      * @param dest dvector the estimated transform.
00392      * @param error dvector containing the deviation of each point from the
00393      *              estimated transform. Usually this is the residual or
00394      *              elementwise squared residual.
00395      * @return true if the transform could be estimated and false otherwise.
00396      */
00397     virtual bool apply(const matrix<dpoint>& src,
00398                        dvector& dest, dvector& error) const = 0;
00399 
00400     /**
00401      * Estimates a transform from the supplied point sets, whereby only
00402      * the points specified in the index vector are considered. This method
00403      * is used by robost estimators using a monte carlo approach.
00404      *
00405      * All points of one point set give a matrix row, whereas all elements
00406      * of a specifec correspondence stand in a matrix column.
00407      *
00408      * @param src  matrix<dpoint> with the point sets. All points of the same
00409      *    image stand in a row. The correspondences in another image stand in
00410      *    the according columns.
00411      * @param dest dvector the estimated transform.
00412      * @param indices which rows of the src matrix have to be considered.
00413      * @param numCorrespondences the first numCorrespondences indices are
00414      *                            considered.
00415      * @return true if the transform could be estimated and false otherwise.
00416      */
00417     virtual bool apply(const matrix<dpoint>& src,
00418                        dvector& dest,
00419                        const ivector& indices,
00420                        int numCorrespondences) const = 0;
00421 
00422     /**
00423      * Estimates a transform from the supplied point sets, whereby only
00424      * the points specified in the index vector are considered. Usually this
00425      * method calls the apply without the residual first, and then computes
00426      * the residual.
00427      *
00428      * All points of one point set give a matrix row, whereas all elements
00429      * of a specifec correspondence stand in a matrix column.
00430      *
00431      * @param src  matrix<dpoint> with the point sets. All points of the same
00432      *    image stand in a row. The correspondences in another image stand in
00433      *    the according columns.
00434      * @param dest dvector the estimated transform.
00435      * @param error dvector containing the deviation of each point from the
00436      *              estimated transform. Usually this is the residual or
00437      *              elementwise squared residual.
00438      * @param indices ivector with the indices of the relevant points.
00439      * @param numCorrespondences the first numCorrespondences indices are
00440      *                            considered.
00441      * @return true if the transform could be estimated and false otherwise.
00442      */
00443     virtual bool apply(const matrix<dpoint>& src,
00444                        dvector& dest, dvector& error,
00445                        const ivector& indices,
00446                        int numCorrespondences) const = 0;
00447 
00448     /**
00449      * Compute the residual for the given correspondences and transformation
00450      * vector.
00451      * @param src matrix<fpoint> with the point sets. All points of the same
00452      *    image stand in a row. The correspondences in another image stand in
00453      *    the according columns.
00454      * @param transform fvector with the transformation
00455      * @param dest      fvector with the residual
00456      * @return true on success and false otherwise.
00457      */
00458     virtual bool computeResidual(const matrix<fpoint >& src,
00459                                     const fvector& transform,
00460                                     fvector& dest) const = 0;
00461 
00462     /**
00463      * Compute the residual for the given correspondences and transformation
00464      * vector.
00465      * @param src matrix<dpoint> with the point sets. All points of the same
00466      *    image stand in a row. The correspondences in another image stand in
00467      *    the according columns.
00468      * @param transform dvector with the transformation
00469      * @param dest      dvector with the residual
00470      * @return true on success and false otherwise.
00471      */
00472     virtual bool computeResidual(const matrix<dpoint >& src,
00473                                     const dvector& transform,
00474                                     dvector& dest) const = 0;
00475     
00476     /**
00477      * Returns the minimum number of correspondences required to estimate
00478      * the transform.
00479      */
00480     virtual int minNumberCorrespondences() const = 0;
00481 
00482     /**
00483      * Returns the mininum dimension of a correspondence,
00484      * e.g. the minimum dimension of a correspondence pair is 2.
00485      * Each derived transform estimator only works on correspondences of
00486      * priori defined dimensions.
00487      */
00488     virtual int minCorrespondenceDimension() const = 0;
00489 
00490     /**
00491      * Returns the maximum dimension of a correspondence,
00492      * e.g. the maximum dimension of a correspondence pair is 2, whereas
00493      * transformEstimator running on n-tuples may allow an infinite number.
00494      * Each derived transform estimator only works on correspondences of
00495      * priori defined dimensions.
00496      */
00497     virtual int maxCorrespondenceDimension() const = 0;
00498 
00499     /**
00500      * A transform estimated on normalized data usually differs from
00501      * the transform of the original data. Considering the normalization
00502      * performed this methods computes the transform which applies to the
00503      * original data.
00504      * @param srcdest the normalized transform. The result will be left here
00505      *     too.
00506      * @param scale a vector containing the scale applied to each point set.
00507      * @param shift a vector containing the shift of each scaled point set.
00508      */
00509     virtual bool denormalize(fvector& srcdest,
00510                              const vector<fpoint>& scale,
00511                              const vector<fpoint>& shift) const = 0;
00512     
00513     /**
00514      * A transform estimated on normalized data usually differs from
00515      * the transform of the original data. Considering the normalization
00516      * performed this methods computes the transform which applies to the
00517      * original data.
00518      * @param srcdest the normalized transform. The result will be left here
00519      *     too.
00520      * @param scale a vector containing the scale applied to each point set.
00521      * @param shift a vector containing the shift of each scaled point set.
00522      */
00523     virtual bool denormalize(dvector& srcdest,
00524                              const vector<dpoint>& scale,
00525                              const vector<dpoint>& shift) const = 0;
00526 
00527     /**
00528      * Copy data of "other" functor.
00529      * @param other the functor to be copied
00530      * @return a reference to this functor object
00531      */
00532     transformEstimator& copy(const transformEstimator& other);
00533 
00534     /**
00535      * Alias for copy member
00536      * @param other the functor to be copied
00537      * @return a reference to this functor object
00538      */
00539     transformEstimator& operator=(const transformEstimator& other);
00540 
00541     /**
00542      * Returns a pointer to a clone of this functor.
00543      */
00544     virtual functor* clone() const = 0;
00545 
00546     /**
00547      * Returns used parameters
00548      */
00549     const parameters& getParameters() const;
00550 
00551   };
00552 }
00553 
00554 #endif

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