test-SOFM.C

Go to the documentation of this file.
00001 /*!@file Learn/test-SOFM.C test the SOFM
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: Lior Elazary <elazary@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Learn/test-SOFM.C $
00036 // $Id: test-SOFM.C 12627 2010-01-22 02:00:51Z lior $
00037 //
00038 
00039 #include "Component/ModelManager.H"
00040 #include "Image/Image.H"
00041 #include "Image/Pixels.H"
00042 #include "Image/ColorOps.H"
00043 #include "Image/ShapeOps.H"
00044 #include "Image/MathOps.H"
00045 #include "Image/CutPaste.H"
00046 #include "Image/DrawOps.H"
00047 #include "Image/Transforms.H"
00048 #include "Media/FrameSeries.H"
00049 #include "Raster/Raster.H"
00050 #include "Util/log.H"
00051 #include "Util/MathFunctions.H"
00052 #include "Learn/SOFM.H"
00053 #include "GUI/DebugWin.H"
00054 
00055 
00056 int main(int argc, char** argv)
00057 {
00058 
00059   MYLOGVERB = LOG_INFO;  // suppress debug messages
00060 
00061   // Instantiate a ModelManager:
00062   ModelManager manager("Test SOFM");
00063 
00064   nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00065   manager.addSubComponent(ofs);
00066 
00067   // Parse command-line:
00068   if (manager.parseCommandLine((const int)argc, (const char**)argv, "", 0, 0) == false)
00069     return(1);
00070 
00071   SOFM sofm("sofm.net", 3, 256, 256);
00072   sofm.RandomWeights();
00073 //  sofm.ZeroWeights();
00074 
00075   // main loop:
00076   int ii=0;
00077   while(1) {
00078 
00079     //generate a random rgb value
00080     std::vector<double> input(3);
00081     input[0] = randomUpToIncluding(255);
00082     input[1] = randomUpToIncluding(255);
00083     input[2] = randomUpToIncluding(255);
00084 
00085     LINFO("Input is (%f,%f,%f)", input[0], input[1], input[2]);
00086 
00087     Image<PixRGB<byte> > inputImg(32,32,ZEROS);
00088     inputImg.clear(PixRGB<byte>(input[0], input[1], input[2]));
00089     ofs->writeRGB(inputImg, "InputImg");
00090 
00091     sofm.setInput(input);
00092     sofm.Propagate();
00093 
00094     double val;
00095     Point2D<int> p = sofm.getWinner(val);
00096 
00097     LINFO("Winner at %ix%i value %f", p.i, p.j, val);
00098     printf("%i %f\n",ii, val);
00099     fflush(stdout);
00100 
00101 
00102     Image<float> sofmOut = sofm.getMap();
00103 
00104     drawCircle(sofmOut, p, 6, 255.0F);
00105 
00106     ofs->writeRGB(sofmOut, "SOFM_act_map");
00107 
00108     Image<PixRGB<byte> > weights = sofm.getWeightsImage();
00109 
00110     drawCircle(weights, p, 6, PixRGB<byte>(0,255,0));
00111 
00112     ofs->writeRGB(weights, "SOFM_weights");
00113 
00114 
00115     sofm.SetLearningRate(ii);
00116     sofm.organize(input);
00117     //inplaceNormalize(SMap, 0.0F, 255.0F);
00118 
00119     ii++;
00120 
00121   }
00122 
00123   // stop all our ModelComponents
00124   manager.stop();
00125 
00126   // all done!
00127   return 0;
00128 }
00129 
00130 // ######################################################################
00131 /* So things look consistent in everyone's emacs... */
00132 /* Local Variables: */
00133 /* indent-tabs-mode: nil */
00134 /* End: */
Generated on Sun May 8 08:05:19 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3