SpectralResidualChannel.H

Go to the documentation of this file.
00001 /*!@file Channels/SpectralResidualChannel.H "Spectral Residual" channel based on Hou&Zhang (CVPR 2007) */
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/Channels/SpectralResidualChannel.H $
00035 // $Id: SpectralResidualChannel.H 12820 2010-02-11 05:44:51Z itti $
00036 //
00037 
00038 #ifndef CHANNELS_SPECTRALRESIDUALCHANNEL_H_DEFINED
00039 #define CHANNELS_SPECTRALRESIDUALCHANNEL_H_DEFINED
00040 
00041 #include "Channels/ChannelBase.H"
00042 #include "Image/ResizeSpec.H"
00043 #include "Image/fancynorm.H" // for MaxNormType
00044 #include "rutz/shared_ptr.h"
00045 
00046 #include <pthread.h>
00047 #include <vector>
00048 
00049 template <class T> class FourierEngine;
00050 template <class T> class FourierInvEngine;
00051 
00052 extern const ModelOptionDef OPT_SpectralResidualChannelSaveOutputMap;
00053 extern const ModelOptionDef OPT_SpectralResidualChannelSaveExtraOutput;
00054 extern const ModelOptionDef OPT_SpectralResidualChannelResizeSpec;
00055 extern const ModelOptionDef OPT_SpectralResidualChannelSpectralBlur;
00056 extern const ModelOptionDef OPT_SpectralResidualChannelOutputBlur;
00057 extern const ModelOptionDef OPT_SpectralResidualChannelOutputBlurFactor;
00058 extern const ModelOptionDef OPT_SpectralResidualChannelDownSizeFilterWidth;
00059 extern const ModelOptionDef OPT_SpectralResidualChannelAttenuationWidth;
00060 extern const ModelOptionDef OPT_SpectralResidualChannelOutputResize;
00061 extern const ModelOptionDef OPT_SpectralResidualChannelOutputResizeSpec;
00062 extern const ModelOptionDef OPT_SpectralResidualChannelHiboostBypass;
00063 extern const ModelOptionDef OPT_SpectralResidualChannelGradientBypass;
00064 
00065 /// "Spectral Residual" channel based on Hou&Zhang (CVPR 2007)
00066 /** See also http://bcmi.sjtu.edu.cn/~houxiaodi */
00067 class SpectralResidualChannel : public ChannelBase
00068 {
00069 public:
00070   /// This helps share downsizing calculations across multiple subchannels in a MultiSpectralResidualChannel
00071   class Downsizer
00072   {
00073   public:
00074     Downsizer();
00075     ~Downsizer();
00076 
00077     Image<float> getDownsized(const Image<float>& x, int filtwidth,
00078                               const Dims& newdims);
00079 
00080   private:
00081     Downsizer(const Downsizer&); // not implemented
00082     Downsizer& operator=(const Downsizer&); // not implemented
00083 
00084     pthread_mutex_t itsMutex;
00085     Image<float> itsInput;
00086     int itsFilterWidth;
00087     std::vector<Image<float> > itsPyr;
00088   };
00089 
00090   /// Default constructor
00091   SpectralResidualChannel(OptionManager& mgr,
00092                           const std::string& descrName = "Spectral Residual",
00093                           const std::string& tagName = "SRS");
00094 
00095   /// Virtual destructor
00096   virtual ~SpectralResidualChannel();
00097 
00098   /// Calls visitChannelBase() on the ChannelVisitor.
00099   virtual void accept(ChannelVisitor& v);
00100 
00101   /// Returns true
00102   virtual bool isHomogeneous() const;
00103 
00104   /// Read params from the ParamMap.
00105   virtual void readFrom(const ParamMap& pmap);
00106 
00107   /// Write params to the ParamMap.
00108   virtual void writeTo(ParamMap& pmap) const;
00109 
00110   /// Returns true if we've gotten any input
00111   virtual bool outputAvailable() const;
00112 
00113   /// Return the dimensions of the output image.
00114   virtual Dims getMapDims() const;
00115 
00116   /// Return the number of feature maps represented by this channel.
00117   virtual uint numSubmaps() const;
00118 
00119   /// Get the feature map at the given index.
00120   virtual Image<float> getSubmap(const uint index) const;
00121 
00122   /// Get the name/description of the feature map at the given index.
00123   virtual std::string getSubmapName(const uint index) const;
00124 
00125   /// Get the name/description of the feature map at the given index, short version.
00126   virtual std::string getSubmapNameShort(const uint index) const;
00127 
00128   /// Not implemented
00129   virtual void getFeatures(const Point2D<int>& locn,
00130                            std::vector<float>& mean) const;
00131 
00132   /// Not implemented
00133   virtual void getFeaturesBatch(std::vector<Point2D<int>*> *locn,
00134                                 std::vector<std::vector<float> > *mean,
00135                                 int *count) const;
00136 
00137   /// Return the spectral residual saliency map
00138   virtual Image<float> getOutput();
00139 
00140   /// Save our various maps using a FrameOstream
00141   virtual void saveResults(const nub::ref<FrameOstream>& ofs);
00142 
00143   /// Subclasses override this to clear any caches they may maintain.
00144   virtual void killCaches();
00145 
00146   ResizeSpec getResizeSpec() const { return itsResizeSpec.getVal(); }
00147   void setResizeSpec(const ResizeSpec& s) { itsResizeSpec.setVal(s); }
00148 
00149   float getOutputBlur() const { return itsOutputBlur.getVal(); }
00150   void setOutputBlur(float f) { itsOutputBlur.setVal(f); }
00151 
00152   ResizeSpec getOutputResizeSpec() const
00153   { return itsOutputResizeSpec.getVal(); }
00154 
00155   void setOutputResizeSpec(bool on, const ResizeSpec& s)
00156   {
00157     itsDoResizeOutput.setVal(on);
00158     itsOutputResizeSpec.setVal(s);
00159   }
00160 
00161   rutz::shared_ptr<Downsizer> getDownsizer() const
00162   { return itsDownsizer; }
00163 
00164   void setDownsizer(rutz::shared_ptr<Downsizer> d)
00165   { itsDownsizer = d; }
00166 
00167 protected:
00168   virtual void doInput(const InputFrame& inframe);
00169 
00170 private:
00171   OModelParam<bool> itsSaveOutput;
00172   OModelParam<bool> itsSaveExtraOutput;
00173   OModelParam<ResizeSpec> itsResizeSpec;
00174   OModelParam<uint> itsSpectralBlur;
00175   OModelParam<float> itsOutputBlur;
00176   OModelParam<double> itsOutputBlurFactor;
00177   OModelParam<int> itsDownSizeFilterWidth;
00178   OModelParam<double> itsAttenuationWidth;
00179   OModelParam<bool> itsDoResizeOutput;
00180   OModelParam<ResizeSpec> itsOutputResizeSpec;
00181   OModelParam<MaxNormType> itsNormType;
00182   OModelParam<float> itsOutputRangeMin;
00183   OModelParam<float> itsOutputRangeMax;
00184   OModelParam<bool> itsHiboostBypass;
00185   OModelParam<bool> itsGradientBypass;
00186 
00187   rutz::shared_ptr<Downsizer> itsDownsizer;
00188 
00189   FourierEngine<double>* itsFFT;
00190   FourierInvEngine<double>* itsIFFT;
00191 
00192   Image<float> itsInput;
00193   Image<float> itsOutput;
00194 
00195   Image<float> itsRescaledInput;
00196   Image<float> itsLogMagnitude;
00197   Image<double> itsPhase;
00198   Image<float> itsSpectralResidual;
00199   Image<float> itsProtoSaliencyMap;
00200 };
00201 
00202 // ######################################################################
00203 /* So things look consistent in everyone's emacs... */
00204 /* Local Variables: */
00205 /* mode: c++ */
00206 /* indent-tabs-mode: nil */
00207 /* End: */
00208 
00209 #endif // CHANNELS_SPECTRALRESIDUALCHANNEL_H_DEFINED
Generated on Sun May 8 08:04:41 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3