segmentImageMC.H

Go to the documentation of this file.
00001 /*!@file VFAT/segmentImageMC.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/segmentImageMC.H $
00035 // $Id: segmentImageMC.H 6006 2005-11-29 22:34:22Z rjpeters $
00036 //
00037 
00038 // ############################################################
00039 // ############################################################
00040 // ##### --- VFAT ---
00041 // ##### Vision Feature Analysis Tool:
00042 // ##### T. Nathan Mundhenk nathan@mundhenk.com
00043 // ##### Laurent Itti itti@pollux.usc.edu
00044 // #####
00045 // ############################################################
00046 // ############################################################
00047 
00048 #ifndef SEGMENTIMAGEMC_H_DEFINED
00049 #define SEGMENTIMAGEMC_H_DEFINED
00050 
00051 #include "Image/All.H"
00052 #include "Image/Pixels.H"
00053 #include <time.h>
00054 #include <sys/time.h>
00055 
00056 //*******************************************
00057 /* ABOUT THE USE OF TEMPLATES HERE
00058 
00059  the INT value is an integer number and should be an unsigned
00060  number (but isn't required to be). However, for images larger
00061  than 256x256 after decimation
00062  e.g. that contain more than 2^16 pixels, you should use a long instead
00063  this is because the number of blobs may be as large as the number
00064  of pixels.
00065 
00066  the FLOAT is for a floating point. A double may be used to obtain more
00067  accurate values at run time. This is at your discression
00068 
00069 */
00070 
00071 //! Define the template declaration for this class
00072 #define SI_TEMPLATE_CLASS <class FLOAT, class INT, unsigned int SI_channels>
00073 //! further define templates for this class
00074 #define SI_TEMPLATE       FLOAT,INT,SI_channels
00075 //! This is a class to track hyper spectal blobs
00076 /*! This class is most likely called by segmentImageTrackMC and will
00077     segment images by linking pixels and the corresponding image
00078     regions by linked stripes. It will also segregate each blob and
00079     track it seperately.
00080 */
00081 template SI_TEMPLATE_CLASS class segmentImageMC
00082 {
00083 private:
00084   Image<PixRGB<byte> > *SI_workImage;
00085   Image<bool> SI_candidatePixels;
00086   Image<bool> SI_preCandidatePixels;
00087   Image<long> SI_blobID;
00088   typename std::vector<Image<FLOAT> > *SI_featureMaps;
00089   typename std::vector<Image<FLOAT> > SI_infeatureMaps;
00090 
00091   //! values for lower threshold values
00092   typename std::vector<FLOAT> SI_lowThresh;
00093   //! values for upper threshold values
00094   typename std::vector<FLOAT> SI_highThresh;
00095   //! frame size that will be inspected
00096   int SI_frameX1,SI_frameY1,SI_frameX2,SI_frameY2;
00097   //! bools to determine if all values have been set to run image
00098   bool SI_set1,SI_set2,SI_set3,SI_set4;
00099   //! set to false to not use band pass filter on candidates
00100   bool SI_useCandidateBandPass;
00101   int SI_doType;
00102   INT SI_num; // number of blob segments
00103   INT SI_masters; // number of masters;
00104   INT SI_mastersCount;
00105   INT SI_totalBlobs;
00106   INT SI_count;
00107   INT SI_iter;
00108   INT SI_maxIDVal;
00109   // list of a pixels master
00110   std::vector<long> SI_masterVec;
00111   typename std::vector<INT> SI_reOrderVec;
00112   typename std::vector<INT> SI_reverseOrderVec;
00113   std::vector<bool> SI_reset;
00114   // list of blob properties
00115   std::vector<FLOAT> SI_centerX;
00116   std::vector<FLOAT> SI_centerY;
00117   // color properties for averageing
00118   typename std::vector<std::vector<FLOAT> > SI_avg;
00119   typename std::vector<std::vector<FLOAT> > SI_std;
00120   typename std::vector<FLOAT> SI_tempAvg;
00121   typename std::vector<FLOAT> SI_tempStd;
00122   typename std::vector<INT> SI_N;
00123   typename std::vector<INT> SI_Xsum;
00124   typename std::vector<INT> SI_Ysum;
00125   typename std::vector<INT> SI_mass;
00126   std::vector<int> SI_xmin;
00127   std::vector<int> SI_xmax;
00128   std::vector<int> SI_ymin;
00129   std::vector<int> SI_ymax;
00130   //! find any candidate pixel based upon pixel thresholding RGB
00131   void SIfindCandidates();
00132   //! find any candidate pixel based upon pixel thresholding RGB
00133   void SIfindCandidatesNoBandPass();
00134   //! remove single pixels without neighbors
00135   void SIremoveSingles();
00136   //! remove single pixels without neighbors, iterator version with weird mem
00137   void SIremoveSinglesItr();
00138   //! scan candidate image and link continious pixels with a unique ID tag
00139   void SIdiscreteLinking();
00140   //! variant on discrete linking works orthogonally with iterators
00141   void SIdiscreteLinkingOrtho();
00142   //! backward link pixels, find master, relabel masters
00143   void SIbackwardLink(INT *slave, INT *master);
00144   //! combine slaves together into single blobs
00145   void SIcombine();
00146   //! get information on blobs for debugging
00147   void SIgetBlobs();
00148   //! Call to segmentation which calls most of these methods
00149   void SIdoSegment();
00150 public:
00151   //! create an object. Set true for RGB false for HSV
00152   /*! skews here are used to skew the curve towards one end of the threshold
00153      that is, you pick the ideal color value as val, the you pick the
00154      cut off threshold as thresh. You can then bias towads one end or the
00155      other by setting skew to +/- value, that value bing added to the
00156      upper or lower bound for the cut off depending on whether it is
00157      +/- that is, if its a neg. value then the lower bound is
00158      extended
00159   */
00160   segmentImageMC();
00161   ~segmentImageMC();
00162   //! set the Value (brightness) value you are looking for with thresh error
00163   void SIsetVal(typename std::vector<FLOAT> &val,
00164                 typename std::vector<FLOAT> &thresh,
00165                 typename std::vector<FLOAT> &skew);
00166   //! set the region of the image to inspect
00167   void SIsetFrame(int *x, int *y);
00168   //! Call during run if color is totally reset
00169   void SIresetCandidates(bool whichWay);
00170   //! set up averaging for color averaging adaptation
00171   void SIsetAvg(INT doAvg);
00172   //! reset averaging for color averaging adaptation
00173   void SIresetAvg();
00174   //! segment image based upon parameters input
00175   void SIsegment(Image<PixRGB<byte> > *image,
00176                  typename std::vector<Image<FLOAT> > *featureMap,
00177                  bool lowPass = false);
00178   //! toggle band pass filter on candidate pixels on/off
00179   void SItoggleCandidateBandPass(bool toggle);
00180   //! merge all blobs into one big blob, useful if you erase blobs
00181   /*! else just use returnCandidates */
00182   Image<INT> SIcreateMother(Image<INT> &img);
00183   //! return an image with labeled blobs. Use getBlobMap to map blobs
00184   Image<long> SIreturnBlobs();
00185   //! return a bool map off all candidate pixels
00186   Image<bool> SIreturnCandidates();
00187   //! return a normalized displayable map off all candidate pixels
00188   Image<FLOAT> SIreturnNormalizedCandidates();
00189   //! return the image that is being worked on, to check if its ok
00190   Image<PixRGB<FLOAT> > SIreturnWorkImage();
00191   //! return the total number of blobs
00192   INT SInumberBlobs();
00193   //! return a map of blobs that gives the numeric ID of a blob from the image
00194   std::vector<INT> SIgetBlobMap();
00195   //! calculate basic mass/center blob properties
00196   void SIcalcMassCenter();
00197   //! get blob center in X
00198   FLOAT SIgetCenterX(INT blob);
00199   //! get blob center in X
00200   FLOAT SIgetCenterY(INT blob);
00201   //! get blob mass
00202   INT SIgetMass(INT blob);
00203   //! get X min for a blob
00204   int SIgetXmin(INT blob);
00205   //! get X max for a blob
00206   int SIgetXmax(INT blob);
00207   //! get Y min for a blob
00208   int SIgetYmin(INT blob);
00209   //! get Y max for a blob
00210   int SIgetYmax(INT blob);
00211   //! get the working image size in X
00212   int SIgetImageSizeX();
00213   //! get the working image size in Y
00214   int SIgetImageSizeY();
00215   //! get HSV mean values and standard deviations for a blob
00216   void SIgetValue(INT *blob, typename std::vector<FLOAT> *mean,
00217                   typename std::vector<FLOAT> *std, INT *in);
00218   //! do HVS color value means for x last iterations
00219   void SIgetValueMean(INT *blobListSize,
00220                       std::vector<INT> *blobList,
00221                       typename std::vector<FLOAT> *mean,
00222                       typename std::vector<FLOAT> *std,
00223                       FLOAT *mass);
00224 };
00225 
00226 // ######################################################################
00227 /* So things look consistent in everyone's emacs... */
00228 /* Local Variables: */
00229 /* indent-tabs-mode: nil */
00230 /* End: */
00231 
00232 #endif
Generated on Sun May 8 08:42:35 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3