featureClusterVision.H

Go to the documentation of this file.
00001 /*!@file VFAT/featureClusterVision.H  Test the nonparametric classifier
00002  */
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: T Nathan Mundhenk <mundhenk@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/featureClusterVision.H $
00036 // $Id: featureClusterVision.H 9412 2008-03-10 23:10:15Z farhan $
00037 //
00038 
00039 // ############################################################
00040 // ############################################################
00041 // ##### --- VFAT ---
00042 // ##### Vision Feature Analysis Tool:
00043 // ##### T. Nathan Mundhenk nathan@mundhenk.com
00044 // ##### Laurent Itti itti@pollux.usc.edu
00045 // #####
00046 // ############################################################
00047 // ############################################################
00048 
00049 #include "Component/ModelComponent.H"
00050 #include "Component/OptionManager.H"
00051 #include "Image/All.H"
00052 #include "Image/Pixels.H"
00053 #include "Image/Point2D.H"
00054 #include "Media/FrameSeries.H"
00055 #include "Neuro/SaliencyMap.H"
00056 #include "Neuro/StdBrain.H"
00057 #include "Neuro/VisualCortex.H"
00058 #include "Raster/Raster.H"
00059 #include "Raster/Raster.H"
00060 #include "Util/Timer.H"
00061 #include "Util/Types.H"
00062 #include "Util/log.H"
00063 #include "Util/readConfig.H"
00064 #include "VFAT/NPclassify2.H"
00065 #include "VFAT/findColorIndex.H"
00066 #include "VFAT/readMatrix.H"
00067 #include "rutz/shared_ptr.h"
00068 #include <stdlib.h>
00069 #include <string>
00070 #include <sys/types.h>
00071 
00072 //! main class for VFAT. This combines all the methods etc.
00073 /*! this class takes NPclassify2, covEstimate, Brain/saliency
00074     as well as ICA/PCA methods to create a saliency based tracking
00075     and simple identification program.
00076 
00077     There are also many test methods for the different elements in
00078     this class
00079 */
00080 
00081 template <class FLOAT>
00082 class featureClusterVision : public ModelComponent
00083 {
00084 private:
00085   //! map of statistically salient points from montyMap
00086   std::vector<Point2D<int> > fCV_cmap;
00087   //! old copy of particles
00088   std::vector<Point2D<int> > fCV_cmapOld;
00089   //! map of sparse points (to cmap points) from sparcifier
00090   std::vector<Point2D<int>*> fCV_rmap;
00091   //! this number is used by the saccade data if needed
00092   std::vector<Point2D<int> > fCV_jumpTo;
00093   //! link map to feature values for given points
00094   typename std::vector<std::vector<FLOAT> > fCV_fmap;
00095   //! space after ICA and post processing to be clustered
00096   typename std::vector<std::vector<FLOAT> > fCV_space;
00097   //! This is a mixture of oreintation channles to rotation invariant texture
00098   typename std::vector<std::vector<FLOAT> > fCV_mixedRotation;
00099   //! This is a mixture of motion channles to rotation invariant texture
00100   typename std::vector<std::vector<FLOAT> > fCV_mixedMotion;
00101   //! This is a mixture of oreintation channles to rotation invariant texture
00102   typename std::vector<std::vector<PixH2SV2<FLOAT> > > fCV_mixedRotationH2SV2;
00103   //! This holds a set of features obtained from stand alone filters
00104   typename std::vector<std::vector<PixH2SV2<FLOAT> > > fCV_standAloneFeatures;
00105   //! This holds a set of features obtained from stand alone filters
00106   typename std::vector<std::vector<PixH2SV2<FLOAT> > > fCV_standAloneFeaturesSin;
00107   //! This holds a set of features obtained from stand alone filters
00108   typename std::vector<std::vector<PixH2SV2<FLOAT> > > fCV_standAloneFeaturesCos;
00109   //! list of covarience matrices
00110   typename std::vector<std::vector<FLOAT*> > fCV_unmixedMap;
00111 
00112   //! list of the classes for each point
00113   std::vector<std::vector<int*> >* fCV_classList;
00114   //! clustered feature list
00115   typename std::vector<std::vector<std::vector<FLOAT*> > > fCV_sortedSpace;
00116   //! gives the size of each matrix, that is features per channel
00117   std::vector<int> fCV_featureMatrixSizes;
00118   //! how many features per channel following ICA
00119   std::vector<int*> fCV_ICAfeaturesPerChannel;
00120   //! this is an index label for saccade data from file if used
00121   std::vector<int> fCV_indexNumber;
00122   //! this is a constant to normalize this feature from 0 to 1 or -1 to 1
00123   typename std::vector<FLOAT> fCV_featureNormConst;
00124   typename std::vector<FLOAT> fCV_featureTransConst;
00125   //! holds results of low pass at location
00126   typename std::vector<PixRGB<FLOAT> > fCV_lowPassVector;
00127 
00128 
00129   //! The unmixed features from ICAemacsc
00130   typename std::vector<Image<FLOAT> > fCV_Unmixed;
00131   //! ICA unmixing Matrices
00132   typename std::vector<Image<FLOAT> > fCV_ICAunmix;
00133   //! Sine type gabor filters
00134   typename std::vector<Image<FLOAT> > fCV_gaborFiltersSin;
00135   //! Cosine type gabor filters
00136   typename std::vector<Image<FLOAT> > fCV_gaborFiltersCos;
00137   //! This ia a pointer to a bunch of conspicuity maps for no-brain use
00138   typename std::vector<Image<FLOAT> > *fCV_cmaps;
00139 
00140 
00141   //! sorted classes by size
00142   std::vector<long> fCV_sortClassSize;
00143   std::vector<long> fCV_sortClassMember;
00144   //! A list of each features name
00145   std::vector<std::string> fCV_featureName;
00146   //! Post ICA feature name list
00147   std::vector<std::string*> fCV_featureNameICA;
00148   //! this is a filler string for pointers
00149   std::string fCV_NULLstring;
00150   //! the name of the low pass kernel file
00151   std::string fCV_lowPassKernelName;
00152   long fCV_sortCount;
00153   //! how many feature channels are you dealing with
00154   int fCV_channelNumbers;
00155   //! many total features are there
00156   int fCV_totalFeatures;
00157   //! how many total features are there potentially, including ignored features
00158   int fCV_totalPotFeatures;
00159   //! How many features are there per channel
00160   int fCV_featuresPerChannel;
00161   //! counters for features selected
00162   int fCV_countMM, fCV_countSM;
00163   //! image size values for salmap
00164   int fCV_sizeX, fCV_sizeY;
00165   FLOAT fCV_sizeXbias, fCV_sizeYbias;
00166   //! offset into feature set of orientations
00167   int fCV_oriOffset;
00168   //! offset into feature set of motion
00169   int fCV_motOffset;
00170   //! offset into V2 junction process
00171   int fCV_mixOffset;
00172   //! spatial component offset
00173   int fCV_spatOffset;
00174   //! offset into color features
00175   int fCV_colorOffset;
00176   //! offset into combined motion channel
00177   int fCV_motionCombinedOffset;
00178   //! reduced feature set size
00179   int fCV_reducedFeatureCount;
00180   //! how many sparce points do you want?
00181   int fCV_sparcePoints;
00182   //! holder for a new matrix size
00183   int fCV_newMatSize;
00184   //! this is the type of low pass filter to use for color extraction
00185   int fCV_lowPassType;
00186   //! amount of decimation to apply to monte carlo mapping
00187   int fCV_monteDec;
00188 
00189   //! size of data set of features
00190   unsigned int fCV_covDataSizeLast;
00191   unsigned int fCV_covDataSizeCurrent;
00192   unsigned int fCV_covDataSizeMatch;
00193   //! how many scale reductions to perform on image in gabor filter
00194   unsigned int fCV_gaborScales;
00195   //! Which feaures are turned on
00196   bool fCV_blueYellowOn, fCV_redGreenOn, fCV_flickerOn, fCV_lumOn, fCV_oriOn;
00197   bool fCV_motionOn, fCV_spatialOn, fCV_mixAlphaOn, fCV_mixBetaOn;
00198   bool fCV_mixGammaOn;
00199   bool fCV_redOn, fCV_greenOn, fCV_blueOn, fCV_yellowOn;
00200   bool fCV_hueOn, fCV_satOn, fCV_valOn;
00201   bool fCV_hue1On, fCV_hue2On;
00202   bool fCV_motionCombinedOn;
00203   //! tells if we should use a quarter size reduction image pyramid
00204   bool fCV_gaborUseQuarter;
00205   //! these are the weights for each feature
00206   FLOAT fCV_redGreenWeight, fCV_blueYellowWeight, fCV_flickerWeight;
00207   FLOAT fCV_lumWeight, fCV_oriWeight, fCV_motionWeight, fCV_spatialWeight;
00208   FLOAT fCV_mixAlphaWeight, fCV_mixBetaWeight, fCV_mixGammaWeight;
00209   FLOAT fCV_redWeight, fCV_greenWeight, fCV_blueWeight, fCV_yellowWeight;
00210   FLOAT fCV_hueWeight, fCV_satWeight, fCV_valWeight;
00211   FLOAT fCV_hue1Weight, fCV_hue2Weight;
00212   FLOAT fCV_motionCombinedWeight;
00213   //! these are a few pointers to some selected normalizers
00214   FLOAT *fCV_redNorm, *fCV_greenNorm, *fCV_blueNorm, *fCV_yellowNorm;
00215   FLOAT *fCV_hueNorm, *fCV_satNorm, *fCV_valNorm;
00216   FLOAT *fCV_hue1Norm, *fCV_hue2Norm;
00217   //! these are a few pointers to some selected normalizers
00218   FLOAT *fCV_redTrans, *fCV_greenTrans, *fCV_blueTrans, *fCV_yellowTrans;
00219   FLOAT *fCV_hueTrans, *fCV_satTrans, *fCV_valTrans;
00220   FLOAT *fCV_hue1Trans, *fCV_hue2Trans;
00221   //! how many features per channel on each channel after ICA
00222   int fCV_ICAfeaturesRedGreen, fCV_ICAfeaturesBlueYellow;
00223   int fCV_ICAfeaturesFlicker, fCV_ICAfeaturesLum;
00224   int fCV_ICAfeaturesMotion, fCV_ICAfeaturesOri;
00225   int fCV_ICAfeaturesSpatial, fCV_ICAfeaturesAlpha;
00226   int fCV_ICAfeaturesBeta, fCV_ICAfeaturesGamma;
00227   int fCV_ICAfeaturesRed, fCV_ICAfeaturesGreen;
00228   int fCV_ICAfeaturesBlue, fCV_ICAfeaturesYellow;
00229   int fCV_ICAfeaturesHue, fCV_ICAfeaturesSat;
00230   int fCV_ICAfeaturesVal;
00231   int fCV_ICAfeaturesHue1, fCV_ICAfeaturesHue2;
00232   int fCV_ICAfeaturesMotionCombined;
00233   //! these are max values on these features
00234   FLOAT fCV_maxMotVal, fCV_maxOriVal;
00235   //! this is the exponent to be applied to the saliency map
00236   FLOAT fCV_saliencyExp;
00237   //! amount of bias to pass from one cluster to the next (Markovian)
00238   FLOAT fCV_NPtemporalBias;
00239   //! bias for recycling particles in x*standard deviation
00240   FLOAT fCV_densityBias;
00241   //! bias over salmap low pass
00242   FLOAT fCV_salmapLowPassTemporalBias;
00243   //! the standard deviation for gabor filters
00244   FLOAT fCV_gaborStandardDev;
00245   //! the period for gabor filters
00246   FLOAT fCV_gaborPeriod;
00247 
00248   //! do the bias, or just set it
00249   bool fCV_doSLPTB;
00250   //! this is true if you want to print out clusters
00251   bool fCV_printOutClusters;
00252   //! this is true if you want to see the basic feature maps
00253   bool fCV_printOutFeatures;
00254   //! print output on the real image input
00255   bool fCV_doReal;
00256   //! is true if NPclassify is to be biased by the last iteration
00257   bool fCV_doNPbias;
00258   //! do you want to write out time stats to a file
00259   bool fCV_useTimerFile;
00260   //! do we use a brain for saliency and features?
00261   bool fCV_useBrain;
00262 
00263   //! Which alternation of covHolder are we using
00264   //bool fCV_useCovHolderUp;
00265   //! What is the current covholder we are using
00266   unsigned int fCV_currentCovHolder;
00267   //! on first iteration set all matched to themselves
00268   bool fCV_doMatchSelf;
00269   //! The real image to write to
00270   Image<PixRGB<FLOAT> > fCV_realImage;
00271   //! low pass version of real image
00272   Image<PixRGB<FLOAT> > fCV_realImageLowPass;
00273   //! H2SV2 version of real image
00274   Image<PixH2SV2<FLOAT> > fCV_realImageH2SV2;
00275   //! H2SV2 low pass version of real image
00276   Image<PixH2SV2<FLOAT> > fCV_realImageH2SV2LowPass;
00277   //! average temporal band pass over salmap
00278   Image<FLOAT> fCV_salmapLowPass;
00279   //! low pass kernel for individual use
00280   Image<FLOAT> fCV_lowPassKernel;
00281   //! output result image suitable for framing : classes
00282   Image<PixRGB<FLOAT> > fCV_outImageClasses;
00283   //! output result image suitable for framing : classes across time
00284   Image<PixRGB<FLOAT> > fCV_outImageTemporal;
00285   //! output result image suitable for framing : temporal target
00286   Image<PixRGB<FLOAT> > fCV_outImageTarget;
00287   //! salmap pointer to use in no-brain condition
00288   Image<FLOAT> *fCV_noBrainSalmap;
00289 
00290   //! the name of the real image
00291   std::string fCV_fileName;
00292   //! this is a map vector that points to the feature on values
00293   std::vector<bool*> fCV_featureOn;
00294   //! this is a list of particles which are to be kept
00295   std::vector<bool> fCV_keepParticle;
00296   //! the total number of channels turned on
00297   int fCV_channelsOn;
00298   //! this is a map vector that points to the weight values
00299   std::vector<FLOAT*> fCV_weights;
00300   //! brain
00301   nub::soft_ref<StdBrain> fCV_brain;
00302   //! point to input frames
00303   nub::soft_ref<InputFrameSeries> fCV_iframes;
00304   //! shared pointer to sal map
00305   nub::soft_ref<SaliencyMap> fCV_SM;
00306   //! shared pointer to visual cortex
00307   nub::soft_ref<VisualCortex> fCV_VC;
00308   //! NP classify object
00309   NPclassify2<FLOAT> fCV_NP;
00310   //! covEstimate Constructor
00311   covEstimate<double> fCV_CV;
00312   //! template for resizing covHolder on the fly
00313   covHolder<double> fCV_tcov;
00314 
00315   //! an array of covarriance data
00316   std::vector<covHolder<double> > *fCV_covHolderCurrent;
00317   std::vector<covHolder<double> > *fCV_covHolderLast;
00318   //std::vector<covHolder<FLOAT> > fCV_covHolderUp;
00319   //std::vector<covHolder<FLOAT> > fCV_covHolderDown;
00320   std::vector<covHolder<double> > fCV_covHolderMatch;
00321   std::vector<std::vector<covHolder<double> > > fCV_covHolder;
00322   //! private methods
00323   void fCVswitchCov();
00324   void fCVlowPass();
00325   void fCVfindFeaturesBrain();
00326   void fCVfindFeaturesNoBrain();
00327   void fCVfindFeaturesFromFile(std::string fileName);
00328   void fCVrunICA();
00329   void fCVrunNPclassify();
00330   void fCVrunCovEstimate();
00331   void fCVcheckParticles();
00332   void fCVmatchClassTemporal();
00333   void fCVsetImageParams();
00334   void fCVresizeMaps1(int sparcePoints);
00335   void fCVresizeMaps2(int sparcePoints, int newMatSize);
00336   void fCVcreateGaborFilters();
00337 public:
00338   featureClusterVision(OptionManager& mgr,
00339                        const std::string& descrName,
00340                        const std::string& tagName,
00341                        nub::soft_ref<StdBrain>& _brain,
00342                        nub::soft_ref<InputFrameSeries>& _ifs,
00343                        const std::string& extraArg0);
00344 
00345   //! fCV without a std brain, user must supply saliency stuff externally
00346   featureClusterVision(OptionManager& mgr,
00347                        const std::string& descrName,
00348                        const std::string& tagName,
00349                        Image<FLOAT> *salMap,
00350                        typename std::vector<Image<FLOAT> > *cmaps,
00351                        nub::soft_ref<InputFrameSeries>& _ifs,
00352                        const std::string& extraArg0);
00353   ~featureClusterVision();
00354 
00355   //! called by default constructor to initialize this class
00356   void fCVsetUpfCV(OptionManager& mgr,
00357                    const std::string& descrName,
00358                    const std::string& tagName,
00359                    nub::soft_ref<InputFrameSeries>& _ifs,
00360                    const std::string& extraArg0);
00361 
00362 
00363   //! When called, this mixes the four channels together into a single channle
00364   /*! This works by finding the normalized difference between the output
00365     of two orthogonal channles. Then it averages the results over all the
00366     channels specified. This works to find the rotation invariant
00367     properties of orientation responses.
00368     @param data This is the raw channle input
00369     @param ch1a this is the first channle input
00370     @param ch1b this is the orthogonal channel to ch1a
00371     @param ch2a this is the second channel set to work in
00372     @param ch2b this is the orthogonal channel to ch2a
00373     @param outAlpha this is a vector of the mixed channels strength
00374     @param outBeta this is a vector of the mixed channels line clearity
00375     @param outGamma this is a vector of the mixed channels junction clearity
00376     @param norm1 this is a normalizer over ch1a and ch1b (e.g. Max value)
00377     @param norm2 this is a normalizer over ch2a and ch2b (e.g. Max value)
00378   */
00379   void fCVmixChannels(std::vector<std::vector<FLOAT> > *data,
00380                    int ch1a, int ch1b,
00381                    int ch2a, int ch2b,
00382                    typename std::vector<FLOAT> *outAlpha,
00383                    typename std::vector<FLOAT> *outBeta,
00384                    typename std::vector<FLOAT> *outGamma,
00385                    FLOAT norm1, FLOAT norm2,
00386                    int size);
00387   //! When called, this mixes the four channels together into a single channle
00388   /*! This works by finding the normalized difference between the output
00389     of two orthogonal channles. Then it averages the results over all the
00390     channels specified. This works to find the rotation invariant
00391     properties of orientation responses. This is like the other mixChannels
00392     however, this works off of Image class images.
00393     @param img0 An image filtered at 0 degrees
00394     @param img45 An image filtered at 45 degrees
00395     @param img90 An image filtered at 90 degrees
00396     @param img135 An image filtered at 135 degrees
00397     @param Alpha This is an image of lineyness in an image
00398     @param Beta This is an image of the crossyness in an image
00399     @param Gamma This is the junction results with crisp crosses
00400     @param norm1 This is a normalizer in (img0+img90)/norm
00401     @param norm2 This is a normalizer in (img45+img135)/norm
00402   */
00403   void fCVmixChannels(Image<FLOAT> &img0, Image<FLOAT> &img45,
00404                    Image<FLOAT> &img90, Image<FLOAT> &img135,
00405                    Image<FLOAT> *Alpha, Image<FLOAT> *Beta,
00406                    Image<FLOAT> *Gamma);
00407   //! This calles mixChannels over the entire dataset
00408   void fCVfindMixedChannels();
00409   //! when called this extracts the features at the most salient point
00410   /*! Most likely you will not need to ever call this unless you are just
00411     trying to get the most salient points plus the mixed orientations
00412   */
00413   void fCVcheckMixing();
00414   //! When called this will print out an ICA/PCA representation of each channle
00415   /*! This shows the end result of the ICA/PCA process on each feature
00416     channel
00417   */
00418   void fCVcheckICA();
00419   //! When called this will print out an ICA/PCA representation of each channle
00420   /*! This shows the end result of the ICA/PCA process on this feature
00421     channel
00422   */
00423   void fCVcheckICA(int channel, bool findMixed);
00424   //! check the output from the combined motion channel
00425   void fCVcheckMotionCombined(long frame);
00426   //! when called this will output features to a file and quit
00427   //! when called this will output post ICA features to a file and quit
00428   void fCVfeaturesToFile(std::string fileName, bool _new);
00429   //! check stand alone feature extraction
00430   void fCVrunStandAloneMSBatchFilter(std::string filename);
00431   //! check stand alone feature extraction
00432   void fCVrunStandAloneMSBatchTest(std::string filename);
00433 
00434   void fCVICAfeaturesToFile(std::string fileName);
00435   //! main method to call for most purposes
00436   void fCVclusterImage();
00437   //! A test method to use with raw saccade data
00438   void fCVsaccadeTest(std::string _maskFile, std::string _outFile, std::string _label,
00439                    std::string _fileName);
00440   //! test stand alone feature extraction
00441   void fCVstandAloneFeatureTest(std::string _fileName);
00442   //! fetches an images base statistics
00443   void fCVgetImageBaseStats(std::string _maskFile, std::string _imageFile,
00444                             std::string _outFile, std::string _label);
00445   //! fetches an images base statistics
00446   void fCVgetImageComplexStats(std::string _maskFile, std::string _imageFile,
00447                             std::string _outFile, std::string _label);
00448 
00449   //! upload a raw copy of the image
00450   void fCVuploadImage(Image<PixRGB<byte> > &input, std::string fileName);
00451   void fCVprintOutClusters();
00452   void fCVprintOutCovSlices(int sizeX,int sizeY);
00453   void fCVprintOutBayesClass();
00454   void fCVprintOutNeighborClass();
00455   void fCVdumpCovMatrix(std::string fileName);
00456   //! get the signature data from this class
00457   std::vector<covHolder<double> > fCVgetCovHolders();
00458   //! how many signatures do we have
00459   unsigned int fCVgetCovHolderSize();
00460   //! get back images of clusters for analysis
00461   void fCVgetClusterImages(Image<PixRGB<FLOAT> > *classImage,
00462                            Image<PixRGB<FLOAT> > *temporalImage,
00463                            Image<PixRGB<FLOAT> > *targetImage,
00464                            Image<FLOAT> *salMap);
00465   void fCVprocessOutSaccadeData(std::string maskFile, std::string outFile, std::string _label);
00466 };
00467 
00468 
00469 
00470 
00471 
Generated on Sun May 8 08:42:34 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3