00001 /*!@file SceneUnderstanding/V1.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: Lior Elazary <elazary@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/plugins/SceneUnderstanding/V1.H $ 00035 // $Id: V1.H 14065 2010-09-28 14:52:03Z lior $ 00036 // 00037 00038 #ifndef V1_H_DEFINED 00039 #define V1_H_DEFINED 00040 00041 //#include "Image/OpenCVUtil.H" // must be first to avoid conflicting defs of int64, uint64 00042 00043 #include "Image/Image.H" 00044 #include "Image/ImageSet.H" 00045 #include "Image/Pixels.H" 00046 #include "Image/Layout.H" 00047 #include "Image/Point3D.H" 00048 #include "Image/TensorOps.H" 00049 #include "plugins/SceneUnderstanding/LGN.H" 00050 #include "Simulation/SimEvents.H" 00051 #include "Simulation/SimModule.H" 00052 #include "Media/MediaSimEvents.H" 00053 #include "Component/ModelOptionDef.H" 00054 #include "Component/OptionManager.H" // for REQUEST_OPTIONALIAS_NEURO() 00055 #include "Component/ModelParam.H" 00056 #include "Util/CpuTimer.H" 00057 00058 #include <vector> 00059 #include <string> 00060 00061 class SimEventV1Bias; 00062 class V1 : public SimModule 00063 { 00064 public: 00065 00066 struct EdgesState 00067 { 00068 TensorField lumTensorField; 00069 TensorField rgTensorField; 00070 TensorField byTensorField; 00071 Image<float> prob; 00072 Image<float> distTr; //the distance transform 00073 //double distance(EdgeState &e) 00074 //{ 00075 // double dist = 1.0e100; 00076 // double dPoint = pos.squdist(e.pos); 00077 // double dRot = e.ori - ori; 00078 // dRot = atan(sin(dRot)/cos(dRot))*180/M_PI; //wrap to 180 deg to 0 00079 00080 // dist = sqrt(dPoint + (dRot*dRot)); 00081 // return dist; 00082 //} 00083 }; 00084 00085 00086 struct SpatialBias 00087 { 00088 Point2D<int> loc; 00089 Dims dims; 00090 float threshold; 00091 00092 SpatialBias() : 00093 loc(-1,-1), 00094 dims(0,0), 00095 threshold(0) 00096 {} 00097 00098 SpatialBias(int i, int j, int w, int h, float t) : 00099 loc(i,j), 00100 dims(w,h), 00101 threshold(t) 00102 {} 00103 bool contains(int x, int y) 00104 { 00105 if (!loc.isValid()) 00106 return false; 00107 00108 if (x > loc.i - (dims.w()/2) && 00109 x < loc.i + (dims.w()/2) && 00110 y > loc.j - (dims.h()/2) && 00111 y < loc.j + (dims.h()/2)) 00112 return true; 00113 else 00114 return false; 00115 00116 } 00117 00118 00119 }; 00120 00121 00122 V1(OptionManager& mgr, const std::string& descrName = "V1", 00123 const std::string& tagName = "V1"); 00124 00125 //! Destructor 00126 ~V1(); 00127 00128 void evolve(SimEventQueue& q); 00129 void evolveGabor(); 00130 void evolveSobel(); 00131 void evolveCanny(); 00132 void evolveTensor(); 00133 00134 Layout<PixRGB<byte> > getDebugImage(); 00135 00136 void setBias(const Image<float> &biasImg); 00137 00138 void applyThreshold(TensorField& tensorField, std::vector<SpatialBias>& spatialBias); 00139 00140 protected: 00141 //! Callback for when a new LGN output is ready 00142 SIMCALLBACK_DECLARE(V1, SimEventLGNOutput); 00143 00144 //! Callback for when a new ganglion output is ready 00145 SIMCALLBACK_DECLARE(V1, SimEventV1Bias); 00146 00147 00148 //! Callback for every time we should save our outputs 00149 SIMCALLBACK_DECLARE(V1, SimEventSaveOutput); 00150 00151 //! Callback for every time we have a user event 00152 SIMCALLBACK_DECLARE(V1, SimEventUserInput); 00153 00154 00155 00156 //! Should we show our debug info 00157 OModelParam<bool> itsShowDebug; 00158 00159 private: 00160 00161 ImageSet<float> itsLGNData; //The input to the cells 00162 Image<float> itsInput; 00163 EdgesState itsEdgesState; 00164 float itsThreshold; 00165 float itsBiasThreshold; 00166 float itsAngBias; 00167 std::vector<SpatialBias> itsSpatialBias; 00168 Point2D<int> itsAttenLoc; 00169 Dims itsWinSize; 00170 CpuTimer itsTimer; 00171 00172 }; 00173 00174 /* ############################### V1 sim events ######################## */ 00175 class SimEventV1Output : public SimEvent 00176 { 00177 public: 00178 SimEventV1Output(SimModule* src, 00179 V1::EdgesState& edgesState) : 00180 SimEvent(src), itsEdgesState(edgesState) 00181 {} 00182 00183 virtual ~SimEventV1Output(){} 00184 V1::EdgesState getEdgesState() { return itsEdgesState; } 00185 00186 private: 00187 const V1::EdgesState itsEdgesState; 00188 }; 00189 00190 class SimEventV1Bias : public SimEvent 00191 { 00192 public: 00193 SimEventV1Bias(SimModule* src, 00194 std::vector<V1::SpatialBias>& bias) : 00195 SimEvent(src), itsSpatialBias(bias) 00196 {} 00197 00198 virtual ~SimEventV1Bias(){} 00199 std::vector<V1::SpatialBias> getSpatialBias() { return itsSpatialBias; } 00200 00201 private: 00202 const std::vector<V1::SpatialBias>& itsSpatialBias; 00203 }; 00204 00205 00206 00207 00208 // ###################################################################### 00209 /* So things look consistent in everyone's emacs... */ 00210 /* Local Variables: */ 00211 /* indent-tabs-mode: nil */ 00212 /* End: */ 00213 00214 #endif //