SalientRegionSegmenter.H

Go to the documentation of this file.
00001 /*!@file Gist/SalientRegionSegmenter.H segment out object depicted by the
00002 salient point. Here we use both region growing and boundary detection
00003  */
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Christian Siagian <siagian@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Gist/SalientRegionSegmenter.H $
00036 // $Id: $
00037 //
00038 //////////////////////////////////////////////////////////////////////////
00039 
00040 #ifndef SALIENT_REGION_SEGMENTER
00041 #define SALIENT_REGION_SEGMENTER
00042 
00043 #include "Gist/SuperPixel.H"  // FIXXX: need to change to GraphBasedSegmenter
00044 #include "Gist/ContourBoundaryDetector.H"
00045 #include "SIFT/Histogram.H"
00046 
00047 struct Segment
00048 {
00049   Segment() { };
00050 
00051   Segment(const int inOrgIndex,
00052           const int inContourIndex,
00053           const int inSegStartIndex,
00054           const int inSegEndIndex) :
00055     orgIndex     (inOrgIndex),
00056     contourIndex (inContourIndex),
00057     segStartIndex(inSegStartIndex),
00058     segEndIndex  (inSegEndIndex)
00059   {
00060     pVal   = 0.0;
00061     lenVal = 0.0;
00062     simVal = 0.0;
00063     strVal = 0.0;
00064     ratVal = 0.0;
00065     disVal = 0.0;
00066   }
00067 
00068   uint orgIndex;      //!< original index 
00069   uint contourIndex;  //!< contour index
00070   uint segStartIndex; //!< segment start index
00071   uint segEndIndex;   //!< segment end index
00072 
00073   float strength;     //!< raw, un-normalized strength of the segment boundary 
00074 
00075   float pVal;         //!< total priority value
00076   float lenVal;       //!< length of the contour boundary 
00077   float simVal;       //!< similarity with the closer side 
00078   float strVal;       //!< strength of boundary
00079   float ratVal;       //!< ratio of in:out
00080   float disVal;       //!< distance between point and middle of segment
00081 
00082   // we flip the sign because want non-ascending order
00083   bool operator < (const Segment& other)
00084   {
00085     return pVal > other.pVal;
00086   }
00087 };
00088 
00089 
00090 
00091 //! salient region segmenter
00092 //! which utilizes boundary detector and graph based region segmentation
00093 class SalientRegionSegmenter
00094 {
00095 public:
00096 
00097   // ######################################################################
00098   //! @name Constructor, assigment and destructor
00099   //@{
00100 
00101   //! constructor
00102   SalientRegionSegmenter();
00103 
00104   //! destructor
00105   ~SalientRegionSegmenter();
00106 
00107   //! set the input image
00108   void setImage(Image<PixRGB<byte> > image);
00109 
00110   //! get the salient region
00111   //! given the salient point
00112   Image<float> getSalientRegion(Point2D<int> pt);
00113 
00114   //@}
00115 
00116   // ######################################################################
00117   //! @name Access functions
00118   //@{
00119 
00120   //! image getter
00121   inline Image<PixRGB<byte> > getImage();
00122 
00123   //@}
00124 
00125 private:
00126 
00127   //! original input image
00128   Image<PixRGB<byte> > itsImage;
00129 
00130   //! histogram of various image features
00131   Image<rutz::shared_ptr<Histogram> > itsImageFeatureHistogram;
00132 
00133   //! contour boundary detector
00134   rutz::shared_ptr<ContourBoundaryDetector> 
00135   itsContourBoundaryDetector;
00136 
00137   //! graph based segmenter
00138   //rutz::shared_ptr<GraphBasedSegmenter> 
00139   //  itsGraphBasedSegmenter;
00140   
00141   //! the image representation of the salient region
00142   Image<float> itsSalientRegionImage;
00143 
00144   //! list of salient points
00145   //! inputted for the current image
00146   std::vector<Point2D<int> > itsSalientPoints;
00147 
00148   //! the initial group of oversegmented regions
00149   //! in image 
00150   Image<int> itsInitialRegionImage;
00151 
00152   //! the initial group of oversegmented regions
00153   //! in vectors of points
00154   std::vector<std::vector<Point2D<int> > > itsInitialRegions;
00155 
00156   //! the initial group of oversegmented regions
00157   //! in image but with average color of region
00158   Image<PixRGB<byte> > itsInitialRegionColorImage;
00159 
00160   //! the initial region adjecency list
00161   std::vector<std::vector<uint> > itsRegionAdjecencyList;
00162 
00163   //! the list of contour boundaries
00164   std::vector<rutz::shared_ptr<Contour> > itsContourBoundaries;
00165 
00166   //! store the maximum edgel strength
00167   float itsMaximumEdgelStrength;
00168 
00169   //! list of histogram entries 
00170   //! for various image features:
00171   //! FIXXX_NOTE: currently just brightness and color (from CIELab)
00172   std::vector<Image<int> > itsImageHistogramEntries;
00173 
00174   //! smoothing kernel for histogram smoothing
00175   Image<float> itsLKernel;
00176   Image<float> itsAKernel;
00177   Image<float> itsBKernel;
00178 
00179   //! store all the already computed histograms 
00180   Image<rutz::shared_ptr<Histogram> > itsComputedHistograms;
00181 
00182   //! debug window
00183   rutz::shared_ptr<XWinManaged> itsWin;
00184 
00185   // ######################################################################
00186   //! @name Compute functions (all the inner-working functions)
00187   //@{
00188 
00189   //! compute the boundaries and initial over-segmented regions 
00190   void computeBoundaryAndRegionInformation();
00191 
00192   //! compute the contour boundaries related information
00193   void computeBoundaryInformation();
00194 
00195   //! compute the initial over-segmented regions
00196   void computeRegionInformation();
00197 
00198   //! compute the region adjecency list
00199   std::vector<std::vector<uint> > getRegionAdjecencyList();
00200 
00201   //! display the region adjecency
00202   void displayRegionAdjecencyList();
00203 
00204   //! display the boundaries and over-segmented regions   
00205   void displayBoundaryAndRegionInformation();
00206 
00207   //! the main function 
00208   //! to estimate the salient region
00209   void computeSalientRegion();
00210 
00211   //! fill the segment with contour boundary segments 
00212   //! sorted of most likely fit
00213   std::list<Segment> fillSegmentQueue(Point2D<int> pt);
00214 
00215   //! set the priority for this segment
00216   void setPriority(Segment &segment, Point2D<int> pt);
00217   
00218   //! get histogram distribution around the point
00219   Histogram getHistogramDistribution(Point2D<int> pt);
00220 
00221   //! get histogram distribution from a list of points
00222   Histogram getHistogramDistribution (std::vector<Point2D<int> > pts);
00223 
00224   //! get point distribution around a segment
00225   //! dist1 always the one closer to the point pt
00226   void getSegmentPointDistributions
00227   (Segment segment, Point2D<int> pt, 
00228    std::vector<Point2D<int> > &pts1, 
00229    std::vector<Point2D<int> > &pts2);
00230 
00231   //! compute the image feature histogram values
00232   void setImageFeatureHistogramValues();
00233 
00234   //! quantize values to histogram bins
00235   Image<int> quantize_values
00236   (Image<float> image, int num_bins, bool normalize = false);
00237 
00238   //! filter out invalid segments 
00239   void filterSegments(std::list<Segment> &segments);
00240 
00241   //! adding unvisited neighbors
00242   void addUnvisitedNeighbors
00243   (std::vector<Point2D<int> > &currentUnassignedLocations, 
00244    Point2D<int> currPoint, 
00245    Image<int> &assignmentMap);
00246 
00247   //! get the pixels connecting the passed in points
00248   std::vector<Point2D<int> > getLine
00249   (Point2D<int> p1, Point2D<int> p2);
00250 
00251   //! assign regions next to the segment
00252   void assignRegionsAroundSegment
00253   (Segment segment, 
00254    std::vector<Point2D<int> > pts2, 
00255    std::vector<Point2D<int> > pts3, 
00256    Image<int>                 &assignmentMap,
00257    std::vector<Point2D<int> > &currentObjectLocations,
00258    std::vector<Point2D<int> > &currentBackgroundLocations,
00259    std::vector<Point2D<int> > &currentUnassignedLocations,
00260    Image<int>       &regionAssignmentMap,
00261    std::vector<int> &currentObjectRegionList, 
00262    std::vector<int> &currentBackgroundRegionList);
00263 
00264   //! display the distribution setup
00265   void displayDistributionSetup
00266   (Segment segment, Point2D<int> pt, 
00267    std::vector<Point2D<int> > pts2, 
00268    std::vector<Point2D<int> > pts3);
00269 
00270   //! display the current state of growing
00271   void displayGrowMap
00272   (Image<int> assignmentMap, Point2D<int> currPoint,
00273    std::vector<Point2D<int> > currentObjectLocations,
00274    std::vector<Point2D<int> > currentObjectCoreLocations,
00275    std::vector<Point2D<int> > currentBackgroundLocations,
00276    std::vector<Point2D<int> > currentUnassignedLocations,
00277    Image<bool> isComparedWith, Segment segment);
00278   
00279   //@}
00280 };
00281 
00282 // ######################################################################
00283 // Implementation for SalientRegionSegmenter inline functions
00284 // ######################################################################
00285 inline Image<PixRGB<byte> > SalientRegionSegmenter::getImage()
00286 { return itsImage; }
00287 
00288 #endif
00289 
00290 // ######################################################################
00291 /* So things look consistent in everyone's emacs... */
00292 /* Local Variables: */
00293 /* indent-tabs-mode: nil */
00294 /* End: */
Generated on Sun May 8 08:04:48 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3