00001 /*!@file AppNeuro/featureVectorDistance.C program computes the distance between the 42 dimension feature vectors for two images */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the 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: Farhan Baluch <fbaluch at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppNeuro/featureVectorDistance.C $ 00035 // $Id: featureVectorDistance.C 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 #ifndef APPNEURO_FEATUREVECTORDISTANCE_C_DEFINED 00039 #define APPNEURO_FEATUREVECTORDISTANCE_C_DEFINED 00040 00041 #include "Component/ModelManager.H" 00042 #include "Image/Image.H" 00043 #include "Image/Pixels.H" 00044 #include "Image/ShapeOps.H" // for rescale() 00045 #include "Image/FilterOps.H" //for correlation(); 00046 #include "Image/CutPaste.H" 00047 #include "Neuro/getSaliency.H" 00048 #include "Raster/Raster.H" 00049 #include "Util/log.H" 00050 #include "Psycho/EyeTrace.H" 00051 #include "Image/MathOps.H" 00052 #include "Util/StringConversions.H" 00053 #include <fstream> 00054 #include <iostream> 00055 #include <stdio.h> 00056 #include <stdlib.h> 00057 //this code will take as input an image file and an eye file and computes NSS for all submaps generated by the model for the image. 00058 00059 00060 int main(int argc, char** argv) 00061 { 00062 ModelManager manager("test"); 00063 00064 nub::ref<GetSaliency> saliency(new GetSaliency(manager)); 00065 manager.addSubComponent(saliency); 00066 if (manager.parseCommandLine(argc, argv, "<imageDirectory> <specDirectory> <outputDirectory>", 3, 3) == false) 00067 return -1; 00068 manager.start(); 00069 00070 std::string trgtImgFile, arrayImgFile, specFile, outTrgFile, 00071 outArrFile,outNameFile, corFile; 00072 size_t numSubMap; 00073 std::ofstream outputFile; 00074 00075 00076 outNameFile = manager.getExtraArg(2) + "mapNames.dat"; 00077 outputFile.open(outNameFile.c_str()); 00078 00079 for(int i=1;i<=5;i++) 00080 { 00081 trgtImgFile = manager.getExtraArg(0) + convertToString(i) + "TARGET.png"; 00082 arrayImgFile = manager.getExtraArg(0) + convertToString(i) + "ARRAY.png"; 00083 specFile = manager.getExtraArg(1) + convertToString(i) + "SPEC.datm"; 00084 00085 LINFO("computing maps for %s",arrayImgFile.c_str()); 00086 00087 const Image<PixRGB<byte> > trgtImg = Raster::ReadRGB(trgtImgFile); 00088 const Image<PixRGB<byte> > arrayImg = Raster::ReadRGB(arrayImgFile); 00089 00090 const int numSalientSpotsTr = saliency->compute(trgtImg, SimTime::SECS(0.1)); 00091 LINFO("found %d salient spots", numSalientSpotsTr); 00092 const Image<float> salmap = saliency->getSalmap(); 00093 const Image<float> resized_salmap = rescale(salmap, trgtImg.getDims()); 00094 const std::vector<subMap> itsTrgtSubMaps = saliency->getSubMaps(); 00095 00096 const int numSalientSpotsArray = saliency->compute(arrayImg,SimTime::SECS(0.1)); 00097 LINFO("found %d salient spots", numSalientSpotsArray); 00098 const std::vector<subMap> itsArraySubMaps = saliency->getSubMaps(); 00099 00100 numSubMap = itsTrgtSubMaps.size(); 00101 00102 //lets save the target and array submaps in a directory 00103 for (size_t j=0;j<numSubMap;j++) 00104 { 00105 outTrgFile = manager.getExtraArg(2) + convertToString(i) + "TRGsub" 00106 + convertToString(j) + ".png"; 00107 LINFO("writing to file %s",outTrgFile.c_str()); 00108 Raster::WriteFloat(itsTrgtSubMaps[j].itsSubMap,FLOAT_NORM_0_255,outTrgFile); 00109 00110 outArrFile = manager.getExtraArg(2) + convertToString(i) + "ARRsub" 00111 + convertToString(j) + ".png"; 00112 LINFO("writing to file %s",outArrFile.c_str()); 00113 Raster::WriteFloat(itsArraySubMaps[j].itsSubMap,FLOAT_NORM_0_255,outArrFile); 00114 outputFile << itsArraySubMaps[j].itsSubMapName <<"\n"; 00115 00116 corFile = manager.getExtraArg(2) + convertToString(i) + "CorSub" 00117 + convertToString(j) + ".png"; 00118 00119 Image<float> temp = crop(itsArraySubMaps[j].itsSubMap,Point2D<int> (58,31),Dims(15,15)); 00120 Raster::WriteFloat(correlation(itsArraySubMaps[j].itsSubMap,temp), FLOAT_NORM_0_255, corFile); 00121 00122 } 00123 00124 } 00125 00126 outputFile.close(); 00127 manager.stop(); 00128 00129 return 0; 00130 } 00131 00132 // ###################################################################### 00133 /* So things look consistent in everyone's emacs... */ 00134 /* Local Variables: */ 00135 /* mode: c++ */ 00136 /* indent-tabs-mode: nil */ 00137 /* End: */ 00138 00139 #endif // APPNEURO_FEATUREVECTORDISTANCE_C_DEFINED