00001 /*!@file Image/Convolutions.H basic 1-D and 2-D filtering operations */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/Convolutions.H $ 00035 // $Id: Convolutions.H 8643 2007-07-27 18:15:43Z rjpeters $ 00036 // 00037 00038 #ifndef IMAGE_CONVOLUTIONS_H_DEFINED 00039 #define IMAGE_CONVOLUTIONS_H_DEFINED 00040 00041 #include "Image/Image.H" 00042 #include "Util/Promotions.H" 00043 00044 class Dims; 00045 template <class T> class Image; 00046 00047 enum ConvolutionBoundaryStrategy 00048 { 00049 CONV_BOUNDARY_ZERO, ///< zero-pad, a.k.a. truncated 00050 CONV_BOUNDARY_CLEAN, ///< normalize by the sum of the used filter coefficients 00051 CONV_BOUNDARY_REPLICATE ///< replicate the nearest image pixel value 00052 }; 00053 00054 //! Brute force, super inefficient 2D convolution, with C filter of Nx*Ny 00055 template <class T_or_RGB> 00056 Image<typename promote_trait<T_or_RGB, float>::TP> 00057 convolve(const Image<T_or_RGB>& src, const float* filter, 00058 const int Nx, const int Ny, 00059 ConvolutionBoundaryStrategy boundary); 00060 00061 //! Brute force, super inefficient 2D convolution 00062 template <class T_or_RGB> inline 00063 Image<typename promote_trait<T_or_RGB, float>::TP> 00064 convolve(const Image<T_or_RGB>& src, const Image<float>& filter, 00065 ConvolutionBoundaryStrategy boundary) 00066 { 00067 return convolve(src, filter.getArrayPtr(), 00068 filter.getWidth(), filter.getHeight(), boundary); 00069 } 00070 00071 //! This is a somewhat-optimized 2-D convolution. 00072 /*! It is optimized in the sense that there are special-case inner loops 00073 for (1) cases where the filter doesn't completely overlap with the 00074 local image patch because we're at the image boundary (in this case 00075 we need a specialized inner loop to handle these boundary 00076 conditions), and (2) cases where the filter and local image patch 00077 overlap completely (in which case we can use a more efficient inner 00078 loop). */ 00079 template <class T> 00080 Image<typename promote_trait<T, float>::TP> 00081 optConvolve(const Image<T>& src, const Image<float>& filter); 00082 00083 //! Brute force, super inefficient 2D convolution (truncated filter boundary) 00084 /*! With normalization by the local image energy, a la HMAX */ 00085 template <class T> 00086 Image<typename promote_trait<T, float>::TP> 00087 convolveHmax(const Image<T>& src, const Image<float>& filter); 00088 00089 //! Separable filter, any size (size=0 for no filter) 00090 /*! If you want to do horizontal-only or vertical-only filtering, then 00091 simply pass an empty filter (i.e., Image<float>()) for the other filter. 00092 00093 @param boundary controls the boundary-handling strategy (i.e., 00094 zero-fill, clean, replicate) 00095 00096 HISTORICAL NOTE: This function takes over for what used to be many 00097 functions, including sepFilter(), sepFiltClean(), xFilter(), 00098 yFilter(), xFilterClean(), and yFilterClean(). First, the x+y 00099 variants are now collapsed into a single function; if you want 00100 x-only or y-only filtering, simply pass an empty image for the 00101 other filter. Second, the functions are collapsed across boundary 00102 handling strategy, where you can now select the boundary strategy 00103 at run-time with the ConvolutionBoundaryStrategy parameter. 00104 */ 00105 template <class T_or_RGB> 00106 Image<typename promote_trait<T_or_RGB, float>::TP> 00107 sepFilter(const Image<T_or_RGB>& src, const Image<float>& hFilter, 00108 const Image<float>& vFilter, 00109 ConvolutionBoundaryStrategy boundary); 00110 00111 template <class T_or_RGB> 00112 Image<typename promote_trait<T_or_RGB, float>::TP> 00113 sepFilter(const Image<T_or_RGB>& src, const float* hFilter, 00114 const float* vFilter, const int hfsize, const int vfsize, 00115 ConvolutionBoundaryStrategy boundary); 00116 00117 // ###################################################################### 00118 /* So things look consistent in everyone's emacs... */ 00119 /* Local Variables: */ 00120 /* mode: c++ */ 00121 /* indent-tabs-mode: nil */ 00122 /* End: */ 00123 00124 #endif // IMAGE_CONVOLUTIONS_H_DEFINED