00001 /*!@file SIFT/FeatureVector.H Feature vector for SIFT obj recognition */ 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: James Bonaiuto <bonaiuto@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SIFT/FeatureVector.H $ 00035 // $Id: FeatureVector.H 14156 2010-10-21 21:21:11Z lior $ 00036 // 00037 00038 #ifndef FEATUREVECTOR_H_DEFINED 00039 #define FEATUREVECTOR_H_DEFINED 00040 00041 #include "Util/Types.H" 00042 #include <vector> 00043 #include "Image/Image.H" 00044 #include "Image/Pixels.H" 00045 00046 00047 // ######################################################################## 00048 //! The FeatureVector class 00049 // ######################################################################## 00050 /*! Stores temporary SIFT Keypoint features. The final feature vector 00051 in a SIFT Keypoint object is composed of bytes while here we use 00052 floats and are an intermediary onto which we can do normalizations 00053 and such before injecting into a Keypoint. A FeatureVector has 128 00054 bins, corresponding to 4 bins for x * 4 bins for y * 4 bins for 00055 orientation. */ 00056 class FeatureVector 00057 { 00058 public : 00059 //! Constructor, xSize,ySize,zSize the size of bins, wrap zBin ? 00060 FeatureVector(int xSize=4, int ySize=4, int zSize=8, bool wrapZ=true); 00061 00062 //! Destructor 00063 ~FeatureVector(); 00064 00065 //! get a value from the feature vector 00066 float getValue(const uint index) const; 00067 00068 //! add value 00069 /*! Linearly add a value. Indices are as follows: 00070 0.0 <= x <= 4.0 : [0 .. 3] x=2.0 falls equally between bins 1 and 2; 00071 0.0 <= y <= 4.0 : [0 .. 3] y=2.0 falls equally between bins 1 and 2; 00072 0.0 <= o <= 8.0 : [0 .. 7] o=4.0 falls equally between bins 3 and 4 */ 00073 void addValue(const float x, const float y, const float orientation, 00074 const float value); 00075 00076 //! normalize Vector 00077 void normalize(); 00078 00079 //! threshold Vector and renormalize 00080 void threshold(const float limit); 00081 00082 //! Convert to byte, to get ready for injection into a Keypoint 00083 /*! CAUTION: this calls normalize(), then threshold(0.2f), then 00084 normalize() again (all of which modify the FeatureVector), then 00085 converts all values multiplied by 512 to byte with clamping. Call 00086 this only when you are ready to discard the FeatureVector and only 00087 keep the final SIFT Keypoint byte data. */ 00088 void toByteKey(std::vector<byte>& dest, float thresh=0.2, bool norm=true); 00089 00090 int size(){ return itsFV.size(); } 00091 00092 //! Return the x Bin Size 00093 inline int getXSize(){ return itsXSize; } 00094 00095 //! Return the y Bin Size 00096 inline int getYSize(){ return itsYSize; } 00097 00098 //! Return the z Bin Size 00099 inline int getZSize(){ return itsZSize; } 00100 00101 //! Get the feature vector image 00102 Image<PixRGB<byte> > getFeatureVectorImage(std::vector<byte> &fv); 00103 00104 //! Get the magnitude of the feature vector 00105 double getMag(); 00106 00107 //! Get the raw feature vector 00108 std::vector<float> getFeatureVector() const { return itsFV; } 00109 00110 00111 private: 00112 std::vector<float> itsFV; // vector of features 00113 int itsXSize; // size of X bin; 00114 int itsYSize; // size of Y bin; 00115 int itsZSize; // size of Z bin; 00116 bool itsWrapZ; // do we wrap the Z bins 00117 00118 }; 00119 00120 00121 // ###################################################################### 00122 // Inlined member functions 00123 // ###################################################################### 00124 00125 00126 00127 #endif 00128 00129 // ###################################################################### 00130 /* So things look consistent in everyone's emacs... */ 00131 /* Local Variables: */ 00132 /* indent-tabs-mode: nil */ 00133 /* End: */