00001 /*!@file Neuro/EnvVisualCortex.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: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/EnvVisualCortex.H $ 00035 // $Id: EnvVisualCortex.H 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 #ifndef NEURO_ENVVISUALCORTEX_H_DEFINED 00039 #define NEURO_ENVVISUALCORTEX_H_DEFINED 00040 00041 #include "Component/ModelComponent.H" 00042 #include "Component/ModelParam.H" 00043 #include "Envision/env_params.h" 00044 #include "Envision/env_types.h" 00045 #include "Envision/env_visual_cortex.h" 00046 #include "Image/Image.H" 00047 #include "Image/LevelSpec.H" 00048 #include "Image/Pixels.H" 00049 #include "rutz/shared_ptr.h" 00050 00051 class WorkThreadServer; 00052 00053 extern const ModelOptionDef OPT_EvcMaxnormType; 00054 extern const ModelOptionDef OPT_EvcScaleBits; 00055 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00056 extern const ModelOptionDef OPT_EvcNumDirections; 00057 extern const ModelOptionDef OPT_EvcMotionThresh; 00058 extern const ModelOptionDef OPT_EvcFlickerThresh; 00059 extern const ModelOptionDef OPT_EvcMultiScaleFlicker; 00060 extern const ModelOptionDef OPT_EvcShowMemStats; 00061 #endif 00062 extern const ModelOptionDef OPT_EvcNumOrientations; 00063 extern const ModelOptionDef OPT_EvcType; 00064 extern const ModelOptionDef OPT_EvcColorSmoothing; 00065 extern const ModelOptionDef OPT_EvcOutputFactor; 00066 00067 // ###################################################################### 00068 //! Base class for a VisualCortex using the fast envision saliency computations 00069 class EnvVisualCortexBase : public ModelComponent 00070 { 00071 public: 00072 //! Constructor 00073 EnvVisualCortexBase(OptionManager& mgr, const std::string& descrName = "EnvVisualCortexBase", 00074 const std::string& tagName = "EnvVisualCortexBase"); 00075 00076 //! virtual destructor for safe inheritance 00077 virtual ~EnvVisualCortexBase(); 00078 00079 //! Return the pyramid level of the saliency map 00080 inline env_size_t getMapLevel() const; 00081 00082 //! Compute saliency map from an input image 00083 /*! Use the getVCXmap(), getImap(), etc to get the results. In the base class input() is pure virtual and the 00084 getVCXmap() and others do not exist. Derived classes implement all these and you should use these derived 00085 classes. */ 00086 virtual void input(const Image<PixRGB<byte> >& rgbin) = 0; 00087 00088 inline byte getIweight(); 00089 inline byte getCweight(); 00090 inline byte getOweight(); 00091 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00092 inline byte getFweight(); 00093 inline byte getMweight(); 00094 #endif 00095 00096 //! Access our internal envision parameters 00097 inline const struct env_params& getParams() const; 00098 00099 inline bool getColorSmoothing() const; 00100 inline void setColorSmoothing(bool val); 00101 00102 inline void setIweight(byte val); 00103 inline void setCweight(byte val); 00104 inline void setOweight(byte val); 00105 inline void setNumOrientations(byte val); 00106 00107 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00108 inline void setFweight(byte val); 00109 inline void setMweight(byte val); 00110 inline void setFthresh(byte val); 00111 inline void setMthresh(byte val); 00112 inline void setMultiScaleFlicker(bool val); 00113 inline void setNumDirections(byte val); 00114 #endif 00115 00116 #ifdef ENV_WITH_VISIT_CHANNEL 00117 inline void setSubmapPreProc(int (*submapPreProc)(const char* tagName, 00118 env_size_t clev, env_size_t slev, struct env_image *submap, 00119 const struct env_image *center, const struct env_image *surround)); 00120 00121 00122 inline void setSubmapPostNormProc(int (*submapPostNormProc)(const char* tagName, 00123 env_size_t clev, env_size_t slev, struct env_image *submap, 00124 const struct env_image *center, const struct env_image *surround)); 00125 00126 inline void setSubmapPostProc(int (*submapPostProc)(const char* tagName, 00127 struct env_image *cmap)); 00128 #endif 00129 00130 protected: 00131 virtual void paramChanged(ModelParamBase* const param, const bool valueChanged, 00132 ParamClient::ChangeStatus* status); 00133 virtual void start1(); 00134 virtual void stop2(); 00135 00136 00137 NModelParam<byte> itsIweight; 00138 NModelParam<byte> itsCweight; 00139 NModelParam<byte> itsOweight; 00140 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00141 NModelParam<byte> itsFweight; 00142 NModelParam<byte> itsMweight; 00143 #endif 00144 OModelParam<bool> itsMultithreaded; 00145 OModelParam<std::string> itsMaxnormType; 00146 OModelParam<byte> itsScaleBits; 00147 OModelParam<byte> itsNumOrientations; 00148 OModelParam<bool> itsColorSmoothing; 00149 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00150 OModelParam<byte> itsNumDirections; 00151 OModelParam<byte> itsMotionThresh; 00152 OModelParam<byte> itsFlickerThresh; 00153 OModelParam<int> itsRangeThresh; 00154 OModelParam<bool> itsMultiScaleFlicker; 00155 OModelParam<bool> itsShowMemStats; 00156 #endif 00157 OModelParam<LevelSpec> itsLevelSpec; 00158 OModelParam<std::string> itsType; 00159 00160 struct env_params envp; 00161 struct env_visual_cortex ivc; 00162 env_size_t npixels; 00163 int framenum; 00164 Image<PixRGB<byte> > itsPrevRgb; 00165 rutz::shared_ptr<WorkThreadServer> itsThreadServer; 00166 }; 00167 00168 // ###################################################################### 00169 //! A VisualCortex using the fast envision saliency computations, version with byte outputs 00170 class EnvVisualCortex : public EnvVisualCortexBase 00171 { 00172 public: 00173 //! Constructor 00174 EnvVisualCortex(OptionManager& mgr, const std::string& descrName = "EnvVisualCortex", 00175 const std::string& tagName = "EnvVisualCortex"); 00176 00177 //! virtual destructor for safe inheritance 00178 virtual ~EnvVisualCortex(); 00179 00180 //! Compute saliency map from an input image 00181 /*! Use the getVCXmap(), getImap(), etc to get the results. */ 00182 virtual void input(const Image<PixRGB<byte> >& rgbin); 00183 00184 inline Image<byte> getVCXmap() const; 00185 00186 inline Image<byte> getImap() const; 00187 inline Image<byte> getCmap() const; 00188 inline Image<byte> getOmap() const; 00189 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00190 inline Image<byte> getFmap() const; 00191 inline Image<byte> getMmap() const; 00192 #endif 00193 00194 protected: 00195 Image<byte> itsVCXmap; 00196 00197 Image<byte> itsImap; 00198 Image<byte> itsCmap; 00199 Image<byte> itsOmap; 00200 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00201 Image<byte> itsFmap; 00202 Image<byte> itsMmap; 00203 #endif 00204 00205 private: 00206 intg32 chanmi, chanma; 00207 intg32 vcxmi, vcxma; 00208 }; 00209 00210 // ###################################################################### 00211 //! A VisualCortex using the fast envision saliency computations, version with float outputs 00212 class EnvVisualCortexFloat : public EnvVisualCortexBase 00213 { 00214 public: 00215 //! Constructor 00216 EnvVisualCortexFloat(OptionManager& mgr, const std::string& descrName = "EnvVisualCortexFloat", 00217 const std::string& tagName = "EnvVisualCortexFloat"); 00218 00219 //! virtual destructor for safe inheritance 00220 virtual ~EnvVisualCortexFloat(); 00221 00222 //! Compute saliency map from an input image 00223 /*! Use the getVCXmap(), getImap(), etc to get the results. */ 00224 virtual void input(const Image<PixRGB<byte> >& rgbin); 00225 00226 inline Image<float> getVCXmap() const; 00227 00228 inline Image<float> getImap() const; 00229 inline Image<float> getCmap() const; 00230 inline Image<float> getOmap() const; 00231 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00232 inline Image<float> getFmap() const; 00233 inline Image<float> getMmap() const; 00234 #endif 00235 00236 protected: 00237 OModelParam<float> itsOutputFactor; //!< output range factor 00238 00239 Image<float> itsVCXmap; 00240 Image<float> itsImap; 00241 Image<float> itsCmap; 00242 Image<float> itsOmap; 00243 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00244 Image<float> itsFmap; 00245 Image<float> itsMmap; 00246 #endif 00247 }; 00248 00249 00250 // ###################################################################### 00251 // inline functions for EnvVisualCortexBase: 00252 00253 env_size_t EnvVisualCortexBase::getMapLevel() const { return this->envp.output_map_level; } 00254 byte EnvVisualCortexBase::getIweight() { return envp.chan_i_weight; } 00255 byte EnvVisualCortexBase::getCweight() { return envp.chan_c_weight; } 00256 byte EnvVisualCortexBase::getOweight() { return envp.chan_o_weight; } 00257 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00258 byte EnvVisualCortexBase::getFweight() { return envp.chan_f_weight; } 00259 byte EnvVisualCortexBase::getMweight() { return envp.chan_m_weight; } 00260 #endif 00261 const struct env_params& EnvVisualCortexBase::getParams() const { return envp; } 00262 bool EnvVisualCortexBase::getColorSmoothing() const { return itsColorSmoothing.getVal(); } 00263 void EnvVisualCortexBase::setIweight(byte val) { envp.chan_i_weight = val; } 00264 void EnvVisualCortexBase::setCweight(byte val) { envp.chan_c_weight = val; } 00265 void EnvVisualCortexBase::setOweight(byte val) { envp.chan_o_weight = val; } 00266 void EnvVisualCortexBase::setNumOrientations(byte val) { envp.num_orientations = val; } 00267 00268 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00269 void EnvVisualCortexBase::setFweight(byte val) { envp.chan_f_weight = val; } 00270 void EnvVisualCortexBase::setMweight(byte val) { envp.chan_m_weight = val; } 00271 void EnvVisualCortexBase::setFthresh(byte val) { envp.flicker_thresh = val; } 00272 void EnvVisualCortexBase::setMthresh(byte val) { envp.motion_thresh = val; } 00273 void EnvVisualCortexBase::setMultiScaleFlicker(bool val) { envp.multiscale_flicker = val ? 1 : 0; } 00274 void EnvVisualCortexBase::setNumDirections(byte val) { envp.num_motion_directions = val; } 00275 #endif 00276 00277 void EnvVisualCortexBase::setColorSmoothing(bool val) { itsColorSmoothing.setVal(val); } 00278 00279 #ifdef ENV_WITH_VISIT_CHANNEL 00280 void EnvVisualCortexBase::setSubmapPreProc(int (*submapPreProc)(const char* tagName, 00281 env_size_t clev, env_size_t slev, struct env_image *submap, 00282 const struct env_image *center, const struct env_image *surround)) 00283 { envp.submapPreProc = submapPreProc; } 00284 00285 void EnvVisualCortexBase::setSubmapPostNormProc(int (*submapPostNormProc)(const char* tagName, 00286 env_size_t clev, env_size_t slev, struct env_image *submap, 00287 const struct env_image *center, const struct env_image *surround)) 00288 { envp.submapPostNormProc = submapPostNormProc; } 00289 00290 void EnvVisualCortexBase::setSubmapPostProc(int (*submapPostProc)(const char* tagName, 00291 struct env_image *cmap)) 00292 { envp.submapPostProc = submapPostProc; } 00293 #endif 00294 00295 00296 // ###################################################################### 00297 // Inline functions for EnvVisualCortex 00298 00299 Image<byte> EnvVisualCortex::getVCXmap() const { return itsVCXmap; } 00300 Image<byte> EnvVisualCortex::getImap() const { return itsImap; } 00301 Image<byte> EnvVisualCortex::getCmap() const { return itsCmap; } 00302 Image<byte> EnvVisualCortex::getOmap() const { return itsOmap; } 00303 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00304 Image<byte> EnvVisualCortex::getFmap() const { return itsFmap; } 00305 Image<byte> EnvVisualCortex::getMmap() const { return itsMmap; } 00306 #endif 00307 00308 // ###################################################################### 00309 // Inline functions for EnvVisualCortexFloat 00310 00311 Image<float> EnvVisualCortexFloat::getVCXmap() const { return itsVCXmap; } 00312 Image<float> EnvVisualCortexFloat::getImap() const { return itsImap; } 00313 Image<float> EnvVisualCortexFloat::getCmap() const { return itsCmap; } 00314 Image<float> EnvVisualCortexFloat::getOmap() const { return itsOmap; } 00315 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00316 Image<float> EnvVisualCortexFloat::getFmap() const { return itsFmap; } 00317 Image<float> EnvVisualCortexFloat::getMmap() const { return itsMmap; } 00318 #endif 00319 00320 // ###################################################################### 00321 /* So things look consistent in everyone's emacs... */ 00322 /* Local Variables: */ 00323 /* mode: c++ */ 00324 /* indent-tabs-mode: nil */ 00325 /* End: */ 00326 00327 #endif // NEURO_ENVVISUALCORTEX_H_DEFINED