00001 /*!@file VFAT/covHolder.H holds properaties of objects 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/covHolder.H $ 00036 // $Id: covHolder.H 6003 2005-11-29 17:22:45Z rjpeters $ 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 #ifndef COVHOLDER_H_DEFINED 00050 #define COVHOLDER_H_DEFINED 00051 00052 #include "VFAT/targetInfo.H" 00053 00054 #include <fstream> 00055 #include <iostream> 00056 00057 //! A general purpose container for holding guassian signatures 00058 /*! This is a general purpose container for classes from the feature 00059 classifier. Note that there are no pointers and all data is copied 00060 this allows this object to be pulled off from the other code if 00061 need be which makes it portable to other machines or memory spaces 00062 so long as the object type is known. 00063 00064 NOTE: To see how means and averages are computed along with how each 00065 sample is matched temporally, see the file covEstimate.C and the 00066 method covEstimate<T>::matchPmeanAccum(...) . This method does a 00067 nearest neighbor matching and computes temporal dynamics for each 00068 class. 00069 */ 00070 template <class FLOAT> class covHolder : public vfatTargetInfo<FLOAT> 00071 { 00072 public: 00073 inline covHolder(); 00074 inline ~covHolder(); 00075 //! resize this container to diminsions x samples 00076 inline void resize(unsigned long _dim, unsigned long _samples, 00077 FLOAT initVal); 00078 //! dump this objects values to a file 00079 inline void dumpMeToFile(std::string myname, std::string frame, bool init); 00080 //! was this object matched to another object? 00081 bool isMatched; 00082 //! Does this object have enough samples 00083 bool isLarge; 00084 //! number of samples in the set (Population in essence) 00085 unsigned long samples; 00086 //! sorted unique base ID of this file (by size) 00087 unsigned long sortID; 00088 //! unique matched ID of this object 00089 unsigned long matchID; 00090 //! angle of intersecting line from 0,0 to x,y in cov_meanRatio 00091 std::vector<std::vector<FLOAT> > meanTheta; 00092 //! mean ratio of x to y for any data point 00093 std::vector<std::vector<FLOAT> > meanRatio; 00094 }; 00095 00096 // ###################################################################### 00097 template <class FLOAT> 00098 inline covHolder<FLOAT>::covHolder() : vfatTargetInfo<FLOAT>() 00099 {} 00100 00101 // ###################################################################### 00102 template <class FLOAT> 00103 inline covHolder<FLOAT>::~covHolder() 00104 {} 00105 00106 // ###################################################################### 00107 template <class FLOAT> 00108 inline void covHolder<FLOAT>::resize(unsigned long _dim, 00109 unsigned long _samples, 00110 FLOAT initVal) 00111 { 00112 std::cerr << "COVHOLDER RESET\n"; 00113 samples = _samples; 00114 vfatTargetInfo<FLOAT>::dim = _dim; 00115 std::string foo = "foo"; 00116 std::vector<FLOAT> tempTD(vfatTargetInfo<FLOAT>::dim,initVal); 00117 meanRatio.resize(vfatTargetInfo<FLOAT>::dim,tempTD); 00118 meanTheta.resize(vfatTargetInfo<FLOAT>::dim,tempTD); 00119 vfatTargetInfo<FLOAT>::featureName.resize(vfatTargetInfo<FLOAT>::dim,foo); 00120 vfatTargetInfo<FLOAT>::resize(_dim); 00121 } 00122 // ###################################################################### 00123 template <class FLOAT> 00124 inline void covHolder<FLOAT>::dumpMeToFile(std::string myname, 00125 std::string frame, 00126 bool init) 00127 { 00128 std::string newFile; 00129 std::string newFile2; 00130 newFile = myname + ".out.covHolder.S.Sig"; 00131 newFile2 = myname + ".out.covHolder.F.Sig"; 00132 LINFO("DUMPING COVMATRIX TO %s",newFile.c_str()); 00133 00134 if(init) 00135 { 00136 std::ofstream outfile(newFile.c_str(),std::ios::out); 00137 outfile << "**************************************************\n"; 00138 outfile << "Note: color values are normalized between 0 and 1\n"; 00139 outfile << "FRAME" 00140 << "\tBaseID" << "\tSortID" 00141 << "\tMatchID" << "\tSamples" 00142 << "\tDiminsions" << "\tLifeSpan" 00143 << "\tPositionX" << "\tPositionY" 00144 << "\tMinX" << "\tMaxX" 00145 << "\tMinY" << "\tMaxY\n"; 00146 outfile.close(); 00147 } 00148 00149 std::ofstream outfile(newFile.c_str(),std::ios::app); 00150 outfile << frame 00151 << "\t" << vfatTargetInfo<FLOAT>::baseID 00152 << "\t" << sortID 00153 << "\t" << matchID << "\t" << samples 00154 << "\t" << vfatTargetInfo<FLOAT>::dim 00155 << "\t" << vfatTargetInfo<FLOAT>::lifeSpan 00156 << "\t" << vfatTargetInfo<FLOAT>::posX 00157 << "\t" << vfatTargetInfo<FLOAT>::posY 00158 << "\t" << vfatTargetInfo<FLOAT>::minX 00159 << "\t" << vfatTargetInfo<FLOAT>::maxX 00160 << "\t" << vfatTargetInfo<FLOAT>::minY 00161 << "\t" << vfatTargetInfo<FLOAT>::maxY << "\n"; 00162 outfile.close(); 00163 00164 if(init) 00165 { 00166 std::ofstream outfile2(newFile2.c_str(),std::ios::out); 00167 outfile << "Note: feature value = bias*(norm*(value + trans))\n"; 00168 outfile << "Also: Spatial norm = 1/image size\n\n"; 00169 00170 outfile2 << "FRAME\t" << "BaseID\t" << "MatchID"; 00171 for(unsigned long x = 0; x < vfatTargetInfo<FLOAT>::dim; x++) 00172 { 00173 outfile2 << "\tFEATURE" 00174 << "\tMean" 00175 << "\tStandardDev" 00176 << "\tMinValue" 00177 << "\tMaxValue" 00178 << "\tEigenVal" 00179 << "\tSpeed" << "\tSpeedAvg" 00180 << "\tAccel" << "\tAccelAvg" 00181 << "\tDistance" 00182 << "\tBias" 00183 << "\tNorm" 00184 << "\tTranslate"; 00185 } 00186 outfile2 << "\n"; 00187 outfile2.close(); 00188 } 00189 00190 std::ofstream outfile2(newFile2.c_str(),std::ios::app); 00191 outfile2 << frame << "\t" << vfatTargetInfo<FLOAT>::baseID << "\t" 00192 << matchID; 00193 for(unsigned long x = 0; x < vfatTargetInfo<FLOAT>::dim; x++) 00194 { 00195 outfile2 << "\t" << vfatTargetInfo<FLOAT>::featureName[x] 00196 << "\t" << vfatTargetInfo<FLOAT>::mean[x] 00197 << "\t" << vfatTargetInfo<FLOAT>::STD[x] 00198 << "\t" << vfatTargetInfo<FLOAT>::min[x] 00199 << "\t" << vfatTargetInfo<FLOAT>::max[x] 00200 << "\t" << vfatTargetInfo<FLOAT>::eigenVal[x] 00201 << "\t" << vfatTargetInfo<FLOAT>::speed[x] 00202 << "\t" << vfatTargetInfo<FLOAT>::avgspeed[x] 00203 << "\t" << vfatTargetInfo<FLOAT>::accel[x] 00204 << "\t" << vfatTargetInfo<FLOAT>::avgaccel[x] 00205 << "\t" << vfatTargetInfo<FLOAT>::distance[x] 00206 << "\t" << vfatTargetInfo<FLOAT>::bias[x] 00207 << "\t" << vfatTargetInfo<FLOAT>::norm[x] 00208 << "\t" << vfatTargetInfo<FLOAT>::trans[x]; 00209 } 00210 outfile2 << "\n"; 00211 outfile2.close(); 00212 00213 /* 00214 outfile << "MeanTheta Matrix\n"; 00215 for(unsigned long x = 0; x < dim; x++) 00216 { 00217 for(unsigned long y = 0; y < dim; y++) 00218 { 00219 outfile << meanTheta[x][y] << " "; 00220 } 00221 outfile << "\n"; 00222 } 00223 outfile << "MeanRatio Matrix\n"; 00224 for(unsigned long x = 0; x < dim; x++) 00225 { 00226 for(unsigned long y = 0; y < dim; y++) 00227 { 00228 outfile << meanRatio[x][y] << " "; 00229 } 00230 outfile << "\n"; 00231 } 00232 */ 00233 outfile.close(); 00234 LINFO("DONE"); 00235 } 00236 00237 #endif