ObjRec.H

Go to the documentation of this file.
00001 /*!@file ObjRec/ObjRec.H Obj Reconition class */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // 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/ObjRec/ObjRec.H $
00035 // $Id: ObjRec.H 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 
00038 #ifndef ObjRec_H_DEFINED
00039 #define ObjRec_H_DEFINED
00040 
00041 #include "Component/ModelComponent.H"
00042 #include "Component/ModelParam.H"
00043 #include "Image/Image.H"
00044 #include "Image/Pixels.H"
00045 
00046 class ObjRec : public ModelComponent
00047 {
00048   struct EdgeState
00049   {
00050     Point2D<int> pos;
00051     float ori;
00052     PixRGB<byte> color;
00053     float prob;
00054   };
00055   struct LineState
00056   {
00057     Point2D<int> pos;
00058     float ori;
00059     float length;
00060     PixRGB<byte> color;
00061     float prob;
00062   };
00063 
00064   struct SquareState
00065   {
00066     Point2D<int> pos;
00067     float ori;
00068     float size;
00069     PixRGB<byte> color;
00070     float prob;
00071   };
00072 
00073 
00074   struct WorldState
00075   {
00076     Image<float> edgeProb;
00077     std::vector<EdgeState> edges;
00078     std::vector<LineState> lines;
00079     std::vector<SquareState> squares;
00080   };
00081 
00082 public:
00083   //Constructor
00084   ObjRec(OptionManager& mgr,
00085           const std::string& descrName = "ObjRec",
00086           const std::string& tagName = "ObjRec");
00087   ~ObjRec();
00088 
00089   //###########################################################
00090   void start2();
00091 
00092   double predictWorld(const Image<PixRGB<byte> > &worldImg);
00093   Image<PixRGB<byte> > getWorldPredictImage();
00094 
00095   void setImageDims(const Dims &dims);
00096 
00097 
00098   void initialProposal ();
00099   void initialProposal(const Image<PixRGB<byte> > &worldImg);
00100   double getPosterior(WorldState &worldState);
00101   double getLikelihood(WorldState &worldState);
00102   double getEdgeLikelihood(WorldState &worldState);
00103   double getLineLikelihood(WorldState &worldState);
00104   double getSquareLikelihood(WorldState &worldState);
00105 
00106 
00107   void generateNewState(WorldState &worldState);
00108   void generateNewEdgeState(WorldState &worldState);
00109   void generateNewLineState(WorldState &worldState);
00110   void generateNewSquareState(WorldState &worldState);
00111 
00112   double sampleOriFromEdgeSpace(WorldState &worldState);
00113   Point2D<int> samplePosFromEdgeSpace(WorldState &worldState);
00114 
00115   double sampleOriFromLineSpace(WorldState &worldState);
00116   Point2D<int> samplePosFromLineSpace(WorldState &worldState);
00117   double sampleSizeFromLineSpace(WorldState &worldState);
00118 
00119   double sampleLengthFromSquareSpace(WorldState &worldState);
00120 
00121   double evalNewEdgesWorld(WorldState &oldWorldState, WorldState &newWorldState);
00122   double evalNewLinesWorld(WorldState &oldWorldState, WorldState &newWorldState);
00123   double evalNewSquaresWorld(WorldState &oldWorldState, WorldState &newWorldState);
00124 
00125   void normalizeWorld(WorldState &worldState);
00126 
00127 
00128   Image<PixRGB<byte> > showWorld(WorldState &worldState);
00129   Image<PixRGB<byte> > showEdgesWorld(WorldState &worldState);
00130   Image<PixRGB<byte> > showLinesWorld(WorldState &worldState);
00131   Image<PixRGB<byte> > showSquaresWorld(WorldState &worldState);
00132 
00133 
00134   ////// debuging utilities ///////////
00135   double evalLikelihood(const Image<PixRGB<byte> > &worldImg, const Point2D<int> &pos, double angle, double length);
00136 
00137 
00138   double edgesProb(const Image<PixRGB<byte> > &worldImg);
00139   double edgesLiklyProb(const Image<PixRGB<byte> > &worldImg);
00140   double edgesPriorProb();
00141 
00142   void houghLines();
00143 
00144   void samplePosterior(const Image<float> &posterior, Point2D<int> &loc, int stop=1000);
00145 
00146   void train(const Image<PixRGB<byte> > &img, const std::string label);
00147   std::string test(const Image<PixRGB<byte> > &img);
00148 
00149 
00150 private:
00151 
00152   Dims itsImageDims;
00153   Image<PixRGB<byte> > itsPredictWorldImg;
00154   Image<PixRGB<byte> > itsCurrentWorldImg;
00155 
00156   std::vector<Image<float> > itsGabors;
00157 
00158   WorldState itsWorldState;
00159   bool itsInitProposal;
00160 
00161 };
00162 
00163 #endif
00164 
00165 // ######################################################################
00166 /* So things look consistent in everyone's emacs... */
00167 /* Local Variables: */
00168 /* indent-tabs-mode: nil */
00169 /* End: */
Generated on Sun May 8 08:41:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3