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

ltiOpticalFlowHS.h

00001 /*
00002  * Copyright (C) 2000, 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 .......: ltiOpticalFlowHS.h
00027  * authors ....: Bernd Mussmann, Suat Akyol
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 15.8.2000
00030  * revisions ..: $Id: ltiOpticalFlowHS.h,v 1.5 2006/02/08 11:34:57 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_OPTICAL_FLOW_HS_H_
00034 #define _LTI_OPTICAL_FLOW_HS_H_
00035 
00036 // include files which are needed in this header!!
00037 
00038 #include "ltiGradientKernels.h"
00039 #include "ltiConvolution.h"
00040 #include "ltiSequence.h"
00041 #include "ltiGaussKernels.h"
00042 #include "ltiDownsampling.h"
00043 #include "ltiFilledUpsampling.h"
00044 
00045 // include parent class:
00046 #include "ltiTransform.h"
00047 
00048 namespace lti {
00049   /**
00050    * Computes the optical flow between two consecutive images
00051    * according to Horn-Schunks gradient based method. Optical
00052    * flow is determined by velocity components u, v, which are
00053    * searched to complete the optical flow equation:
00054    *
00055    * I(x+u*delta_t, y+v*delta_t, t+delta_t) = I(x,y,t) + e
00056    *
00057    * I=intensity function, t=timeindex, x/y=coordinates, e=error
00058    *
00059    *
00060    * Theory: "The Computation of Optical Flow", Beauchemin & Barron,
00061    * ACM Computing Surveys, Vol.27 No. 3
00062    *
00063    * Algorithm: "Computer Vision", Klette, Schluens & koschan, Springer, pp.190
00064    */
00065   class opticalFlowHS : public transform {
00066   public:
00067     /**
00068      * the parameters for the class opticalFlowHS
00069      */
00070     class parameters : public transform::parameters {
00071     public:
00072       /**
00073        * default constructor
00074        */
00075       parameters();
00076 
00077       /**
00078        * copy constructor
00079        * @param other the parameters object to be copied
00080        */
00081       parameters(const parameters& other);
00082 
00083       /**
00084        * destructor
00085        */
00086       ~parameters();
00087 
00088       /**
00089        * returns name of this type
00090        */
00091       const char* getTypeName() const;
00092 
00093       /**
00094        * copy the contents of a parameters object
00095        * @param other the parameters object to be copied
00096        * @return a reference to this parameters object
00097        */
00098       parameters& copy(const parameters& other);
00099 
00100       /**
00101        * returns a pointer to a clone of the parameters
00102        */
00103       virtual functor::parameters* clone() const;
00104 
00105       //  parameters of functor
00106 
00107       /**
00108        * Size of kernel for spatial gradient computation.
00109        * kernelSize = 3,4,5 (default=3)
00110        */
00111       int kernelSize;
00112 
00113       /**
00114        * Number of iterations.
00115        * iterations = 1,2,... (default=100)
00116        */
00117       int iterations;
00118 
00119       /**
00120        * Smoothness constraint factor.
00121        * lambda > 0.0 (default = 10.0)
00122        *
00123        * The solutions (u,v) of the optical flow equation are ambiguous.
00124        * The additional "smoothness-constraint" allows to select a solution
00125        * conditional on the desired smoothness of the flowfield. Smoothness
00126        * is controlled by parameter 'lambda'. Higher values produce
00127        * smoother flowfields but also higher error e.
00128       */
00129       float lambda;
00130 
00131       /**
00132        * Toggles multi scale approach for computation of optical flow.
00133        * (default = true)
00134        *
00135        * If multiScale==true, then the two input images are sampled down to
00136        * several scale levels, before the optical flow is computed iteratively
00137        * from coarse to fine resolution. This approach allows faster computation
00138        * and can cope with large motion.
00139        * Remark: The number of scale levels can vary, since it depends on the
00140        * number of iterations and the original image size.
00141       */
00142       bool multiScale;
00143 
00144       /**
00145        * If you want to hand over previously calculated flow results (u,v) as initial values
00146        * of iterative flow computation, then this must be set to 'true'. Otherwise initial
00147        * values will always be 0.
00148        * (default = false)
00149        * Remark: previous results must be passed as function parameters with the 'on copy apply'.
00150        * (u,v) must be equal sized to input channels ch_t0, ch_t1, or else they will be ignored.
00151       */
00152       bool initialize;
00153     };
00154 
00155     /**
00156      * default constructor
00157      */
00158     opticalFlowHS();
00159 
00160     /**
00161      * copy constructor
00162      * @param other the object to be copied
00163      */
00164     opticalFlowHS(const opticalFlowHS& other);
00165 
00166     /**
00167      * destructor
00168      */
00169     virtual ~opticalFlowHS();
00170 
00171     /**
00172      * returns the name of this type ("opticalFlowHS")
00173      */
00174     virtual const char* getTypeName() const;
00175 
00176     /**
00177      * operates on the given parameter.
00178      * @param ch_t0_u channel at timeindex 0.
00179      * @param ch_t1_v channel at timeindex 1. Note that ch_t0 is the predecessor of ch_t1.
00180      * u,v (x,y components of flowfield) are returned in ch_t0_u, ch_t1_v
00181      */
00182     void apply(channel& ch_t0_u,channel& ch_t1_v) const;
00183 
00184     /**
00185      * operates on a copy of the given parameters.
00186      * @param ch_t0 channel at timeindex 0.
00187      * @param ch_t1 channel at timeindex 1. Note that ch_t0 is the predecessor of ch_t1.
00188      * @param u x component of flowfield
00189      * @param v y component of flowfield
00190      */
00191     void apply(const channel& ch_t0,
00192                const channel& ch_t1,
00193                channel& u,
00194                channel& v) const;
00195 
00196     /**
00197      * copy data of "other" functor.
00198      * @param other the functor to be copied
00199      * @return a reference to this functor object
00200      */
00201     opticalFlowHS& copy(const opticalFlowHS& other);
00202 
00203     /**
00204      * returns a pointer to a clone of this functor.
00205      */
00206     virtual functor* clone() const;
00207 
00208     /**
00209      * returns used parameters
00210      */
00211     const parameters& getParameters() const;
00212 
00213     private:
00214 
00215     /**
00216      * Implements functionality of optical flow computation.
00217      * Uses Horn-Schunck Method with given %parameters, except
00218      * for '%parameter.iterations', which is replaced by the
00219      * function call %parameter. Iteration is always initialized
00220      * with (u,v), which MUST have same size as ch_t0 and ch_t1.
00221      */
00222     void computeOpticalFlow(const channel& ch_t0,
00223                             const channel& ch_t1,
00224                             channel& u,
00225                             channel& v,
00226                             int iterations) const;
00227 
00228     /**
00229      * Will be used, when multi scale approach is desired.
00230      * Calls the function 'computeOpticalFlow' for each sampling
00231      * level.
00232      */
00233     void computeMultiScaled(const channel& ch_t0,
00234                             const channel& ch_t1,
00235                             channel& u,
00236                             channel& v) const;
00237 
00238     /**
00239      * Will be used, when single scale approach is desired.
00240      * Calls the function 'computeOpticalFlow' once.
00241      */
00242     void computeSingleScaled(const channel& ch_t0,
00243                              const channel& ch_t1,
00244                              channel& u,
00245                              channel& v) const;
00246 
00247   };
00248 }
00249 
00250 #endif

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