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

ltiGaussKernels.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 .......: ltiGaussKernels.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 28.04.00
00030  * revisions ..: $Id: ltiGaussKernels.h,v 1.6 2006/02/08 11:09:58 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_GAUSSKERNELS_H_
00034 #define _LTI_GAUSSKERNELS_H_
00035 
00036 #include "ltiLinearKernels.h"
00037 
00038 namespace lti {
00039   /**
00040    * one-dimensional filter kernel
00041    *
00042    *  This class will create a one-dimensional gaussian filter kernel.
00043    *
00044    *  The area under the filter will be normalized to one.
00045    *
00046    *  The one dimesional kernel is calculated with following equation:
00047    *
00048    *  \f$ g(x) = \frac{1}{\sigma \sqrt{2\pi}} \exp{-\frac{x^2}{2\sigma^2}}\f$
00049    *
00050    *  Example:
00051    *
00052    *  \code
00053    *  // the vector to be filtered:
00054    *  lti::vector<channel::value_type> data;
00055    *
00056    *  // ... initialize vector here ...
00057    *
00058    *  // gaussian filter kernel with 3 elements, and a variance of 0.72
00059    *  lti::gaussKernel1D<channel::value_type> kernel(3,0.72);
00060    *
00061    *  lti::convolution filter;                        // convolution operator
00062    *  lti::convolution::parameters param;             // parameters
00063    *  param.setKernel(kernel);                        // use the gauss kernel
00064    *  filter.setParameters(param);                    // set parameters
00065    *
00066    *  // filter the vector and leave the result there too
00067    *
00068    *  filter.apply(data);
00069    *  \endcode
00070    */
00071   template<class T>
00072   class gaussKernel1D : public kernel1D<T> {
00073   public:
00074     /**
00075      * constructor
00076      * @param size size of the kernel in one dimension
00077      * @param variance variance of the kernel.  If this argument is
00078      *        ommited or a negative value is given, the variance will
00079      *        be calculated such that the value at the index floor(size/2)
00080      *        is 1/(1+floor(size/2)) times the value at index 0.
00081      *        For example, for size==3, the value at 1 will be 1/2 the value
00082      *        at 0.
00083      *        Hence a 3 taps kernel will contain the elements (1/4,1/2,1/4).
00084      */
00085     gaussKernel1D(const int& size = 3,
00086                   const double& variance = -1.0);
00087 
00088     /** initialize this kernel with the specified values
00089      * @param size size of the kernel in one dimension
00090      * @param theVariance variance of the kernel. If this argument is
00091      *        ommited or a negative value is given, the variance will
00092      *        be calculated such that the value at the index floor(size/2)
00093      *        is 1/(1+floor(size/2)) times the value at index 0.
00094      *        For example, for size==3, the value at 1 will be 1/2 the value
00095      *        at 0.
00096      *        Hence a 3 taps kernel will contain the elements (1/4,1/2,1/4).
00097      */
00098     void generate(const int& size,
00099                   const double& theVariance=-1.0);
00100 
00101     /**
00102      * Returns the actual variance used for generating the
00103      * kernel. This is helpful if a negative value was given in the
00104      * generation.
00105      */
00106     const double& getActualVariance() const;
00107   protected:
00108     double variance;
00109   };
00110 
00111   /** 
00112    * Two-dimensional Gaussian filter kernel
00113    *
00114    * Gaussian kernels are separable, and will be created this way!
00115    * (@see  gaussKernel1D)
00116    *
00117    * You can create a "real" 2D kernel with the following code
00118    *
00119    * \code
00120    * lti::gaussKernel2D<float> gauss(5); // a kernel 5x5 with default variance
00121    * lti::kernel2D<float>      kern;     // a 2D kernel;
00122    * 
00123    * kern.castFrom(gauss);
00124    * \endcode
00125    *
00126    * but note that the convolution of this kernel with a channel is less
00127    * efficient than convolving its separable version.
00128    *
00129    * To convolve this filter with a channel follow the next example
00130    *
00131    * \code
00132    * // the channel to be filtered:
00133    * lti::channel data;
00134    *
00135    * // ... initialize channel here ...
00136    *
00137    * // gauss filter kernel with dimensions 5x5, and a variance of 1.3
00138    * lti::gaussKernel2D<lti::channel::value_type> kernel(5,1.3);
00139    *
00140    * lti::convolution filter;                        // convolution operator
00141    * lti::convolution::parameters param;             // parameters
00142    * param.setKernel(kernel);                        // use the gauss kernel
00143    * filter.setParameters(param);                    // set parameters
00144    *
00145    * // filter the channel and leave the result there too
00146    * filter.apply(data);
00147    * 
00148    * \endcode
00149    *
00150    * You can also use following shortcut, if you can use the default
00151    * boundary type for the convolution:
00152    *
00153    * \code
00154    * // gauss filter kernel with dimensions 5x5, and a variance of 1.3
00155    * lti::gaussKernel2D<lti::channel::value_type> kernel(5,1.3);
00156    *
00157    * lti::convolution filter(kernel);                // convolution operator
00158    *
00159    * // filter the channel and leave the result there too
00160    * filter.apply(data);
00161    *
00162    * \endcode
00163    */
00164   template<class T>
00165   class gaussKernel2D : public sepKernel<T> {
00166   public:
00167     /**
00168      * constructor
00169      * @param size is the dimension of the one dimensional part (i.e. the
00170      *             filter kern is a size x size kernel!)
00171      * @param theVariance variance of the kernel.  If negative, a default
00172      *             value from the given size will be computed 
00173      *             (see lti::gaussKernel1D<T>)
00174      */
00175     gaussKernel2D(const int& size = 3,
00176                   const double& theVariance =  1.4426950409);
00177 
00178     /** 
00179      * initialize this kernel with the specified values
00180      * @param size size of the kernel in one dimension
00181      * @param theVariance variance of the kernel.  If negative, a default
00182      *                    value from the given size will be computed 
00183      *                    (see lti::gaussKernel1D<T>)
00184      */
00185     void generate(const int& size,
00186                   const double& theVariance);
00187 
00188     /**
00189      * Returns the actual variance used for generating the
00190      * kernel. This is helpful if a negative value was given in the
00191      * generation.
00192      */
00193     const double& getActualVariance() const;
00194   protected:
00195     double variance;
00196   };
00197 }
00198 
00199 #include "ltiGaussKernels_template.h"
00200 
00201 #endif

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