latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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 .......: ltiLaplacianKernel.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 17.11.2003 00030 * revisions ..: $Id: ltiLaplacianKernel.h,v 1.3 2006/02/08 11:21:53 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_LAPLACIAN_KERNELS_H_ 00034 #define _LTI_LAPLACIAN_KERNELS_H_ 00035 00036 #include "ltiLinearKernels.h" 00037 00038 namespace lti { 00039 /** 00040 * Two-dimensional kernels to compute the Laplacian 00041 * 00042 * The Laplacian is defined as: 00043 * 00044 * \f[\nabla^2f = \frac{\partial^2f}{\partial x^2} + 00045 * \frac{\partial^2f}{\partial y^2}\f] 00046 * 00047 * This class will create a two-dimensional filter kernel that can be 00048 * applied with lti::convolution to any channel, in order to compute 00049 * the Laplacian of that channel. 00050 * 00051 * Please note that only kernels of "float" are provided, since ubyte 00052 * channels cannot represent negative values. 00053 * 00054 * There are three posibilities for the kernel dimensions 3x3, 5x5 or 9x9. 00055 * 00056 * The 3x3 is the standard kernel: 00057 * \code 00058 * 0 1 0 00059 * 1 -4 1 00060 * 0 1 0 00061 * \endcode 00062 * 00063 * There is another 3x3 Laplacian kernel based on a polynomial quadratic 00064 * least-square-error surface passing through the 3x3 grid (this can 00065 * generated giving the size "2" (from quadratic) ): 00066 * \code 00067 * 0.2 0.1 0.2 00068 * 0.1 -1.2 0.1 00069 * 0.2 0.1 0.2 00070 * \endcode 00071 * 00072 * We designed kernel with following approach: 00073 * 00074 * - Approximate the 3x3 with a quadratic surface that passes exactly 00075 * through the middle point of the grid. 00076 * The quadratic function has the form: 00077 * q(x,y) = a*x^2 + b*x*y + c*y^2 + d*x + e*y + f 00078 * - Assume, without loss of generality, that the center point has 00079 * coordinates (0,0). 00080 * Since the surface goes through the middle point we got the term f. 00081 * - We have now five coefficients to be determined with eight values of 00082 * the neighbors. We can solve this problem with standard SVD methods. 00083 * - With the SVD we can compute the terms for a, b, c, d and e that 00084 * minimize the quadratic error, in terms of a matrix that does not depend 00085 * on the values of the grid itself. 00086 * - Since the Hessian matrix for the surface is composed of the a,c and b/2 00087 * terms, and the Hessian matrix represents the second order derivatives 00088 * of the surface, we can use this values directly to compute our kernel. 00089 * 00090 * The 5x5 and 9x9 kernels are based on the gradient operators 00091 * defined by Ando in its paper "Consistent Gradient Operators" 00092 * (IEEE PAMI, Vol. 22, No. 3, March 2000). With this gradients, the 00093 * operators for the second derivatives are computed and added. 00094 * From the 3x3 gradient kernel is generated the 5x5 Laplacian one, and from 00095 * the 5x5 kernel the 9x9 Laplacian one. 00096 * 00097 * These kernels are not directly separable and therefore implemented as 00098 * two-dimensional ones. You can approximate the separability with the 00099 * separate() methods of the sepKernel<T> class. 00100 * 00101 * @ingroup gLinearFilters 00102 */ 00103 class laplacianKernel : public kernel2D<float> { 00104 public: 00105 /** 00106 * constructor 00107 * @param size is the dimension of the one dimensional part (i.e. the 00108 * filter kern is a size x size kernel!) 00109 * The valid values are 2, 3, 5 or 9. If an invalid value is 00110 * given, an empty kernel will be created. 00111 * Note that "2" generates the 3x3 "quadratic" kernel 00112 * approximation. 00113 */ 00114 laplacianKernel(const int size = 3); 00115 00116 /** 00117 * Initialize this kernel with the specified values. 00118 * 00119 * @param size size of the kernel in one dimension. The valid 00120 * values are 3, 5 or 9. If an invalid value is given, an 00121 * empty kernel will be created. 00122 */ 00123 void generate(const int size); 00124 }; 00125 } 00126 #endif