latest version v1.9 - last update 10 Apr 2010 |
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 .......: ltiGaborKernels.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 28.04.00 00030 * revisions ..: $Id: ltiGaborKernels.h,v 1.3 2006/02/08 11:09:24 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_GABORKERNELS_H_ 00034 #define _LTI_GABORKERNELS_H_ 00035 00036 #include "ltiLinearKernels.h" 00037 00038 namespace lti { 00039 /** two-dimensional gabor filter kernel 00040 00041 The Gabor kernels are defined by the following equation: 00042 00043 \f$ f_{mn}(x,y) = 00044 \frac{1}{2\pi\sigma^2}\exp(-\frac{x^2+y^2}{2\sigma_m^2}) 00045 \cos\left(\omega_mx\cos\theta_n+\omega_my\sin\theta_n \right) \f$ 00046 00047 The index m denotes the "band" of the filter (which variance it uses) 00048 and the index n the direction of the filter. 00049 00050 For this implementation, the volume under the gauss function for the 00051 specified size will be normalized to 1. The result will be modulated 00052 with the given direction and frequency. 00053 00054 Due to the nature of this filter, avoid its use with unsigned byte 00055 channels! (no lti::channel8, only lti::channel). 00056 00057 You can use an approximation of this kern as separable filter 00058 (see lti::sepKernel<T>::separate()), or you can use the 00059 lti::gaborKernelSep as a two-filter-pair separable filter. 00060 00061 Example: 00062 00063 \code 00064 // the channel to be filtered: 00065 lti::channel data; 00066 00067 // ... initialize channel here ... 00068 00069 // gabor filter kernel with 7 elements, a variance of 1.0, frequency 00070 // of 0.5 and 45° 00071 lti::gaborKernel<channel::value_type> kernel(7,1.0,0.5,45.0*Pi/180.0); 00072 00073 lti::convolution filter; // convolution operator 00074 lti::convolution::parameters param; // parameters 00075 param.setKernel(kernel); // use the gabor kernel 00076 filter.setParameters(param); // set parameters 00077 00078 // filter the data and leave the result there too 00079 filter.apply(data); 00080 \endcode 00081 */ 00082 template<class T> 00083 class gaborKernel : public kernel2D<T> { 00084 public: 00085 /** constructor 00086 @param size is the number of elements pro dimension (i.e. the 00087 filter kern is a 'size x size' kernel!) 00088 @param theVariance variance of the kernel 00089 @param frequency the angular frequency to be modulated with 00090 (in radians per line) 00091 @param angle the angle to modulate the gaussian function (in radians) 00092 */ 00093 gaborKernel(const int& size, 00094 const double& theVariance, 00095 const double& frequency, 00096 const double& angle); 00097 00098 /** initialize this kernel with the specified values 00099 @param size size of the kernel in one dimension 00100 @param theVariance variance of the kernel 00101 @param frequency the angular frequency to be modulated with 00102 (in radians per line) 00103 @param angle the angle to modulate the gaussian function (in radians) 00104 */ 00105 void generate(const int& size, 00106 const double& theVariance, 00107 const double& frequency, 00108 const double& angle); 00109 }; 00110 00111 /** two-dimensional separable gabor filter kernel 00112 00113 The Gabor kernels are defined by the following equation: 00114 00115 \f$ f_{mn}(x,y) = 00116 \frac{1}{2\pi\sigma^2}\exp(-\frac{x^2+y^2}{2\sigma_m^2}) 00117 \cos\left(\omega_mx\cos\theta_n+\omega_my\sin\theta_n \right) \f$ 00118 00119 The index m denotes the "band" of the filter (which variance it uses) 00120 and the index n the direction of the filter. 00121 00122 This kernel can be expressed also as: 00123 \f$ f_{mn} = h_1(x)h_2(x)-h_3(x)h_4(x)\f$ 00124 00125 This two-filter-pair separation property is used in this implementation. 00126 00127 Due to the nature of this filter, avoid its use with unsigned byte 00128 channels! (no lti::channel8, only lti::channel). 00129 00130 Example: 00131 00132 00133 \code 00134 // the channel to be filtered: 00135 lti::channel data; 00136 00137 // ... initialize channel here ... 00138 00139 // gabor filter kernel with 7 elements, a variance of 1.0, frequency 00140 // of 0.5 and 45° 00141 lti::gaborKernelSep<channel::value_type> kernel(3,1.0,0.5,45*Pi/180.0); 00142 00143 lti::convolution filter; // convolution operator 00144 lti::convolution::parameters param; // parameters 00145 param.setKernel(kernel); // use the gauss kernel 00146 filter.setParameters(param); // set parameters 00147 00148 // filter the vector and leave the result there too 00149 00150 filter.apply(data); 00151 \endcode 00152 00153 Generally, it is faster to use the separable kernel for kernel 00154 dimension bigger or equal han 5x5. 00155 */ 00156 template<class T> 00157 class gaborKernelSep : public sepKernel<T> { 00158 public: 00159 /** constructor 00160 @param size is the number of elements pro dimension (i.e. the 00161 filter kern is a 'size x size' kernel!) 00162 @param theVariance variance of the kernel 00163 @param frequency the angular frequency to be modulated with 00164 (in radians per line) 00165 @param angle the angle to modulate the gaussian function (in radians) 00166 */ 00167 gaborKernelSep(const int& size, 00168 const double& theVariance, 00169 const double& frequency, 00170 const double& angle); 00171 00172 /** initialize this kernel with the specified values 00173 @param size size of the kernel in one dimension 00174 @param theVariance variance of the kernel 00175 @param frequency the angular frequency to be modulated with 00176 (in radians per line) 00177 @param angle the angle to modulate the gaussian function (in radians) 00178 */ 00179 void generate(const int& size, 00180 const double& theVariance, 00181 const double& frequency, 00182 const double& angle); 00183 }; 00184 00185 } 00186 00187 #include "ltiGaborKernels_template.h" 00188 00189 #endif