segmentImage2.H

Go to the documentation of this file.
00001 /*!@file VFAT/segmentImage2.H Basic image segmenter blob finder using color */
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: T. Nathan Mundhenk <mundhenk@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/segmentImage2.H $
00035 // $Id: segmentImage2.H 4663 2005-06-23 17:47:28Z rjpeters $
00036 //
00037 
00038 #include "Image/All.H"
00039 #include "Image/Pixels.H"
00040 //#include <vector>
00041 #include <time.h>
00042 #include <sys/time.h>
00043 
00044 #define RGB  1
00045 #define HSV  2
00046 #define GREY 3
00047 
00048 class segmentImage2
00049 {
00050 private:
00051   Image<PixRGB<float> > SI_workImage;
00052   Image<float> SI_workImageGREY;
00053   Image<bool> SI_candidatePixels;
00054   Image<bool> SI_preCandidatePixels;
00055   Image<long> SI_blobID;
00056   //! RGB values and upper and lower threshold values
00057   int SI_red,SI_green,SI_blue,SI_redLT,SI_greenLT;
00058   int SI_blueLT,SI_redUT,SI_greenUT,SI_blueUT;
00059   //! HSV vlaues and upper and lower threshold values
00060   double SI_H,SI_S,SI_V,SI_HLT,SI_SLT,SI_VLT,SI_HUT,SI_SUT,SI_VUT;
00061   //! frame size that will be inspected
00062   int SI_frameX1,SI_frameY1,SI_frameX2,SI_frameY2;
00063   //! bools to determine if all values have been set to run image
00064   bool SI_set1,SI_set2,SI_set3,SI_set4;
00065   int SI_doType;
00066   long SI_num; // number of blob segments
00067   long SI_masters; // number of masters;
00068   long SI_mastersCount;
00069   long SI_totalBlobs;
00070   long SI_Hsamp,SI_Ssamp,SI_Vsamp,SI_HSVcount,SI_HSViter;
00071   // list of a pixels master
00072   std::vector<long> SI_masterVec;
00073   std::vector<long> SI_reOrderVec;
00074   std::vector<long> SI_reverseOrderVec;
00075   std::vector<bool> SI_reset;
00076   // list of blob properties
00077   std::vector<float> SI_centerX;
00078   std::vector<float> SI_centerY;
00079   // color properties for averageing
00080   std::vector<float> SI_Havg;
00081   std::vector<float> SI_Savg;
00082   std::vector<float> SI_Vavg;
00083   std::vector<float> SI_Hstdd;
00084   std::vector<float> SI_Sstdd;
00085   std::vector<float> SI_Vstdd;
00086   std::vector<float> SI_HSVN;
00087   std::vector<long> SI_Xsum;
00088   std::vector<long> SI_Ysum;
00089   std::vector<long> SI_mass;
00090   std::vector<int> SI_xmin;
00091   std::vector<int> SI_xmax;
00092   std::vector<int> SI_ymin;
00093   std::vector<int> SI_ymax;
00094   //! find any candidate pixel based upon pixel thresholding RGB
00095   void SIfindCandidatesRGB();
00096   //! find any candidate pixel based upon pixel thresholding HSV
00097   void SIfindCandidatesHSV();
00098   //! find any candidate pixel based upon pixel thresholding grey scale
00099   void SIfindCandidatesGREY();
00100   //! remove single pixels without neighbors
00101   void SIremoveSingles();
00102   //! scan candidate image and link continious pixels with a unique ID tag
00103   void SIdiscreteLinking();
00104   //! backward link pixels, find master, relabel masters
00105   void SIbackwardLink(long slave, long master);
00106   //! combine slaves together into single blobs
00107   void SIcombine();
00108   //! get information on blobs for debugging
00109   void SIgetBlobs();
00110   //! Call to segmentation which calls most of these methods
00111   void SIdoSegment();
00112 public:
00113   //! create an object. Set true for RGB false for HSV
00114   /*! skews here are used to skew the curve towards one end of the threshold
00115      that is, you pick the ideal color value as val, the you pick the
00116      cut off threshold as thresh. You can then bias towads one end or the
00117      other by setting skew to +/- value, that value bing added to the
00118      upper or lower bound for the cut off depending on whether it is
00119      +/- that is, if its a neg. value then the lower bound is
00120      extended
00121   */
00122   segmentImage2(int imageType);
00123   segmentImage2();
00124   ~segmentImage2();
00125   //! set the red value you are looking for with thresh error, and skew
00126   void SIsetRed(int val, int thresh, int skew);
00127   //! set the green value you are looking for with thresh error, and skew
00128   void SIsetGreen(int val, int thresh, int skew);
00129   //! set the blue value you are looking for with thresh error, and skew
00130   void SIsetBlue(int val, int thresh, int skew);
00131   //! set the Hue value you are looking for with thresh error, and skew
00132   void SIsetHue(double val, double thresh, double skew);
00133   //! set the Saturation value you are looking for with thresh error, and skew
00134   void SIsetSat(double val, double thresh, double skew);
00135   //! set the Value (brightness) value you are looking for with thresh error
00136   void SIsetVal(double val, double thresh, double skew);
00137   //! set the region of the image to inspect
00138   void SIsetFrame(int x1, int y1, int x2, int y2, int realX, int realY);
00139   //! set up averaging for HSV color averaging
00140   void SIsetHSVavg(long doAvg);
00141   //! segment image based upon parameters input
00142   void SIsegment(Image<PixRGB<float> > &image);
00143   //! segment image based upon parameters input
00144   void SIsegment(Image<float> &image);
00145   //! merge all blobs into one big blob, useful if you erase blobs
00146   /*! else just use returnCandidates */
00147   Image<long> SIcreateMother(Image<long> &img);
00148   //! return an image with labeled blobs. Use getBlobMap to map blobs
00149   Image<long> SIreturnBlobs();
00150   //! return a bool map off all candidate pixels
00151   Image<bool> SIreturnCandidates();
00152   //! return a normalized displayable map off all candidate pixels
00153   Image<float> SIreturnNormalizedCandidates();
00154   //! return the image that is being worked on, to check if its ok
00155   Image<PixRGB<float> > SIreturnWorkImage();
00156   //! return the image that is being worked on, to check if its ok
00157   Image<float> SIreturnWorkImageGREY();
00158   //! return the total number of blobs
00159   int SInumberBlobs();
00160   //! return a map of blobs that gives the numeric ID of a blob from the image
00161   std::vector<long> SIgetBlobMap();
00162   //! calculate basic mass/center blob properties
00163   void SIcalcMassCenter();
00164   //! get blob center in X
00165   float SIgetCenterX(long blob);
00166   //! get blob center in X
00167   float SIgetCenterY(long blob);
00168   //! get blob mass
00169   long SIgetMass(long blob);
00170   //! get X min for a blob
00171   int SIgetXmin(long blob);
00172   //! get X max for a blob
00173   int SIgetXmax(long blob);
00174   //! get Y min for a blob
00175   int SIgetYmin(long blob);
00176   //! get Y max for a blob
00177   int SIgetYmax(long blob);
00178   //! get the working image size in X
00179   int SIgetImageSizeX();
00180   //! get the working image size in Y
00181   int SIgetImageSizeY();
00182   //! get HSV mean values and standard deviations for a blob
00183   void SIgetHSVvalue(long blob, float *H, float *S, float *V,
00184                    float *Hstd, float *Sstd, float *Vstd);
00185   //! do HVS color value means for x last iterations
00186   void  SIgetHSVvalueMean(long blob, float *H, float *S, float *V,
00187                         float *Hstd, float *Sstd, float *Vstd);
00188 
00189 };
00190 
00191 // ######################################################################
00192 /* So things look consistent in everyone's emacs... */
00193 /* Local Variables: */
00194 /* indent-tabs-mode: nil */
00195 /* End: */
Generated on Sun May 8 08:42:35 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3