TestImages.H

Go to the documentation of this file.
00001 /*!@file Media/TestImages.H Header file for test Images */
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
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Media/TestImages.H $
00035 // $Id: TestImages.H 12055 2009-11-18 23:47:49Z lior $
00036 //
00037 
00038 #ifndef MEDIA_TESTIMAGES_H_DEFINED
00039 #define MEDIA_TESTIMAGES_H_DEFINED
00040 
00041 #include "Image/Image.H"
00042 #include "Image/Pixels.H"
00043 #include "Raster/Raster.H"
00044 #include "Raster/GenericFrame.H"
00045 
00046 #include <vector>
00047 #include <string>
00048 
00049 #ifdef HAVE_LIBXML
00050 #include <libxml/parser.h>
00051 #include <libxml/tree.h>
00052 #endif
00053 
00054 //! TestImages
00055 class TestImages
00056 {
00057 public :
00058   //! Types of libraries available
00059   enum  LIBRARY { ALOI, CSAIL, COIL, MIT_LABELME, CALTECH256,
00060                   CSCLAB, IMG_DIR, XMLFILE };
00061 
00062   //! Possible uses
00063   enum  USETYPE { TRAIN, TEST, ALL };
00064 
00065   struct ObjData {
00066     Image<PixRGB<byte> > img;
00067     unsigned int         id;
00068     double               maxProb;
00069     double               normProb;
00070     std::string          name;
00071     std::string          description;
00072     std::string          filename;
00073     Dims                 dims;
00074     std::vector<Point2D<int> > polygon;
00075     // if an objectmask file was given instead of a polygon, it will prevail
00076     Image<byte>          objmask;
00077     // if available [X, Y, Z, U, V] related to most salient location
00078     // on object, otherwise empty vector
00079     std::vector<int>     location3D;
00080   };
00081 
00082   struct SceneData : public GenericFrame::MetaData
00083   {
00084     Image<PixRGB<byte> > img;
00085     std::string description;
00086     std::string filename;
00087     Dims dims;
00088     std::string type;
00089     std::vector<ObjData> objects;
00090     USETYPE useType;
00091   };
00092 
00093 
00094   //! Constructor
00095   TestImages(const char* imagesPath, LIBRARY lib,
00096              const int numTraining = -1, const int numTesting = -1,
00097              const int numObjects = -1);
00098 
00099   ~TestImages();
00100 
00101   //! Return a single object
00102   //!if lum or col or rot are -1, then return a random of that type
00103   Image<PixRGB<byte> > getObject(int id=-1, int lum=-1, int col=-2, int rot=-2);
00104 
00105   //! return the scene data
00106   SceneData getSceneData(uint scene, USETYPE useType=ALL);
00107 
00108   //! Return an ObjData for a single object
00109   //! load the image when the object is requested to save on memory
00110   ObjData getObjectData(uint scene, uint obj, bool getImage = false);
00111 
00112   //! get the obj in this position
00113   ObjData getObjFromPos(uint scene, const Point2D<int> &pt);
00114 
00115   Image<PixRGB<byte> > getScene(uint sceneId, USETYPE useType=ALL);
00116 
00117   std::string getSceneFilename(uint sceneId);
00118 
00119   Image<PixRGB<byte> > getLabelMeScene(uint sceneId);
00120   Image<PixRGB<byte> > getCscLabScene(uint sceneId);
00121 
00122   //! generate a scene from its objects
00123   Image<PixRGB<byte> > generateScene(uint scene);
00124 
00125   uint getMaxLum();
00126   uint getMaxCol();
00127   uint getMaxRot();
00128 
00129   //! get the number of objects in a scene
00130   uint getNumObj(uint scene = 0);
00131 
00132   //! get the max number of scenes we have
00133   uint getNumScenes(USETYPE useType = ALL);
00134 
00135   //! get the object name
00136   const char* getObjName(uint id);
00137 
00138   //! get the polygon encompesing the obj
00139   std::vector<Point2D<int> > getObjPolygon(uint id);
00140 
00141   //! get an object mask (use current scene)
00142   Image<byte> getObjMask(uint id);
00143 
00144   //! get an object mask
00145   Image<byte> getObjMask(uint scene, uint obj);
00146 
00147   //! get an object mask
00148   Image<byte> getObjMask(uint scene, uint obj, const Dims& sceneDims);
00149 
00150   //! get a mask from all objects
00151   Image<byte> getAllObjMask();
00152 
00153   //! label a scene from avilable polygons
00154   int labelScene(uint scene, Image<PixRGB<byte> > &sceneImg);
00155 
00156   //! Set the root path
00157   void setRootPath(std::string path) { itsCurrentPath = path; }
00158 
00159 private:
00160   // read a list of scenes from the file system
00161   void readDir(const char *path);
00162 
00163   void readCalTech256Dir(const char *path, const int trainingSize = -1,
00164                          const int testingSize = -1, bool shuffe = true);
00165   // get an object from the current scene
00166   Image<PixRGB<byte> > getCscLabObj(int id);
00167 
00168   //get an object from the current scene
00169   Image<PixRGB<byte> > getLabelMeObj(int id);
00170 
00171   //read a list of objects from an xml file
00172   void readObjXML(const char *path);
00173 
00174 #ifdef HAVE_LIBXML
00175   // retrun the text associaded with the named node
00176   void getNodeMatchText(xmlDocPtr doc, xmlNodePtr nodePtr,
00177                         const char* nodeName, std::string &result);
00178 #endif
00179 
00180   const char* itsImagesPath;
00181   LIBRARY itsLibType;
00182 
00183   int itsMaxLum;
00184   int itsMaxCol;
00185   int itsMaxRot;
00186 
00187   static const char* ALOI_LUM[];
00188   static const char* ALOI_COL[];
00189   static const char* ALOI_ROT[];
00190 
00191   int itsSceneId;   // the current scene id
00192 
00193   std::vector<std::vector<Point2D<int> > > itsObjPolygon;
00194   std::vector<std::string> itsObjNames;
00195   std::vector<std::string> itsSceneFilenames;
00196   std::vector<ObjData> itsObjects;
00197   Image<PixRGB<byte> > itsCurrentScene;
00198   std::string itsCurrentPath;
00199 
00200   std::vector<SceneData> itsScenes;
00201   std::vector<SceneData> itsTrainScenes;
00202   std::vector<SceneData> itsTestScenes;
00203 
00204   int itsNumTraining;
00205   int itsNumTesting;
00206   int itsNumObjects;
00207 };
00208 
00209 #endif
00210 
00211 // ######################################################################
00212 /* So things look consistent in everyone's emacs... */
00213 /* Local Variables: */
00214 /* indent-tabs-mode: nil */
00215 /* End: */
Generated on Sun May 8 08:41:01 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3