00001 /*!@file CINNIC/MrGabor.C A Gabor */ 00002 00003 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CINNIC/MrGabor.C $ 00004 // $Id: MrGabor.C 9412 2008-03-10 23:10:15Z farhan $ 00005 00006 // ############################################################ 00007 // ############################################################ 00008 // ##### ---CINNIC--- 00009 // ##### Contour Integration: 00010 // ##### T. Nathan Mundhenk nathan@mundhenk.com 00011 // ############################################################ 00012 // ############################################################ 00013 00014 #include "CINNIC/gaborElement.H" 00015 #include "Image/ColorOps.H" 00016 #include "Image/CutPaste.H" // for inplacePaste() 00017 #include "Image/Image.H" 00018 #include "Image/Kernels.H" // for gaborFilter2() 00019 #include "Image/Transforms.H" 00020 #include "Raster/Raster.H" 00021 #include "Util/log.H" 00022 #include "Util/readConfig.H" 00023 00024 #include <stdio.h> 00025 #include <stdlib.h> 00026 #include <sys/types.h> 00027 #include <time.h> 00028 00029 00030 //! This is the configFile name 00031 const char* configFile; 00032 //! This is the gaborElement file 00033 const char* gaborElementFile; 00034 //! what to save the image as (name) 00035 const char* imageSaveName; 00036 //! This is the configFile object 00037 readConfig configIn(25); 00038 //! This is the gaborElement object 00039 readConfig gaborIn(25); 00040 //! keep track of gabor properties 00041 std::vector<gaborElement> theGabors; 00042 //! store the gabors 00043 std::vector<Image<float> > theGaborImages; 00044 //! the master images 00045 std::vector<Image<float> > theMasterImages; 00046 //! variables 00047 int gaborNumber, sizeX, sizeY; 00048 float backGround; 00049 char getX[100]; 00050 char getY[100]; 00051 char getSTDDEV[100]; 00052 char getPERIOD[100]; 00053 char getPHASE[100]; 00054 char getTHETA[100]; 00055 char getSIGMOD[100]; 00056 char getAMPLITUDE[100]; 00057 char getMASTER[100]; 00058 00059 int main(int argc, char* argv[]) 00060 { 00061 Image<float> finalImage; 00062 Image<float> masterImage; 00063 Image<byte> convert; 00064 time_t t1,t2; 00065 (void) time(&t1); 00066 configFile = "gabor.conf"; 00067 gaborElementFile = argv[1]; 00068 configIn.openFile(configFile); 00069 gaborIn.openFile(gaborElementFile); 00070 gaborNumber = (int)gaborIn.getItemValueF("gaborNumber"); 00071 LINFO("Number of Gabor Elements in Image %d",gaborNumber); 00072 backGround = gaborIn.getItemValueF("backGround"); 00073 LINFO("backGround color in Image %f",backGround); 00074 imageSaveName = gaborIn.getItemValueC("imageSaveName"); 00075 LINFO("Will save as file %s",imageSaveName); 00076 sizeX = (int)gaborIn.getItemValueF("sizeX"); 00077 sizeY = (int)gaborIn.getItemValueF("sizeY"); 00078 LINFO("IMAGE size %dx%d",sizeX,sizeY); 00079 finalImage.resize(sizeX,sizeY); 00080 masterImage.resize(sizeX,sizeY); 00081 for(int x = 0; x < finalImage.getWidth(); x++) 00082 { 00083 for(int y = 0; y < finalImage.getHeight(); y++) 00084 { 00085 finalImage.setVal(x,y,backGround); 00086 } 00087 } 00088 gaborElement geTemp; 00089 theGabors.resize(gaborNumber); 00090 Image<float> giTemp; 00091 giTemp.resize(1,1); 00092 theGaborImages.resize(gaborNumber,giTemp); 00093 theMasterImages.resize(gaborNumber,giTemp); 00094 //go ahead and store gabors just incase we need them later 00095 LINFO("PLACING gabors..."); 00096 for(int i = 0; i < gaborNumber; i++) 00097 { 00098 sprintf(getX,"x%d",i+1); 00099 theGabors[i].x = (int)gaborIn.getItemValueF(getX); 00100 sprintf(getY,"y%d",i+1); 00101 theGabors[i].y = (int)gaborIn.getItemValueF(getY); 00102 sprintf(getSTDDEV,"stddev%d",i+1); 00103 theGabors[i].stddev = 00104 gaborIn.getItemValueF(getSTDDEV); 00105 sprintf(getPERIOD,"period%d",i+1); 00106 theGabors[i].period = 00107 gaborIn.getItemValueF(getPERIOD); 00108 sprintf(getPHASE,"phase%d",i+1); 00109 theGabors[i].phase = 00110 gaborIn.getItemValueF(getPHASE); 00111 sprintf(getTHETA,"theta%d",i+1); 00112 theGabors[i].theta = 00113 gaborIn.getItemValueF(getTHETA); 00114 sprintf(getSIGMOD,"sigMod%d",i+1); 00115 theGabors[i].sigMod = 00116 gaborIn.getItemValueF(getSIGMOD); 00117 sprintf(getAMPLITUDE,"amplitude%d",i+1); 00118 theGabors[i].amplitude = 00119 gaborIn.getItemValueF(getAMPLITUDE); 00120 //sprintf(getMASTER,"master%d",i+1); 00121 //theGabors[i].master = 00122 // (int)gaborIn.getItemValueF(getMASTER); 00123 theGabors[i].master = 0; 00124 theGaborImages[i] = gaborFilter2<float>(theGabors[i].stddev, 00125 theGabors[i].period, 00126 theGabors[i].phase, 00127 theGabors[i].theta, 00128 theGabors[i].sigMod, 00129 theGabors[i].amplitude); 00130 int xx = theGabors[i].x - (theGaborImages[i].getWidth()/2); 00131 int yy = theGabors[i].y - (theGaborImages[i].getHeight()/2); 00132 if(theGabors[i].master == 1) 00133 { 00134 theMasterImages[i] = gaussian2D<float>(theGabors[i].stddev, 00135 2.0F); 00136 //Raster::VisuFloat(theMasterImages[i], 0, "MASTER.pgm"); 00137 inplacePaste(masterImage, theMasterImages[i],Point2D<int>(xx,yy)); 00138 } 00139 inplacePasteGabor(finalImage, theGaborImages[i], 00140 Point2D<int>(xx,yy),backGround); 00141 } 00142 //Raster::VisuFloat(finalImage, 0, imageSaveName, RASFMT_PNM); 00143 convert = finalImage; 00144 Raster::WriteGray(convert,sformat("%s.pgm", imageSaveName)); 00145 //Raster::VisuFloat(masterImage, 0, sformat("%s.master.pgm",imageSaveName)); 00146 convert = masterImage; 00147 Raster::WriteGray(convert,sformat("%s.master.pgm",imageSaveName)); 00148 (void) time(&t2); 00149 long int tl = (long int) t2-t1; 00150 printf("\n*************************************\n"); 00151 printf("Time to execute, %ld seconds\n",tl); 00152 printf("*************************************\n\n"); 00153 00154 return 1; 00155 } 00156 00157 // ###################################################################### 00158 /* So things look consistent in everyone's emacs... */ 00159 /* Local Variables: */ 00160 /* indent-tabs-mode: nil */ 00161 /* End: */