
00001 /*!@file Image/PyramidOps.H Free functions operating on pyramid data structures */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // 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: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/PyramidOps.H $ 00035 // $Id: PyramidOps.H 9412 2008-03-10 23:10:15Z farhan $ 00036 // 00037 00038 #ifndef IMAGE_PYRAMIDOPS_H_DEFINED 00039 #define IMAGE_PYRAMIDOPS_H_DEFINED 00040 00041 #include "Image/Convolutions.H" 00042 #include "Image/PyramidTypes.H" 00043 #include "Util/Promotions.H" 00044 #include "Util/Types.H" 00045 00046 template <class T> class Point2D; 00047 template <class T> class Image; 00048 template <class T> class ImageSet; 00049 00050 // ############################################################ 00051 // ##### Dyadic pyramid pixel operations: 00052 // ############################################################ 00053 00054 //! Get value of a pixel from a dyadic pyramid at a given level and coordinates 00055 /*! @param pix The pixel value returned 00056 @param p Coordinates given at scale 0 (base pyramid level); 00057 bilinear interpolation will be used to compute pixel value at 00058 given level. 00059 @param lev The pyramid level to get the pixel value from. */ 00060 template <class T_or_RGB> 00061 T_or_RGB getPyrPixel(const ImageSet<T_or_RGB>& pyr, 00062 const Point2D<int>& p, const uint lev); 00063 00064 //! Get value of a pixel from a dyadic pyramid at a given level and coordinates, no interpolation 00065 /*! @param pix The pixel value returned 00066 @param p Coordinates given at scale 0 (base pyramid level); 00067 This version does not use interpolation. 00068 @param lev The pyramid level to get the pixel value from. */ 00069 template <class T_or_RGB> 00070 T_or_RGB getPyrPixelNI(const ImageSet<T_or_RGB>& pyr, 00071 const Point2D<int>& p, const uint lev); 00072 00073 //! Get value of a pixel from a dyadic pyramid with trilinear interpolation 00074 template <class T_or_RGB> 00075 T_or_RGB getPyrPixel(const ImageSet<T_or_RGB>& pyr, 00076 const float x, const float y, const float z); 00077 00078 // ############################################################ 00079 // ##### Pyramid builder functions: 00080 // ############################################################ 00081 00082 //! Uses a Gaussian filter of size \a filterSize. 00083 template <class T_or_RGB> 00084 ImageSet<T_or_RGB> buildPyrGaussian(const Image<T_or_RGB>& image, 00085 int firstlevel, int depth, 00086 int filterSize); 00087 00088 //! Uses an arbitrary filter given as argument 00089 template <class T_or_RGB> 00090 ImageSet<T_or_RGB> buildPyrConvolve(const Image<T_or_RGB>& image, 00091 int firstlevel, int depth, 00092 const Image<float>& filter, 00093 ConvolutionBoundaryStrategy boundary); 00094 00095 //! Uses a Laplacian filter of size \a filterSize. 00096 template <class T_or_RGB> 00097 ImageSet<T_or_RGB> buildPyrLaplacian(const Image<T_or_RGB>& image, 00098 int firstlevel, int depth, 00099 int filterSize); 00100 00101 //! Uses an oriented Laplacian filter with a given size/orientation/intensity. 00102 /*! This is a fast approximation to gabor convolution. 00103 00104 @param usetab Whether to use trig tables to speed up the 00105 computations at the cost of some loss of precision. 00106 */ 00107 template <class T_or_RGB> 00108 ImageSet<T_or_RGB> buildPyrOrientedFromLaplacian(const ImageSet<T_or_RGB>& laplacian, 00109 int filterSize, 00110 float theta, float intens = 10.0f, 00111 const bool usetab = false); 00112 00113 //! Uses an oriented Laplacian filter with a given size/orientation/intensity. 00114 /*! This is a fast approximation to gabor convolution. 00115 00116 @param usetab Whether to use trig tables to speed up the 00117 computations at the cost of some loss of precision. 00118 */ 00119 template <class T_or_RGB> 00120 ImageSet<T_or_RGB> buildPyrOriented(const Image<T_or_RGB>& image, 00121 int firstlevel, int depth, 00122 int filterSize, 00123 float theta, float intens = 10.0f, 00124 const bool usetab = false); 00125 00126 //! Just fills the deepest level with the local image average at that scale. 00127 template <class T_or_RGB> 00128 ImageSet<T_or_RGB> buildPyrLocalAvg(const Image<T_or_RGB>& image, int depth); 00129 00130 //! Each level contains local 2x2 averages of the previous level 00131 template <class T_or_RGB> 00132 ImageSet<T_or_RGB> buildPyrLocalAvg2x2(const Image<T_or_RGB>& image, int depth); 00133 00134 //! Just fills the deepest level with the local image maximum at that scale. 00135 template <class T_or_RGB> 00136 ImageSet<T_or_RGB> buildPyrLocalMax(const Image<T_or_RGB>& image, int depth); 00137 00138 //! Build a pyramid of type given by the PyramidType. 00139 template <class T_or_RGB> 00140 ImageSet<T_or_RGB> buildPyrGeneric(const Image<T_or_RGB>& image, 00141 int firstlevel, int depth, 00142 const PyramidType typ, 00143 const float gabor_theta = 0.0f, 00144 const float gabor_intens = 10.0f); 00145 00146 enum GaborFlags 00147 { 00148 DO_ENERGY_NORM = 1, 00149 DO_LAPLACIAN = 2, 00150 DO_CLAMPED_DIFF = 4, 00151 NO_ABS = 8 00152 }; 00153 00154 //! Build a Gabor Pyramid with a given angle, filter period and elongation 00155 /*!@param size determines the filter size (in pixels) - in the default case 00156 (-1), the size is computed from the filter_preiod and elongation*/ 00157 ImageSet<float> buildPyrGabor(const ImageSet<float>& gaussianPyr, 00158 float angle, float filter_period, 00159 float elongation = 1.0, 00160 int size = -1, int flags = 0); 00161 00162 //! Build a Gabor Pyramid with a given angle, filter period and elongation 00163 /*!@param size determines the filter size (in pixels) - in the default case 00164 (-1), the size is computed from the filter_preiod and elongation*/ 00165 ImageSet<float> buildPyrGabor(const Image<float>& img, 00166 int firstlevel, int depth, float angle, 00167 float filter_period, float elongation = 1.0, 00168 int size = -1, int flags = 0); 00169 00170 // ############################################################ 00171 // ##### Processing Functions: 00172 // ############################################################ 00173 00174 //! Compute center-surround between images at lev1 and lev2 00175 template <class T> 00176 Image<T> centerSurround(const ImageSet<T>& pyr, 00177 const int lev1, const int lev2, 00178 const bool absol = false, 00179 const ImageSet<float>* clipPyr = 0); 00180 00181 //! Compute center-surround between images, splitting positive and negative 00182 template <class T> 00183 void centerSurround(const ImageSet<T>& pyr, 00184 const int lev1, const int lev2, 00185 Image<T>& pos, Image<T>& neg, 00186 const ImageSet<float>* clipPyr = 0); 00187 00188 //! Compute single-opponent center-surround between images at lev1 and lev2 00189 /*! This is essentially cpyr[lev1] - spyr[lev2] */ 00190 template <class T> 00191 Image<T> centerSurroundSingleOpponent(const ImageSet<T>& cpyr, 00192 const ImageSet<T>& spyr, 00193 const int lev1, const int lev2, 00194 const bool absol = false, 00195 const ImageSet<float>* clipPyr = 0); 00196 00197 //! Compute single-opp center-surr between imgs, splitting pos and neg 00198 template <class T> 00199 void centerSurroundSingleOpponent(const ImageSet<T>& cpyr, 00200 const ImageSet<T>& spyr, 00201 const int lev1, const int lev2, 00202 Image<T>& pos, Image<T>& neg, 00203 const ImageSet<float>* clipPyr = 0); 00204 00205 //! Compute center-surround between difference images at lev1 and lev2 00206 /*! Difference images are obtained at each level by taking the difference 00207 between the image from *this minus the image from other_pyr */ 00208 template <class T> 00209 Image<T> centerSurroundDiff(const ImageSet<T>& pyr1, 00210 const ImageSet<T>& pyr2, 00211 const int lev1, const int lev2, 00212 const bool absol = false, 00213 const ImageSet<float>* clipPyr = 0); 00214 00215 //! Compute center-surround differnces, splitting pos & neg values 00216 template <class T> 00217 void centerSurroundDiff(const ImageSet<T>& pyr1, 00218 const ImageSet<T>& pyr2, 00219 const int lev1, const int lev2, 00220 Image<T>& pos, Image<T>& neg, 00221 const ImageSet<float>* clipPyr = 0); 00222 00223 //! Compute single-opp center-surround btw difference images at lev1 and lev2 00224 /*! Difference images are obtained at each level by taking the difference 00225 between the image from *this minus the image from other_pyr */ 00226 template <class T> 00227 Image<T> centerSurroundDiffSingleOpponent(const ImageSet<T>& cpyr1, 00228 const ImageSet<T>& cpyr2, 00229 const ImageSet<T>& spyr1, 00230 const ImageSet<T>& spyr2, 00231 const int lev1, const int lev2, 00232 const bool absol = false, 00233 const ImageSet<float>* clipPyr = 0); 00234 00235 //! Compute single-opp center-surround differnces, splitting pos & neg values 00236 template <class T> 00237 void centerSurroundDiffSingleOpponent(const ImageSet<T>& cpyr1, 00238 const ImageSet<T>& cpyr2, 00239 const ImageSet<T>& spyr1, 00240 const ImageSet<T>& spyr2, 00241 const int lev1, const int lev2, 00242 Image<T>& pos, Image<T>& neg, 00243 const ImageSet<float>* clipPyr = 0); 00244 00245 //! generate a weighted blur 00246 /*! The higher the modulator value (0..255), the more blurring at that 00247 location */ 00248 template <class T_or_RGB> 00249 Image<T_or_RGB> weightedBlur(const Image<byte>& modulator, 00250 const ImageSet<T_or_RGB>& pyr); 00251 00252 //! Generate a foveation blur 00253 /*! Mask should be 255 inside the object and 0 outside; the pyramid 00254 should be a Gaussian pyramid and will be used to create the 00255 eccentricity-dependent blur. The deeper the pyramid, the more severe 00256 the blur */ 00257 template <class T_or_RGB> 00258 Image<T_or_RGB> foveate(const Image<byte>& mask, 00259 const ImageSet<T_or_RGB>& pyr); 00260 00261 // ###################################################################### 00262 /* So things look consistent in everyone's emacs... */ 00263 /* Local Variables: */ 00264 /* indent-tabs-mode: nil */ 00265 /* End: */ 00266 00267 #endif // !IMAGE_PYRAMIDOPS_H_DEFINED
1.4.4