00001 /*!@file SpaceVariant/ScaleSpaceOps.H */ 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: David J. Berg <dberg@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu:/software/invt/trunk/saliency/src/SpaceVariant/ScaleSpaceOps.H $ 00035 00036 #ifndef IMAGE_SCALESPACEOPS_H_DEFINED 00037 #define IMAGE_SCALESPACEOPS_H_DEFINED 00038 00039 #include "Image/Image.H" 00040 #include "Util/Promotions.H" 00041 00042 #include <utility> //for pair 00043 00044 //forward declare 00045 template <class T> class ImageSet; 00046 00047 // ###################################################################### 00048 /*! A class to represent a template of a local edge at a specific orientaton 00049 and length and with a specific dinsity of sub regions. 00050 The spaceing is set for difference of gaussians responses where the 00051 centers are allowed to be offset if smult < 1.0 else 00052 the spacing is set suitable for sub regions which are made of 00053 center-surround LGN type resonses. Orientation should be in 00054 radians, and all other values in pixels. Its best, but not reqired if 00055 length is odd. 00056 00057 The optimal offset for a given std_center and smult was determined by fitting 00058 difference of Gaussians (with different offsets) to 1 period of a sin function 00059 for different frequencies. A function offset=c*std_center fit this function quite nicely 00060 00061 For the edge made of two DoG's things are a little more complicated and the best 00062 parameters to a sin function form a surface in 3D (std_center, smult, offset). 00063 First for each surround_multiplier we fit a linear function to find the best offset as above. Then 00064 fit a function of surround_multiplier over 'c' variable as the sum of two exponentials. Once 00065 some initial paramters were estimated we fit the whole surface to obtain 00066 :offset=(a*exp(surround_mult*b) + c*exp(surround_mult*d) + e * std_center) where a-e are constants 00067 */ 00068 // ###################################################################### 00069 struct LocalEdge 00070 { 00071 LocalEdge(const Dims& inp_dims, const float& std_center, const float& smult, const float& orientation, 00072 const uint& length, const uint density); 00073 00074 LocalEdge(); 00075 00076 ~LocalEdge(); 00077 00078 typedef std::vector<std::pair<float,float> > EdgeTemplate; 00079 EdgeTemplate onReg, offReg; 00080 }; 00081 00082 // ###################################################################### 00083 // ###################################################################### 00084 // scale space functions 00085 // ###################################################################### 00086 // ###################################################################### 00087 // create a scale space up to the desired blur parameterized by the 00088 // standard deviation of the gaussian filter 00089 // ###################################################################### 00090 template <class T_or_RGB> 00091 ImageSet<typename promote_trait<T_or_RGB, float>::TP> 00092 getScaleSpace(const Image<T_or_RGB>& input, const float& max_std); 00093 00094 // ###################################################################### 00095 template <class T_or_RGB> 00096 void addScale(ImageSet<T_or_RGB>& pyr, const float& max_std); 00097 00098 // ###################################################################### 00099 //! Get value of a pixel from a dyadic pyramid with trilinear interpolation 00100 // ###################################################################### 00101 template <class T_or_RGB> 00102 T_or_RGB getScaleSpacePixel(const ImageSet<T_or_RGB>& pyr, const float& x, const float& y, const float& std); 00103 00104 // ###################################################################### 00105 //! Get value of a difference of scales pixel from a dyadic pyramid with trilinear interpolation 00106 // ###################################################################### 00107 template <class T_or_RGB> 00108 typename promote_trait<T_or_RGB, float>::TP 00109 getDiffScaleSpacePixel(const ImageSet<T_or_RGB>& pyr, const float& x, const float& y, const float& std_center, const float& std_surround, const bool on_center = true); 00110 00111 // ###################################################################### 00112 /*! Get value of a local edge by pooling nearby on only and off only 00113 responses, but allowing the centers to differ. The tree shrew 00114 apparently creates edge detecting cells in this fashion see 00115 Hirsh and Martiniz, Trends Neuro Sci, 2006 for a review. 00116 The result is squared. 00117 00118 Note: the std should be the same as was used to construct the LocalEdge object 00119 */ 00120 // ###################################################################### 00121 template <class T_or_RGB> 00122 typename promote_trait<T_or_RGB, float>::TP 00123 getEdgeScaleSpacePixel(const ImageSet<T_or_RGB>& pyr, const float& x, const float& y, const float& std, const LocalEdge& edgemap); 00124 00125 // ###################################################################### 00126 /*! Get value of a local edge by pooling nearby difference of scales pixel 00127 from a pyramid with trilinear interpolation. The wiring diagram is inspired by: 00128 Hirsh and Martiniz, Trends Neuro Sci, 2006 (for a reviw). 00129 We model the orientation of a pixel as an on-center DiffScaleSpacePixel 00130 adjacent to an off-center one, creating a local orientation estimation. 00131 When the parameters are chosen correctly this looks simmilar to a odd gabor or 00132 a third derivitive Gaussian An edge is then modeled as a length of local co-oriented local 00133 orientations at a specific density. The result is squared. 00134 00135 Note: the variance and surround_mult should be the same as was used to construct the LocalEdge object 00136 */ 00137 // ###################################################################### 00138 template <class T_or_RGB> 00139 typename promote_trait<T_or_RGB, float>::TP 00140 getEdgeScaleSpacePixel(const ImageSet<T_or_RGB>& pyr, const float& x, const float& y, const float& std_center, const float& std_surround, const LocalEdge& edgemap); 00141 00142 #endif // IMAGE_SCALESPACEOPS_H_DEFINED 00143 // ###################################################################### 00144 /* So things look consistent in everyone's emacs... */ 00145 /* Local Variables: */ 00146 /* mode: c++ */ 00147 /* indent-tabs-mode: nil */ 00148 /* End: */ 00149 00150