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

ltiTranslationScaleEstimator.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 .......: ltiTranslationScaleEstimator.h
00027  * authors ....: Claudia Goenner
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 14.4.2004
00030  * revisions ..: $Id: ltiTranslationScaleEstimator.h,v 1.5 2007/01/10 02:26:09 alvarado Exp $
00031  */
00032 
00033 #ifndef _LTI_TRANSLATION_SCALE_ESTIMATOR_H_
00034 #define _LTI_TRANSLATION_SCALE_ESTIMATOR_H_
00035 
00036 #include "ltiHomographyEstimatorBase.h"
00037 #include "ltiHTypes.h"
00038 
00039 namespace lti {
00040 
00041   /**
00042    * This class estimates a translation and common scale for the x and y
00043    * coordinates, i.e. the following transformation:
00044    * \code
00045    * x_new = s * x + tx
00046    * y_new = s * y + ty
00047    * \endcode
00048    * The resulting least squares problem is solved by a cholesky
00049    * decomposition.
00050    *
00051    * Such a transformation can be used to correct distortion errors
00052    * when the camera rotation and translation is known a priori,
00053    * but errorprone.
00054    */
00055   class translationScaleEstimator : public homographyEstimatorBase {
00056   public:
00057     /**
00058      * The parameters for the class translationScaleEstimator
00059      */
00060     class parameters : public homographyEstimatorBase::parameters {
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 
00147     /**
00148      * Default constructor
00149      */
00150     translationScaleEstimator();
00151 
00152     /**
00153      * Construct a functor using the given parameters
00154      */
00155     translationScaleEstimator(const parameters& par);
00156 
00157     /**
00158      * Copy constructor
00159      * @param other the object to be copied
00160      */
00161     translationScaleEstimator(const translationScaleEstimator& other);
00162 
00163     /**
00164      * Destructor
00165      */
00166     virtual ~translationScaleEstimator();
00167 
00168     /**
00169      * Returns the name of this type ("translationScaleEstimator")
00170      */
00171     virtual const char* getTypeName() const;
00172 
00173     /**
00174      * Estimates a transform from the supplied point sets, where all
00175      * points are considered. 
00176      *
00177      * All points of one point set give a matrix row, whereas all elements
00178      * of a specifec correspondence stand in a matrix column.
00179      *
00180      * @param src matrix<ipoint> with the point sets. All points of the same
00181      *    image stand in a row. The correspondences in another image stand in
00182      *    the according columns.
00183      * @param dest fvector the estimated transform.
00184      * @return true if apply successful or false otherwise.
00185      */
00186     virtual bool apply(const matrix<ipoint>& src,
00187            fvector& dest) const;
00188 
00189     /**
00190      * Estimates a transform from the supplied point sets, where all
00191      * points are considered. This method calls the apply without
00192      * the residual first, and then computes the residual.
00193      *
00194      * All points of one point set give a matrix row, whereas all elements
00195      * of a specifec correspondence stand in a matrix column.
00196      *  
00197      * @param src matrix<ipoint> with the point sets. All points of the same
00198      *    image stand in a row. The correspondences in another image stand in
00199      *    the according columns.
00200      * @param dest fvector the estimated transform.
00201      * @param error fvector containing the deviation of each point from the
00202      *              estimated transform. Usually this is the residual or
00203      *              elementwise squared residual.
00204      * @return true if apply successful or false otherwise.
00205      */
00206     virtual bool apply(const matrix<ipoint>& src,
00207            fvector& dest, fvector& error) const;
00208 
00209     /**
00210      * Estimates a transform from the supplied point sets, whereby only
00211      * the points specified in the index vector are considered. This method
00212      * is used by robost estimators using a monte carlo approach.
00213      *
00214      * All points of one point set give a matrix row, whereas all elements
00215      * of a specifec correspondence stand in a matrix column.
00216      *
00217      * @param src matrix<ipoint> with the point sets. All points of the same
00218      *    image stand in a row. The correspondences in another image stand in
00219      *    the according columns.
00220      * @param dest fvector the estimated transform.
00221      * @param indices ivector with the indices of the relevant points.
00222      * @param numCorrespondences the first numCorrespondences indices are
00223      *                            considered.
00224      * @return true if apply successful or false otherwise.
00225      */
00226     virtual bool apply(const matrix<ipoint>& src,
00227            fvector& dest,
00228            const ivector& indices,
00229            int numCorrespondences) const;
00230 
00231     /**
00232      * Estimates a transform from the supplied point sets, whereby only
00233      * the points specified in the index vector are considered. This
00234      * method calls the apply without the residual first, and then computes
00235      * the residual.
00236      *
00237      * All points of one point set give a matrix row, whereas all elements
00238      * of a specifec correspondence stand in a matrix column.
00239      *
00240      * @param src matrix<ipoint> with the point sets. All points of the same
00241      *    image stand in a row. The correspondences in another image stand in
00242      *    the according columns.
00243      * @param dest fvector the estimated transform.
00244      * @param error fvector containing the deviation of each point from the
00245      *              estimated transform. Usually this is the residual or
00246      *              elementwise squared residual.
00247      * @param indices ivector with the indices of the relevant points.
00248      * @param numCorrespondences the first numCorrespondences indices are
00249      *                            considered.
00250      * @return true if apply successful or false otherwise.
00251      */
00252     virtual bool apply(const matrix<ipoint>& src,
00253            fvector& dest, fvector& error,
00254            const ivector& indices,
00255            int numCorrespondences) const;
00256 
00257     /**
00258      * Estimates a transform from the supplied point sets, where all
00259      * points are considered.
00260      *
00261      * All points of one point set give a matrix row, whereas all elements
00262      * of a specifec correspondence stand in a matrix column.
00263      *
00264      * @param src matrix<fpoint> with the point sets. All points of the same
00265      *    image stand in a row. The correspondences in another image stand in
00266      *    the according columns.
00267      * @param dest fvector the estimated transform.
00268      * @return true if apply successful or false otherwise.
00269      */
00270     virtual bool apply(const matrix<fpoint>& src,
00271            fvector& dest) const;
00272 
00273     /**
00274      * Estimates a transform from the supplied point sets, where all
00275      * points are considered. This method calls the apply without
00276      * the residual first, and then computes the residual.
00277      *
00278      * All points of one point set give a matrix row, whereas all elements
00279      * of a specifec correspondence stand in a matrix column.
00280      *  
00281      * @param src matrix<fpoint> with the point sets. All points of the same
00282      *    image stand in a row. The correspondences in another image stand in
00283      *    the according columns.
00284      * @param dest fvector the estimated transform.
00285      * @param error fvector containing the deviation of each point from the
00286      *              estimated transform. Usually this is the residual or
00287      *              elementwise squared residual.
00288      * @return true if apply successful or false otherwise.
00289      */
00290     virtual bool apply(const matrix<fpoint>& src,
00291            fvector& dest, fvector& error) const;
00292 
00293     /**
00294      * Estimates a transform from the supplied point sets, whereby only
00295      * the points specified in the index vector are considered. This method
00296      * is used by robost estimators using a monte carlo approach.
00297      *
00298      * All points of one point set give a matrix row, whereas all elements
00299      * of a specifec correspondence stand in a matrix column.
00300      *
00301      * @param src matrix<fpoint> with the point sets. All points of the same
00302      *    image stand in a row. The correspondences in another image stand in
00303      *    the according columns.
00304      * @param dest fvector the estimated transform.
00305      * @param indices ivector with the indices of the relevant points.
00306      * @param numCorrespondences the first numCorrespondences indices are
00307      *                            considered.
00308      * @return true if apply successful or false otherwise.
00309      */
00310     virtual bool apply(const matrix<fpoint>& src,
00311            fvector& dest,
00312            const ivector& indices,
00313            int numCorrespondences) const;
00314 
00315     /**
00316      * Estimates a transform from the supplied point sets, whereby only
00317      * the points specified in the index vector are considered. This
00318      * method calls the apply without the residual first, and then computes
00319      * the residual.
00320      *
00321      * All points of one point set give a matrix row, whereas all elements
00322      * of a specifec correspondence stand in a matrix column.
00323      *
00324      * @param src matrix<fpoint> with the point sets. All points of the same
00325      *    image stand in a row. The correspondences in another image stand in
00326      *    the according columns.
00327      * @param dest fvector the estimated transform.
00328      * @param error fvector containing the deviation of each point from the
00329      *              estimated transform. Usually this is the residual or
00330      *              elementwise squared residual.
00331      * @param indices ivector with the indices of the relevant points.
00332      * @param numCorrespondences the first numCorrespondences indices are
00333      *                            considered.
00334      * @return true if apply successful or false otherwise.
00335      */
00336     virtual bool apply(const matrix<fpoint>& src,
00337            fvector& dest, fvector& error,
00338            const ivector& indices,
00339            int numCorrespondences) const;
00340 
00341     /**
00342      * Estimates a transform from the supplied point sets, where all
00343      * points are considered.
00344      *
00345      * All points of one point set give a matrix row, whereas all elements
00346      * of a specifec correspondence stand in a matrix column.
00347      *
00348      * @param src matrix<dpoint> with the point sets. All points of the same
00349      *    image stand in a row. The correspondences in another image stand in
00350      *    the according columns.
00351      * @param dest dvector the estimated transform.
00352      * @return true if apply successful or false otherwise.
00353      */
00354     virtual bool apply(const matrix<dpoint>& src,
00355            dvector& dest) const;
00356 
00357     /**
00358      * Estimates a transform from the supplied point sets, where all
00359      * points are considered. This method calls the apply without
00360      * the residual first, and then computes the residual.
00361      *
00362      * All points of one point set give a matrix row, whereas all elements
00363      * of a specifec correspondence stand in a matrix column.
00364      *    
00365      * @param src matrix<dpoint> with the point sets. All points of the same
00366      *    image stand in a row. The correspondences in another image stand in
00367      *    the according columns.
00368      * @param dest dvector the estimated transform.
00369      * @param error dvector containing the deviation of each point from the
00370      *              estimated transform. Usually this is the residual or
00371      *              elementwise squared residual.
00372      * @return true if apply successful or false otherwise.
00373      */
00374     virtual bool apply(const matrix<dpoint>& src,
00375            dvector& dest, dvector& error) const;
00376 
00377     /**
00378      * Estimates a transform from the supplied point sets, whereby only
00379      * the points specified in the index vector are considered. This method
00380      * is used by robost estimators using a monte carlo approach.
00381      *
00382      * All points of one point set give a matrix row, whereas all elements
00383      * of a specifec correspondence stand in a matrix column.
00384      *
00385      * @param src matrix<dpoint> with the point sets. All points of the same
00386      *    image stand in a row. The correspondences in another image stand in
00387      *    the according columns.
00388      * @param dest dvector the estimated transform.
00389      * @param indices ivector with the indices of the relevant points.
00390      * @param numCorrespondences the first numCorrespondences indices are
00391      *                            considered.
00392      * @return true if apply successful or false otherwise.
00393      */
00394     virtual bool apply(const matrix<dpoint>& src,
00395            dvector& dest,
00396            const ivector& indices,
00397            int numCorrespondences) const;
00398 
00399     /**
00400      * Estimates a transform from the supplied point sets, whereby only
00401      * the points specified in the index vector are considered. This
00402      * method calls the apply without the residual first, and then computes
00403      * the residual.
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 error dvector containing the deviation of each point from the
00413      *              estimated transform. Usually this is the residual or
00414      *              elementwise squared residual.
00415      * @param indices ivector with the indices of the relevant points.
00416      * @param numCorrespondences the first numCorrespondences indices are
00417      *                            considered.
00418      * @return true if apply successful or false otherwise.
00419      */
00420     virtual bool apply(const matrix<dpoint>& src,
00421            dvector& dest, dvector& error,
00422            const ivector& indices,
00423            int numCorrespondences) const;
00424 
00425     /**
00426      * Compute the residual for the given correspondences and transformation
00427      * vector.
00428      * @param src matrix<fpoint> with the point sets. All points of the same
00429      *    image stand in a row. The correspondences in another image stand in
00430      *    the according columns.
00431      * @param transform fvector with the transformation
00432      * @param dest      fvector with the residual
00433      * @return true on success and false otherwise.
00434      */
00435     virtual bool computeResidual(const matrix<fpoint >& src,
00436             const fvector& transform,
00437             fvector& dest) const;
00438 
00439     /**
00440      * Compute the residual for the given correspondences and transformation
00441      * vector.
00442      * @param src matrix<dpoint> with the point sets. All points of the same
00443      *    image stand in a row. The correspondences in another image stand in
00444      *    the according columns.
00445      * @param transform dvector with the transformation
00446      * @param dest      dvector with the residual
00447      * @return true on success and false otherwise.
00448      */
00449     virtual bool computeResidual(const matrix<dpoint >& src,
00450             const dvector& transform,
00451             dvector& dest) const;
00452 
00453     /**
00454      * Returns the minimum number of correspondences required to estimate
00455      * the transform.
00456      */
00457     virtual int minNumberCorrespondences() const;
00458 
00459     /**
00460      * Returns the mininum dimension of a correspondence,
00461      * e.g. the minimum dimension of a correspondence pair is 2.
00462      * Each derived transform estimator only works on correspondences of
00463      * priori defined dimensions.
00464      */
00465     virtual int minCorrespondenceDimension() const;
00466 
00467     /**
00468      * Returns the maximum dimension of a correspondence,
00469      * e.g. the maximum dimension of a correspondence pair is 2, whereas
00470      * transformEstimator running on n-tuples may allow an infinite number.
00471      * Each derived transform estimator only works on correspondences of
00472      * priori defined dimensions.
00473      */
00474     virtual int maxCorrespondenceDimension() const;
00475 
00476     /**
00477      * A transform estimated on normalized data usually differs from
00478      * the transform of the original data. Considering the normalization
00479      * performed this methods computes the transform which applies to the
00480      * original data.
00481      * @param srcdest the normalized transform. The result will be left here
00482      *     too.
00483      * @param scale a vector containing the scale applied to each point set.
00484      * @param shift a vector containing the shift of each scaled point set.
00485      */
00486     bool denormalize(fvector& srcdest,
00487          const vector<fpoint>& scale,
00488          const vector<fpoint>& shift) const;
00489 
00490     /**
00491      * A transform estimated on normalized data usually differs from
00492      * the transform of the original data. Considering the normalization
00493      * performed this methods computes the transform which applies to the
00494      * original data.
00495      * @param srcdest the normalized transform. The result will be left here
00496      *     too.
00497      * @param scale a vector containing the scale applied to each point set.
00498      * @param shift a vector containing the shift of each scaled point set.
00499      */
00500     bool denormalize(dvector& srcdest,
00501          const vector<dpoint>& scale,
00502          const vector<dpoint>& shift) const;
00503 
00504     /**
00505      * Converts the estimated vector into a hMatrix3D<float>, which is e.g.
00506      * used by geometricTransform.
00507      * @param src fvector the estimated transform.
00508      * @param dest hMatrix3D<float> the estimated transform as a hMatrix3D.
00509      *
00510      * @return true if successful or false otherwise.
00511      */
00512     bool convert(const fvector& src, hMatrix3D<float>& dest) const;
00513   
00514     /**
00515      * Converts the estimated vector into a hMatrix3D<float>, which is e.g.
00516      * used by geometricTransform.
00517      * @param src dvector the estimated transform.
00518      * @param dest hMatrix3D<float> the estimated transform as a hMatrix3D.
00519      *
00520      * @return true if successful or false otherwise.
00521      */
00522     bool convert(const dvector& src, hMatrix3D<float>& dest) const;
00523     
00524     /**
00525      * Converts the estimated vector into a 3x3 matrix.
00526      *
00527      * @param src fvector the estimated transform.
00528      * @param dest fmatrix the estimated transform as a matrix.
00529      *
00530      * @return true if successful or false otherwise.
00531      */
00532     bool convert(const fvector& src, fmatrix& dest) const;
00533 
00534     /**
00535      * Converts the estimated vector into a 3x3 matrix.
00536      *
00537      * @param src dvector the estimated transform.
00538      * @param dest dmatrix the estimated transform as a matrix.
00539      *
00540      * @return true if successful or false otherwise.
00541      */
00542     bool convert(const dvector& src, dmatrix& dest) const;
00543 
00544     /**
00545      * This is a fast short cut used by the special robust estimator
00546      * homographyVerification in the main loop.
00547      * @param pt fpoint the point to be transformed
00548      * @param transf fvector with the transformation, which e.g. was computed
00549      *               by an apply.
00550      * @return the transformed point
00551      */
00552     fpoint transform(const fpoint& pt, 
00553          const fvector& transf) const;
00554     
00555     /**
00556      * This is a fast short cut used by the special robust estimator
00557      * homographyVerification in the main loop.
00558      * @param pt fpoint the point to be transformed
00559      * @param transf fvector with the transformation, which e.g. was computed
00560      *               by an apply.
00561      * @return the transformed point
00562      */
00563     dpoint transform(const dpoint& pt, 
00564          const dvector& transf) const;
00565 
00566     /**
00567      * Copy data of "other" functor.
00568      * @param other the functor to be copied
00569      * @return a reference to this functor object
00570      */
00571     translationScaleEstimator& copy(const translationScaleEstimator& other);
00572 
00573     /**
00574      * Alias for copy member
00575      * @param other the functor to be copied
00576      * @return a reference to this functor object
00577      */
00578     translationScaleEstimator& operator=(const translationScaleEstimator& other);
00579 
00580     /**
00581      * Returns a pointer to a clone of this functor.
00582      */
00583     virtual functor* clone() const;
00584 
00585     /**
00586      * Returns used parameters
00587      */
00588     const parameters& getParameters() const;
00589 
00590   };
00591 
00592   // -------------------------------------------------------------------
00593   // The transform-methods! no t-helper due to efficiency here
00594   // -------------------------------------------------------------------
00595 
00596   inline fpoint translationScaleEstimator
00597     ::transform(const fpoint& pt, const fvector& transf) const {
00598     
00599     fpoint res;
00600     fvector::const_iterator it ( transf.begin() );
00601     res.x = *it * pt.x;
00602     res.y = *it * pt.y;
00603     res.x += *(++it);
00604     res.y += *(++it);
00605  
00606     return res;
00607   }
00608   
00609   inline dpoint  translationScaleEstimator
00610     ::transform(const dpoint& pt, const dvector& transf) const {
00611    
00612     dpoint res;
00613     dvector::const_iterator it ( transf.begin() );
00614     res.x = *it * pt.x;
00615     res.y = *it * pt.y;
00616     res.x += *(++it);
00617     res.y += *(++it);
00618     
00619     return res;
00620   }
00621 }
00622 
00623 #endif

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