Contours.H

Go to the documentation of this file.
00001 /*!@file SceneUnderstanding/Contours.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/Contours.H $
00035 // $Id: Contours.H 13904 2010-09-09 21:37:01Z lior $
00036 //
00037 
00038 #ifndef Contours_H_DEFINED
00039 #define Contours_H_DEFINED
00040 
00041 #include "Image/Image.H"
00042 #include "Image/ImageSet.H"
00043 #include "Image/Pixels.H"
00044 #include "Image/Layout.H"
00045 #include "plugins/SceneUnderstanding/V2.H"
00046 #include "plugins/SceneUnderstanding/TensorVoting.H"
00047 #include "Image/TensorOps.H"
00048 #include "Simulation/SimEvents.H"
00049 #include "Simulation/SimModule.H"
00050 
00051 #include <vector>
00052 #include <string>
00053 class SimEventContoursBias;
00054 
00055 class Contours : public SimModule
00056 {
00057 public:
00058   const static float UNKNOWN = -1.0F;
00059   const static float NOTDEFINED = -2.0F;
00060 
00061   struct Contour
00062   {
00063     std::vector<Point2D<int> > points;
00064     std::vector<float> ori;
00065 
00066     size_t size() const
00067     {
00068       return points.size();
00069     }
00070   };
00071 
00072   struct ContourCmp
00073   {
00074     bool operator()(const Contour& c1, const Contour& c2)
00075     {
00076       return c1.size() > c2.size();
00077     }
00078   };
00079   
00080 
00081   Contours(OptionManager& mgr, const std::string& descrName = "Contours",
00082       const std::string& tagName = "Contours");
00083 
00084   //! Destructor
00085   ~Contours();
00086 
00087   void evolve(SimEventQueue& q);
00088 
00089   Layout<PixRGB<byte> > getDebugImage();
00090 
00091 protected:
00092   //! Callback for when a new ganglion output is ready
00093   SIMCALLBACK_DECLARE(Contours, SimEventV2Output);
00094 
00095   //! Callback for when a new ganglion output is ready
00096   SIMCALLBACK_DECLARE(Contours, SimEventContoursBias);
00097 
00098   //! Callback for every time we should save our outputs
00099   SIMCALLBACK_DECLARE(Contours, SimEventSaveOutput);
00100 
00101   //! Callback for every time we have a user event
00102   SIMCALLBACK_DECLARE(Contours, SimEventUserInput);
00103 
00104   //! Should we show our debug info
00105   OModelParam<bool> itsShowDebug;
00106 
00107   std::vector<Point2D<int> > getPointList(TensorVoting& tv, Image<float>& contoursImg,
00108       Image<float>& edgesMag, Image<float>& edgesOri);
00109 
00110   std::vector<Point2D<int> > getPointList(Image<float>& inMag, Image<float>& inOri,
00111       Image<float>& contoursImg);
00112 
00113   
00114   Contour followContour(int idx, Point2D<int> startLoc, Image<float>& contoursImg,
00115       const Image<float>& edgesMag, const Image<float>& edgesOri);
00116 
00117   Point2D<int> findEdgeToFollow(const Point2D<int>& edgeLoc,
00118       const float origEdgeMag,
00119       const Image<float>& edgesMag, const Image<float>& edgesOri,
00120       const Image<float>& contoursImg,
00121       const Point2D<int>& pEdge);
00122   
00123   
00124 
00125 private:
00126   std::vector<TensorVoting> itsTensorFields;
00127   std::vector<Contour> itsContours;
00128   std::vector<Contour> itsBiasContours;
00129 
00130   int itsCurrentContour;
00131 
00132 };
00133 
00134 /* ############################### V2 sim events ######################## */
00135 class SimEventContoursOutput : public SimEvent
00136 {
00137 public:
00138   SimEventContoursOutput(SimModule* src,
00139       std::vector<Contours::Contour>& contour,
00140       Image<float>& img) :
00141     SimEvent(src), itsContours(contour), itsImg(img)
00142   {}
00143 
00144   virtual ~SimEventContoursOutput(){}
00145   std::vector<Contours::Contour> getContours() { return itsContours; }
00146   Image<float> getImg() { return itsImg; }
00147 
00148 private:
00149   const std::vector<Contours::Contour>& itsContours;
00150   const Image<float>& itsImg;
00151 };
00152 
00153 class SimEventContoursBias : public SimEvent
00154 {
00155 public:
00156   SimEventContoursBias(SimModule* src,
00157       std::vector<Contours::Contour>& contour) :
00158     SimEvent(src), itsContours(contour)
00159   {}
00160 
00161   virtual ~SimEventContoursBias(){}
00162   std::vector<Contours::Contour> getContours() { return itsContours; }
00163 
00164 private:
00165   const std::vector<Contours::Contour>& itsContours;
00166 };
00167 
00168 
00169 // ######################################################################
00170 /* So things look consistent in everyone's emacs... */
00171 /* Local Variables: */
00172 /* indent-tabs-mode: nil */
00173 /* End: */
00174 
00175 #endif //
Generated on Sun May 8 08:41:09 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3