00001 /** @file Psycho/GaborPatch.H represent the physical parameters of a gabor patch */ 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/Psycho/GaborPatch.H $ 00035 // $Id: GaborPatch.H 9078 2007-12-11 21:11:45Z rjpeters $ 00036 // 00037 00038 // Code herein is derived from GroovX, also licensed under the GPL 00039 // Copyright (c) 2002-2004 California Institute of Technology 00040 // Copyright (c) 2004-2007 University of Southern California 00041 // [http://ilab.usc.edu/rjpeters/groovx/] 00042 00043 #ifndef PSYCHO_GABORPATCH_H_DEFINED 00044 #define PSYCHO_GABORPATCH_H_DEFINED 00045 00046 #include "Image/Image.H" 00047 #include "Psycho/SearchItem.H" 00048 #include "rutz/rand.h" 00049 00050 #include <cmath> 00051 00052 struct GaborSpec 00053 { 00054 /// Construct with given values. 00055 /** Some values may be discretized into a (smallish) finite number of 00056 possible values to minimize the total number of GaborPatch objects 00057 that have to be created. */ 00058 GaborSpec(double s, double o, double t, double p); 00059 00060 /// Comparison operator for sorting and associative arrays. 00061 bool operator<(const GaborSpec& x) const; 00062 00063 const double theta; ///< Orientation of primary axis 00064 const double phi; ///< Phase angle of grating 00065 const double sigma; ///< Std dev of gaussian mask 00066 const double omega; ///< Spatial frequency of grating 00067 }; 00068 00069 /// Manages a pixmap representation of a gabor patch. 00070 /** Can either compute values directly, or can cache the entire patch. */ 00071 class GaborPatch 00072 { 00073 public: 00074 GaborPatch(const GaborSpec& spec); 00075 00076 ~GaborPatch(); 00077 00078 static const GaborPatch& lookup(const GaborSpec& s); 00079 00080 static const GaborPatch& lookup(double sigma, double omega, 00081 double theta, double phi); 00082 00083 int size() const { return itsSize; } 00084 00085 Image<double> image(double contrast) const 00086 { 00087 if (contrast == 1.0) 00088 return itsData; 00089 return itsData * contrast; 00090 } 00091 00092 private: 00093 GaborPatch(const GaborPatch&); 00094 GaborPatch& operator=(const GaborPatch&); 00095 00096 const GaborSpec itsSpec; 00097 const int itsSize; 00098 const double itsCenter; 00099 const double itsCosTheta; 00100 const double itsSinTheta; 00101 const double itsSigmaSqr; 00102 Image<double> itsData; 00103 }; 00104 00105 class GaborPatchItem : public SearchItem 00106 { 00107 public: 00108 GaborPatchItem(); 00109 00110 virtual ~GaborPatchItem(); 00111 00112 virtual Image<double> getPatch() const; 00113 00114 double theta; // angle to x-axis, 0 to TWOPI 00115 double phi; 00116 double contrast; 00117 00118 double itsPeriod; 00119 double itsSigma; 00120 }; 00121 00122 class GaborPatchItemFactory : public SearchItemFactory 00123 { 00124 public: 00125 GaborPatchItemFactory(int thetaSeed, 00126 int phaseSeed, 00127 int contrastSeed, 00128 double gaborPeriod = 15.0, double gaborSigma = 7.5); 00129 00130 virtual ~GaborPatchItemFactory(); 00131 00132 virtual rutz::shared_ptr<SearchItem> make(const geom::vec2d& pos); 00133 00134 rutz::shared_ptr<GaborPatchItem> makeForeground(const geom::vec2d& pos, 00135 const double theta); 00136 00137 private: 00138 rutz::urand itsThetaRand; 00139 rutz::urand itsPhaseRand; 00140 rutz::urand itsContrastRand; 00141 00142 double itsThetaJitter; 00143 double itsContrastJitter; 00144 00145 double itsPeriod; 00146 double itsSigma; 00147 }; 00148 00149 // ###################################################################### 00150 /* So things look consistent in everyone's emacs... */ 00151 /* Local Variables: */ 00152 /* mode: c++ */ 00153 /* indent-tabs-mode: nil */ 00154 /* End: */ 00155 00156 #endif // PSYCHO_GABORPATCH_H_DEFINED