segmentImage.H

Go to the documentation of this file.
00001 /*!@file VFAT/segmentImage.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/segmentImage.H $
00035 // $Id: segmentImage.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 segmentImage
00049 {
00050 private:
00051   Image<PixRGB<float> > workImage;
00052   Image<float> workImageGREY;
00053   Image<bool> candidatePixels;
00054   Image<bool> preCandidatePixels;
00055   Image<long> blobID;
00056   //! RGB values and upper and lower threshold values
00057   int red,green,blue,redLT,greenLT,blueLT,redUT,greenUT,blueUT;
00058   //! HSV vlaues and upper and lower threshold values
00059   double H,S,V,HLT,SLT,VLT,HUT,SUT,VUT;
00060   //! frame size that will be inspected
00061   int frameX1,frameY1,frameX2,frameY2;
00062   //! bools to determine if all values have been set to run image
00063   bool set1,set2,set3,set4;
00064   int doType;
00065   long num; // number of blob segments
00066   long masters; // number of masters;
00067   long mastersCount;
00068   long totalBlobs;
00069   long Hsamp,Ssamp,Vsamp,HSVcount,HSViter;
00070   // list of a pixels master
00071   std::vector<long> masterVec;
00072   std::vector<long> reOrderVec;
00073   std::vector<long> reverseOrderVec;
00074   std::vector<bool> reset;
00075   // list of blob properties
00076   std::vector<float> centerX;
00077   std::vector<float> centerY;
00078   // color properties for averageing
00079   std::vector<float> Havg;
00080   std::vector<float> Savg;
00081   std::vector<float> Vavg;
00082   std::vector<float> Hstdd;
00083   std::vector<float> Sstdd;
00084   std::vector<float> Vstdd;
00085   std::vector<float> HSVN;
00086   std::vector<long> Xsum;
00087   std::vector<long> Ysum;
00088   std::vector<long> mass;
00089   std::vector<int> xmin;
00090   std::vector<int> xmax;
00091   std::vector<int> ymin;
00092   std::vector<int> ymax;
00093   //! find any candidate pixel based upon pixel thresholding RGB
00094   void findCandidatesRGB();
00095   //! find any candidate pixel based upon pixel thresholding HSV
00096   void findCandidatesHSV();
00097   //! find any candidate pixel based upon pixel thresholding grey scale
00098   void findCandidatesGREY();
00099   //! remove single pixels without neighbors
00100   void removeSingles();
00101   //! scan candidate image and link continious pixels with a unique ID tag
00102   void discreteLinking();
00103   //! backward link pixels, find master, relabel masters
00104   void backwardLink(long slave, long master);
00105   //! combine slaves together into single blobs
00106   void combine();
00107   //! get information on blobs for debugging
00108   void getBlobs();
00109   //! Call to segmentation which calls most of these methods
00110   void doSegment();
00111 public:
00112   //! create an object. Set true for RGB false for HSV
00113   /*! skews here are used to skew the curve towards one end of the threshold
00114      that is, you pick the ideal color value as val, the you pick the
00115      cut off threshold as thresh. You can then bias towads one end or the
00116      other by setting skew to +/- value, that value bing added to the
00117      upper or lower bound for the cut off depending on whether it is
00118      +/- that is, if its a neg. value then the lower bound is
00119      extended
00120   */
00121   segmentImage(int imageType);
00122   segmentImage();
00123   ~segmentImage();
00124   //! set the red value you are looking for with thresh error, and skew
00125   void setRed(int val, int thresh, int skew);
00126   //! set the green value you are looking for with thresh error, and skew
00127   void setGreen(int val, int thresh, int skew);
00128   //! set the blue value you are looking for with thresh error, and skew
00129   void setBlue(int val, int thresh, int skew);
00130   //! set the Hue value you are looking for with thresh error, and skew
00131   void setHue(double val, double thresh, double skew);
00132   //! set the Saturation value you are looking for with thresh error, and skew
00133   void setSat(double val, double thresh, double skew);
00134   //! set the Value (brightness) value you are looking for with thresh error
00135   void setVal(double val, double thresh, double skew);
00136   //! set the region of the image to inspect
00137   void setFrame(int x1, int y1, int x2, int y2, int realX, int realY);
00138   //! set up averaging for HSV color averaging
00139   void setHSVavg(long doAvg);
00140   //! segment image based upon parameters input
00141   void segment(Image<PixRGB<float> > &image);
00142   //! segment image based upon parameters input
00143   void segment(Image<float> &image);
00144   //! merge all blobs into one big blob, useful if you erase blobs
00145   /*! else just use returnCandidates */
00146   Image<long> createMother(Image<long> &img);
00147   //! return an image with labeled blobs. Use getBlobMap to map blobs
00148   Image<long> returnBlobs();
00149   //! return a bool map off all candidate pixels
00150   Image<bool> returnCandidates();
00151   //! return a normalized displayable map off all candidate pixels
00152   Image<float> returnNormalizedCandidates();
00153   //! return the image that is being worked on, to check if its ok
00154   Image<PixRGB<float> > returnWorkImage();
00155   //! return the image that is being worked on, to check if its ok
00156   Image<float> returnWorkImageGREY();
00157   //! return the total number of blobs
00158   int numberBlobs();
00159   //! return a map of blobs that gives the numeric ID of a blob from the image
00160   std::vector<long> getBlobMap();
00161   //! calculate basic mass/center blob properties
00162   void calcMassCenter();
00163   //! get blob center in X
00164   float getCenterX(long blob);
00165   //! get blob center in X
00166   float getCenterY(long blob);
00167   //! get blob mass
00168   long getMass(long blob);
00169   //! get X min for a blob
00170   int getXmin(long blob);
00171   //! get X max for a blob
00172   int getXmax(long blob);
00173   //! get Y min for a blob
00174   int getYmin(long blob);
00175   //! get Y max for a blob
00176   int getYmax(long blob);
00177   //! get the working image size in X
00178   int getImageSizeX();
00179   //! get the working image size in Y
00180   int getImageSizeY();
00181   //! get HSV mean values and standard deviations for a blob
00182   void getHSVvalue(long blob, float *H, float *S, float *V,
00183                    float *Hstd, float *Sstd, float *Vstd);
00184   //! do HVS color value means for x last iterations
00185   void  getHSVvalueMean(long blob, float *H, float *S, float *V,
00186                         float *Hstd, float *Sstd, float *Vstd);
00187 
00188 };
00189 
00190 // ######################################################################
00191 /* So things look consistent in everyone's emacs... */
00192 /* Local Variables: */
00193 /* indent-tabs-mode: nil */
00194 /* End: */
Generated on Sun May 8 08:42:35 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3