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

ltiShiftInvariance.h

00001 /*
00002  * Copyright (C) 2001, 2002, 2003, 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 Digital Image/Signal Processing Library
00026  * file .......: ltiShiftInvariance.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 31.5.2001
00030  * revisions ..: $Id: ltiShiftInvariance.h,v 1.10 2007/01/10 02:26:06 alvarado Exp $
00031  */
00032 
00033 #ifndef _LTI_SHIFT_INVARIANCE_H_
00034 #define _LTI_SHIFT_INVARIANCE_H_
00035 
00036 #include "ltiImage.h"
00037 #include "ltiVector.h"
00038 
00039 #include "ltiGlobalFeatureExtractor.h"
00040 
00041 namespace lti {
00042 
00043   /**
00044    * This functor takes a vector, which is supposed to be periodic, and
00045    * generates a second "normalized" shifted one.  It uses different modi.
00046    *
00047    * This first one uses the property of the fourier transform to represent a
00048    * vector "shift" as the addition of a factor k*w (w=2*Pi*f) to the
00049    * phase of its representation in the frecuency space.  To get rid
00050    * of this term, the phase is twice derived, and the result is
00051    * subracted from the first order derivative.  This resulting vector
00052    * should represent a constant value k, but due to the phase
00053    * "discontinuities" is not the case.  The average of the vector
00054    * values which lie in a given tolerance interval will be used to
00055    * calculate the shift.
00056    *
00057    * This hasn't beed documented anywere
00058    *
00059    * The second one calculates and centers the first momentum of the
00060    * cyclic vector at the position 0
00061    */
00062   class shiftInvariance : public globalFeatureExtractor {
00063   public:
00064     /**
00065      * the parameters for the class shiftInvariance
00066      */
00067     class parameters : public globalFeatureExtractor::parameters {
00068     public:
00069       /**
00070        * default constructor
00071        */
00072       parameters();
00073 
00074       /**
00075        * copy constructor
00076        * @param other the parameters object to be copied
00077        */
00078       parameters(const parameters& other);
00079 
00080       /**
00081        * destructor
00082        */
00083       ~parameters();
00084 
00085       /**
00086        * returns name of this type
00087        */
00088       const char* getTypeName() const;
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& copy(const parameters& other);
00096 
00097       /**
00098        * copy the contents of a parameters object
00099        * @param other the parameters object to be copied
00100        * @return a reference to this parameters object
00101        */
00102       parameters& operator=(const parameters& other);
00103 
00104 
00105       /**
00106        * returns a pointer to a clone of the parameters
00107        */
00108       virtual functor::parameters* clone() const;
00109 
00110       /**
00111        * write the parameters in the given ioHandler
00112        * @param handler the ioHandler to be used
00113        * @param complete if true (the default) the enclosing begin/end will
00114        *        be also written, otherwise only the data block will be written.
00115        * @return true if write was successful
00116        */
00117       virtual bool write(ioHandler& handler,const bool complete=true) const;
00118 
00119       /**
00120        * write the parameters in the given ioHandler
00121        * @param handler the ioHandler to be used
00122        * @param complete if true (the default) the enclosing begin/end will
00123        *        be also written, otherwise only the data block will be written.
00124        * @return true if write was successful
00125        */
00126       virtual bool read(ioHandler& handler,const bool complete=true);
00127 
00128 #     ifdef _LTI_MSC_6
00129       /**
00130        * this function is required by MSVC only, as a workaround for a
00131        * very awful bug, which exists since MSVC V.4.0, and still by
00132        * V.6.0 with all bugfixes (so called "service packs") remains
00133        * there...  This method is also public due to another bug, so please
00134        * NEVER EVER call this method directly: use read() instead
00135        */
00136       bool readMS(ioHandler& handler,const bool complete=true);
00137 
00138       /**
00139        * this function is required by MSVC only, as a workaround for a
00140        * very awful bug, which exists since MSVC V.4.0, and still by
00141        * V.6.0 with all bugfixes (so called "service packs") remains
00142        * there...  This method is also public due to another bug, so please
00143        * NEVER EVER call this method directly: use write() instead
00144        */
00145       bool writeMS(ioHandler& handler,const bool complete=true) const;
00146 #     endif
00147 
00148       // ------------------------------------------------
00149       // the parameters
00150       // ------------------------------------------------
00151 
00152       /**
00153        * Shift invariance mode
00154        */
00155       enum eMode {
00156         Fourier, /**< Try to eliminate the phase term caused by signal
00157                       shift */
00158         Momentum /**< Shift the signal in a way that the first cyclic momentum
00159                       is position at 0 */
00160       };
00161 
00162       /**
00163        * the mode to be used.
00164        * Default value: Momentum
00165        */
00166       eMode mode;
00167 
00168     };
00169 
00170     /**
00171      * default constructor
00172      */
00173     shiftInvariance();
00174 
00175     /**
00176      * copy constructor
00177      * @param other the object to be copied
00178      */
00179     shiftInvariance(const shiftInvariance& other);
00180 
00181     /**
00182      * destructor
00183      */
00184     virtual ~shiftInvariance();
00185 
00186     /**
00187      * returns the name of this type ("shiftInvariance")
00188      */
00189     virtual const char* getTypeName() const;
00190 
00191     //TODO: comment your apply methods!
00192 
00193     /**
00194      * operates on the given %parameter.
00195      * @param srcdest dvector with the source data.  The result
00196      *                 will be left here too.
00197      * @return true if apply successful or false otherwise.
00198      */
00199     bool apply(dvector& srcdest) const;
00200 
00201     /**
00202      * operates on a copy of the given %parameters.
00203      * @param src dvector with the source data.
00204      * @param dest dvector where the result will be left.
00205      * @return true if apply successful or false otherwise.
00206      */
00207     bool apply(const dvector& src,dvector& dest) const;
00208 
00209     /**
00210      * operates on a copy of the given %parameters.
00211      * @param src dvector with the source data.
00212      * @param dest dvector where the result will be left.
00213      * @param shft will contain the number of elements the vector was
00214      *             shifted
00215      * @return true if apply successful or false otherwise.
00216      */
00217     bool apply(const dvector& src,dvector& dest,int& shft) const;
00218 
00219     /**
00220      * copy data of "other" functor.
00221      * @param other the functor to be copied
00222      * @return a reference to this functor object
00223      */
00224     shiftInvariance& copy(const shiftInvariance& other);
00225 
00226     /**
00227      * returns a pointer to a clone of this functor.
00228      */
00229     virtual functor* clone() const;
00230 
00231     /**
00232      * returns used parameters
00233      */
00234     const parameters& getParameters() const;
00235 
00236   private:
00237     /**
00238      * returns the angle normalized to the interval 0..2Pi
00239      */
00240     double normAngle(const double& x) const;
00241 
00242     /**
00243      * operates on a copy of the given %parameters.
00244      * @param src dvector with the source data.
00245      * @param dest dvector where the result will be left.
00246      * @return true if apply successful or false otherwise.
00247      *
00248      * The derivatives of first and second order will be computed directly
00249      * from the phase of the fourier transform of the source.
00250      */
00251     bool direct(const dvector& src,dvector& dest,int& shft) const;
00252 
00253     /**
00254      * operates on a copy of the given %parameters.
00255      * @param src dvector with the source data.
00256      * @param dest dvector where the result will be left.
00257      * @return true if apply successful or false otherwise.
00258      *
00259      * Shift will be calculated based on the first momentum.
00260      */
00261     bool momentum(const dvector& src,dvector& dest,int& shft) const;
00262 
00263     /**
00264      * operates on a copy of the given %parameters.
00265      * @param src dvector with the source data.
00266      * @param dest dvector where the result will be left.
00267      * @return true if apply successful or false otherwise.
00268      *
00269      * The derivatives of first and second order will be computed indirectly
00270      * through the cosine and sine of the phase.  There are still some
00271      * theoretical problems with this method, but it works fine.
00272      *
00273      * This is much slower than the direct method, and it requires much more
00274      * memory.
00275      *
00276      */
00277     bool arctan(const dvector& src,dvector& dest,int& shft) const;
00278 
00279     /**
00280      * consider discontinuities in the magnitud to interpolate
00281      * missing phase elements
00282      */
00283     bool fixArg(const dvector& mag,dvector& arg) const;
00284 
00285     /**
00286      * cyclic shift of the given vector
00287      */
00288     bool shift(const dvector& in,const int& shft,dvector& out) const;
00289   };
00290 }
00291 
00292 #endif

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