MrGabor2.C

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