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

ltiFMatrixEstimator.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 .......: ltiFMatrixEstimator.h
00027  * authors ....: Claudia Goenner
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 15.7.2004
00030  * revisions ..: $Id: ltiFMatrixEstimator.h,v 1.6 2007/01/10 02:25:54 alvarado Exp $
00031  */
00032 
00033 #ifndef _LTI_FMATRIX_ESTIMATOR_H_
00034 #define _LTI_FMATRIX_ESTIMATOR_H_
00035 
00036 #include "ltiFMatrixEstimatorBase.h"
00037 #include "ltiHTypes.h"
00038 
00039 namespace lti {
00040 
00041   /**
00042    * A class for estimating the fundamental matrix with a least squares
00043    * approach.
00044    */
00045   class fMatrixEstimator : public fMatrixEstimatorBase {
00046   public:
00047     /**
00048      * The parameters for the class fMatrixEstimator
00049      */
00050     class parameters : public fMatrixEstimatorBase::parameters {
00051     public:
00052       /**
00053        * Default constructor
00054        */
00055       parameters();
00056 
00057       /**
00058        * Copy constructor
00059        * @param other the parameters object to be copied
00060        */
00061       parameters(const parameters& other);
00062 
00063       /**
00064        * Destructor
00065        */
00066       ~parameters();
00067 
00068       /**
00069        * Returns name of this type
00070        */
00071       const char* getTypeName() const;
00072 
00073       /**
00074        * Copy the contents of a parameters object
00075        * @param other the parameters object to be copied
00076        * @return a reference to this parameters object
00077        */
00078       parameters& copy(const parameters& other);
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& operator=(const parameters& other);
00086 
00087 
00088       /**
00089        * Returns a pointer to a clone of the parameters
00090        */
00091       virtual functor::parameters* clone() const;
00092 
00093       /**
00094        * Write the parameters in the given ioHandler
00095        * @param handler the ioHandler to be used
00096        * @param complete if true (the default) the enclosing begin/end will
00097        *        be also written, otherwise only the data block will be written.
00098        * @return true if write was successful
00099        */
00100       virtual bool write(ioHandler& handler,const bool complete=true) const;
00101 
00102       /**
00103        * Read the parameters from the given ioHandler
00104        * @param handler the ioHandler to be used
00105        * @param complete if true (the default) the enclosing begin/end will
00106        *        be also written, otherwise only the data block will be written.
00107        * @return true if write was successful
00108        */
00109       virtual bool read(ioHandler& handler,const bool complete=true);
00110 
00111 #     ifdef _LTI_MSC_6
00112       /**
00113        * This function is required by MSVC only, as a workaround for a
00114        * very awful bug, which exists since MSVC V.4.0, and still by
00115        * V.6.0 with all bugfixes (so called "service packs") remains
00116        * there...  This method is also public due to another bug, so please
00117        * NEVER EVER call this method directly: use read() instead
00118        */
00119       bool readMS(ioHandler& handler,const bool complete=true);
00120 
00121       /**
00122        * This function is required by MSVC only, as a workaround for a
00123        * very awful bug, which exists since MSVC V.4.0, and still by
00124        * V.6.0 with all bugfixes (so called "service packs") remains
00125        * there...  This method is also public due to another bug, so please
00126        * NEVER EVER call this method directly: use write() instead
00127        */
00128       bool writeMS(ioHandler& handler,const bool complete=true) const;
00129 #     endif
00130 
00131       // ------------------------------------------------
00132       // the parameters
00133       // ------------------------------------------------
00134 
00135     };
00136 
00137     /**
00138      * Default constructor
00139      */
00140     fMatrixEstimator();
00141 
00142     /**
00143      * Construct a functor using the given parameters
00144      */
00145     fMatrixEstimator(const parameters& par);
00146 
00147     /**
00148      * Copy constructor
00149      * @param other the object to be copied
00150      */
00151     fMatrixEstimator(const fMatrixEstimator& other);
00152 
00153     /**
00154      * Destructor
00155      */
00156     virtual ~fMatrixEstimator();
00157 
00158     /**
00159      * Returns the name of this type ("fMatrixEstimator")
00160      */
00161     virtual const char* getTypeName() const;
00162 
00163     /**
00164      * Estimates a transform from the supplied point sets, where all
00165      * points are considered. Please implement efficient code using
00166      * iterators here. Not all robust estimators use a random sampling
00167      * approach. Some estimators consider all input points and weight them
00168      * according to their deviation from the transform computed at the prior
00169      * iteration.
00170      *
00171      * All points of one point set give a matrix row, whereas all elements
00172      * of a specifec correspondence stand in a matrix column.
00173      *
00174      * @param src matrix<ipoint> with the point sets. All points of the same
00175      *    image stand in a row. The correspondences in another image stand in
00176      *    the according columns.
00177      * @param dest fvector the estimated transform.
00178      * @return true if apply successful or false otherwise.
00179      */
00180     virtual bool apply(const matrix<ipoint>& src,
00181                        fvector& dest) const;
00182 
00183     /**
00184      * Estimates a transform from the supplied point sets, where all
00185      * points are considered. Usually this method calls the apply without
00186      * the residual first, and then computes the residual.
00187      *
00188      * All points of one point set give a matrix row, whereas all elements
00189      * of a specifec correspondence stand in a matrix column.
00190      *  
00191      * @param src matrix<ipoint> with the point sets. All points of the same
00192      *    image stand in a row. The correspondences in another image stand in
00193      *    the according columns.
00194      * @param dest fvector the estimated transform.
00195      * @param error fvector containing the deviation of each point from the
00196      *              estimated transform. Usually this is the residual or
00197      *              elementwise squared residual.
00198      * @return true if apply successful or false otherwise.
00199      */
00200     virtual bool apply(const matrix<ipoint>& src,
00201                        fvector& dest, fvector& error) const;
00202 
00203     /**
00204      * Estimates a transform from the supplied point sets, whereby only
00205      * the points specified in the index vector are considered. This method
00206      * is used by robost estimators using a monte carlo approach.
00207      *
00208      * All points of one point set give a matrix row, whereas all elements
00209      * of a specifec correspondence stand in a matrix column.
00210      *
00211      * @param src matrix<ipoint> with the point sets. All points of the same
00212      *    image stand in a row. The correspondences in another image stand in
00213      *    the according columns.
00214      * @param dest fvector the estimated transform.
00215      * @param indices ivector with the indices of the relevant points.
00216      * @param numCorrespondences the first numCorrespondences indices are
00217      *                            considered.
00218      * @return true if apply successful or false otherwise.
00219      */
00220     virtual bool apply(const matrix<ipoint>& src,
00221                        fvector& dest,
00222                        const ivector& indices,
00223                        int numCorrespondences) const;
00224 
00225     /**
00226      * Estimates a transform from the supplied point sets, whereby only
00227      * the points specified in the index vector are considered. Usually this
00228      * method calls the apply without the residual first, and then computes
00229      * the residual.
00230      *
00231      * All points of one point set give a matrix row, whereas all elements
00232      * of a specifec correspondence stand in a matrix column.
00233      *
00234      * @param src matrix<ipoint> with the point sets. All points of the same
00235      *    image stand in a row. The correspondences in another image stand in
00236      *    the according columns.
00237      * @param dest fvector the estimated transform.
00238      * @param error fvector containing the deviation of each point from the
00239      *              estimated transform. Usually this is the residual or
00240      *              elementwise squared residual.
00241      * @param indices ivector with the indices of the relevant points.
00242      * @param numCorrespondences the first numCorrespondences indices are
00243      *                            considered.
00244      * @return true if apply successful or false otherwise.
00245      */
00246     virtual bool apply(const matrix<ipoint>& src,
00247                        fvector& dest, fvector& error,
00248                        const ivector& indices,
00249                        int numCorrespondences) const;
00250 
00251      /**
00252      * Estimates a transform from the supplied point sets, where all
00253      * points are considered. Please implement efficient code using
00254      * iterators here. Not all robust estimators use a random sampling
00255      * approach. Some estimators consider all input points and weight them
00256      * according to their deviation from the transform computed at the prior
00257      * iteration.
00258      *
00259      * All points of one point set give a matrix row, whereas all elements
00260      * of a specifec correspondence stand in a matrix column.
00261      *
00262      * @param src matrix<fpoint> with the point sets. All points of the same
00263      *    image stand in a row. The correspondences in another image stand in
00264      *    the according columns.
00265      * @param dest fvector the estimated transform.
00266      * @return true if apply successful or false otherwise.
00267      */
00268     virtual bool apply(const matrix<fpoint>& src,
00269                        fvector& dest) const;
00270 
00271     /**
00272      * Estimates a transform from the supplied point sets, where all
00273      * points are considered. Usually this method calls the apply without
00274      * the residual first, and then computes the residual.
00275      *
00276      * All points of one point set give a matrix row, whereas all elements
00277      * of a specifec correspondence stand in a matrix column.
00278      *  
00279      * @param src matrix<fpoint> with the point sets. All points of the same
00280      *    image stand in a row. The correspondences in another image stand in
00281      *    the according columns.
00282      * @param dest fvector the estimated transform.
00283      * @param error fvector containing the deviation of each point from the
00284      *              estimated transform. Usually this is the residual or
00285      *              elementwise squared residual.
00286      * @return true if apply successful or false otherwise.
00287      */
00288     virtual bool apply(const matrix<fpoint>& src,
00289                        fvector& dest, fvector& error) const;
00290 
00291     /**
00292      * Estimates a transform from the supplied point sets, whereby only
00293      * the points specified in the index vector are considered. This method
00294      * is used by robost estimators using a monte carlo approach.
00295      *
00296      * All points of one point set give a matrix row, whereas all elements
00297      * of a specifec correspondence stand in a matrix column.
00298      *
00299      * @param src matrix<fpoint> with the point sets. All points of the same
00300      *    image stand in a row. The correspondences in another image stand in
00301      *    the according columns.
00302      * @param dest fvector the estimated transform.
00303      * @param indices ivector with the indices of the relevant points.
00304      * @param numCorrespondences the first numCorrespondences indices are
00305      *                            considered.
00306      * @return true if apply successful or false otherwise.
00307      */
00308     virtual bool apply(const matrix<fpoint>& src,
00309                        fvector& dest,
00310                        const ivector& indices,
00311                        int numCorrespondences) const;
00312 
00313     /**
00314      * Estimates a transform from the supplied point sets, whereby only
00315      * the points specified in the index vector are considered. Usually this
00316      * method calls the apply without the residual first, and then computes
00317      * the residual.
00318      *
00319      * All points of one point set give a matrix row, whereas all elements
00320      * of a specifec correspondence stand in a matrix column.
00321      *
00322      * @param src matrix<fpoint> with the point sets. All points of the same
00323      *    image stand in a row. The correspondences in another image stand in
00324      *    the according columns.
00325      * @param dest fvector the estimated transform.
00326      * @param error fvector containing the deviation of each point from the
00327      *              estimated transform. Usually this is the residual or
00328      *              elementwise squared residual.
00329      * @param indices ivector with the indices of the relevant points.
00330      * @param numCorrespondences the first numCorrespondences indices are
00331      *                            considered.
00332      * @return true if apply successful or false otherwise.
00333      */
00334     virtual bool apply(const matrix<fpoint>& src,
00335                        fvector& dest, fvector& error,
00336                        const ivector& indices,
00337                        int numCorrespondences) const;
00338 
00339     /**
00340      * Estimates a transform from the supplied point sets, where all
00341      * points are considered. Please implement efficient code using
00342      * iterators here. Not all robust estimators use a random sampling
00343      * approach. Some estimators consider all input points and weight them
00344      * according to their deviation from the transform computed at the prior
00345      * iteration.
00346      *
00347      * All points of one point set give a matrix row, whereas all elements
00348      * of a specifec correspondence stand in a matrix column.
00349      *
00350      * @param src matrix<dpoint> with the point sets. All points of the same
00351      *    image stand in a row. The correspondences in another image stand in
00352      *    the according columns.
00353      * @param dest dvector the estimated transform.
00354      * @return true if apply successful or false otherwise.
00355      */
00356     virtual bool apply(const matrix<dpoint>& src,
00357                        dvector& dest) const;
00358 
00359     /**
00360      * Estimates a transform from the supplied point sets, where all
00361      * points are considered. Usually this method calls the apply without
00362      * the residual first, and then computes the residual.
00363      *
00364      * All points of one point set give a matrix row, whereas all elements
00365      * of a specifec correspondence stand in a matrix column.
00366      *    
00367      * @param src matrix<dpoint> with the point sets. All points of the same
00368      *    image stand in a row. The correspondences in another image stand in
00369      *    the according columns.
00370      * @param dest dvector the estimated transform.
00371      * @param error dvector containing the deviation of each point from the
00372      *              estimated transform. Usually this is the residual or
00373      *              elementwise squared residual.
00374      * @return true if apply successful or false otherwise.
00375      */
00376     virtual bool apply(const matrix<dpoint>& src,
00377                        dvector& dest, dvector& error) const;
00378 
00379     /**
00380      * Estimates a transform from the supplied point sets, whereby only
00381      * the points specified in the index vector are considered. This method
00382      * is used by robost estimators using a monte carlo approach.
00383      *
00384      * All points of one point set give a matrix row, whereas all elements
00385      * of a specifec correspondence stand in a matrix column.
00386      *
00387      * @param src matrix<dpoint> with the point sets. All points of the same
00388      *    image stand in a row. The correspondences in another image stand in
00389      *    the according columns.
00390      * @param dest dvector the estimated transform.
00391      * @param indices ivector with the indices of the relevant points.
00392      * @param numCorrespondences the first numCorrespondences indices are
00393      *                            considered.
00394      * @return true if apply successful or false otherwise.
00395      */
00396     virtual bool apply(const matrix<dpoint>& src,
00397                        dvector& dest,
00398                        const ivector& indices,
00399                        int numCorrespondences) const;
00400 
00401     /**
00402      * Estimates a transform from the supplied point sets, whereby only
00403      * the points specified in the index vector are considered. Usually this
00404      * method calls the apply without the residual first, and then computes
00405      * the residual.
00406      *
00407      * All points of one point set give a matrix row, whereas all elements
00408      * of a specifec correspondence stand in a matrix column.
00409      *
00410      * @param src matrix<dpoint> with the point sets. All points of the same
00411      *    image stand in a row. The correspondences in another image stand in
00412      *    the according columns.
00413      * @param dest dvector the estimated transform.
00414      * @param error dvector containing the deviation of each point from the
00415      *              estimated transform. Usually this is the residual or
00416      *              elementwise squared residual.
00417      * @param indices ivector with the indices of the relevant points.
00418      * @param numCorrespondences the first numCorrespondences indices are
00419      *                            considered.
00420      * @return true if apply successful or false otherwise.
00421      */
00422     virtual bool apply(const matrix<dpoint>& src,
00423                        dvector& dest, dvector& error,
00424                        const ivector& indices,
00425                        int numCorrespondences) const;
00426 
00427     /**
00428      * Compute the residual for the given correspondences and transformation
00429      * vector.
00430      * @param src matrix<fpoint> with the point sets. All points of the same
00431      *    image stand in a row. The correspondences in another image stand in
00432      *    the according columns.
00433      * @param transform fvector with the transformation
00434      * @param dest      fvector with the residual
00435      * @return true on success and false otherwise.
00436      */
00437     virtual bool computeResidual(const matrix<fpoint >& src,
00438                                     const fvector& transform,
00439                                     fvector& dest) const;
00440 
00441     /**
00442      * Compute the residual for the given correspondences and transformation
00443      * vector.
00444      * @param src matrix<dpoint> with the point sets. All points of the same
00445      *    image stand in a row. The correspondences in another image stand in
00446      *    the according columns.
00447      * @param transform dvector with the transformation
00448      * @param dest      dvector with the residual
00449      * @return true on success and false otherwise.
00450      */
00451     virtual bool computeResidual(const matrix<dpoint >& src,
00452                                  const dvector& transform,
00453                                  dvector& dest) const;
00454 
00455     /**
00456      * Returns the minimum number of correspondences required to estimate
00457      * the transform.
00458      */
00459     virtual int minNumberCorrespondences() const;
00460 
00461     /**
00462      * Returns the mininum dimension of a correspondence,
00463      * e.g. the minimum dimension of a correspondence pair is 2.
00464      * Each derived transform estimator only works on correspondences of
00465      * priori defined dimensions.
00466      */
00467     virtual int minCorrespondenceDimension() const;
00468 
00469     /**
00470      * Returns the maximum dimension of a correspondence,
00471      * e.g. the maximum dimension of a correspondence pair is 2, whereas
00472      * transformEstimator running on n-tuples may allow an infinite number.
00473      * Each derived transform estimator only works on correspondences of
00474      * priori defined dimensions.
00475      */
00476     virtual int maxCorrespondenceDimension() const;
00477 
00478     /**
00479      * A transform estimated on normalized data usually differs from
00480      * the transform of the original data. Considering the normalization
00481      * performed this methods computes the transform which applies to the
00482      * original data.
00483      * @param srcdest the normalized transform. The result will be left here
00484      *     too.
00485      * @param scale a vector containing the scale applied to each point set.
00486      * @param shift a vector containing the shift of each scaled point set.
00487      */
00488     bool denormalize(fvector& srcdest,
00489                      const vector<fpoint>& scale,
00490                      const vector<fpoint>& shift) const;
00491 
00492     /**
00493      * A transform estimated on normalized data usually differs from
00494      * the transform of the original data. Considering the normalization
00495      * performed this methods computes the transform which applies to the
00496      * original data.
00497      * @param srcdest the normalized transform. The result will be left here
00498      *     too.
00499      * @param scale a vector containing the scale applied to each point set.
00500      * @param shift a vector containing the shift of each scaled point set.
00501      */
00502     bool denormalize(dvector& srcdest,
00503                      const vector<dpoint>& scale,
00504                      const vector<dpoint>& shift) const;
00505 
00506     /**
00507      * Converts the estimated vector into a 3x3 matrix.
00508      *
00509      * @param src fvector the estimated transform.
00510      * @param dest fmatrix the estimated transform as a matrix.
00511      *
00512      * @return true if successful or false otherwise.
00513      */
00514     bool convert(const fvector& src, fmatrix& dest) const;
00515 
00516     /**
00517      * Converts the estimated vector into a 3x3 matrix.
00518      *
00519      * @param src dvector the estimated transform.
00520      * @param dest dmatrix the estimated transform as a matrix.
00521      *
00522      * @return true if successful or false otherwise.
00523      */
00524     bool convert(const dvector& src, dmatrix& dest) const;
00525 
00526     /**
00527      * Copy data of "other" functor.
00528      * @param other the functor to be copied
00529      * @return a reference to this functor object
00530      */
00531     fMatrixEstimator& copy(const fMatrixEstimator& other);
00532 
00533     /**
00534      * Alias for copy member
00535      * @param other the functor to be copied
00536      * @return a reference to this functor object
00537      */
00538     fMatrixEstimator& operator=(const fMatrixEstimator& other);
00539 
00540     /**
00541      * Returns a pointer to a clone of this functor.
00542      */
00543     virtual functor* clone() const;
00544 
00545     /**
00546      * Returns used parameters
00547      */
00548     const parameters& getParameters() const;
00549 
00550   };
00551 }
00552 
00553 #endif

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