test-SuperPixel.C

Go to the documentation of this file.
00001 /*!@file Gist/test-SuperPixel.C testing SuperPixel segmentation algorithm */
00002 // //////////////////////////////////////////////////////////////////// //
00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00004 // University of Southern California (USC) and the iLab at USC.         //
00005 // See http://iLab.usc.edu for information about this project.          //
00006 // //////////////////////////////////////////////////////////////////// //
00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00009 // in Visual Environments, and Applications'' by Christof Koch and      //
00010 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00011 // pending; application number 09/912,225 filed July 23, 2001; see      //
00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00015 //                                                                      //
00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00017 // redistribute it and/or modify it under the terms of the GNU General  //
00018 // Public License as published by the Free Software Foundation; either  //
00019 // version 2 of the License, or (at your option) any later version.     //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00024 // PURPOSE.  See the GNU General Public License for more details.       //
00025 //                                                                      //
00026 // You should have received a copy of the GNU General Public License    //
00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00029 // Boston, MA 02111-1307 USA.                                           //
00030 // //////////////////////////////////////////////////////////////////// //
00031 //
00032 // Primary maintainer for this file: Christian Siagian <siagian@usc.edu>
00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Gist/test-SuperPixel.C $
00034 // $Id: test-SuperPixel.C 14762 2011-05-03 01:13:16Z siagian $
00035 //
00036 //////////////////////////////////////////////////////////////////////////
00037 //
00038 // Implementation of the segmentation algorithm described in:
00039 //
00040 // Efficient Graph-Based Image Segmentation
00041 // Pedro F. Felzenszwalb and Daniel P. Huttenlocher
00042 // International Journal of Computer Vision, 59(2) September 2004.
00043 // Copyright (C) 2006 Pedro Felzenszwalb
00044 
00045 
00046 #include "Component/ModelManager.H"
00047 #include "Media/FrameSeries.H"
00048 #include "Transport/FrameIstream.H"
00049 
00050 #include "Image/Image.H"
00051 #include "Image/Pixels.H"
00052 #include "Raster/Raster.H"
00053 #include "Image/CutPaste.H"     // for inplacePaste()
00054 #include "Image/LowPass.H"
00055 #include "Image/ShapeOps.H"
00056 
00057 // #include <cstdio>
00058 // #include <cstdlib>
00059 // #include <image.h>
00060 // #include <misc.h>
00061 // #include <pnmfile.h>
00062 
00063 #include "Gist/SuperPixel.H"
00064 
00065 #include "Util/Timer.H"
00066 
00067 int main(int argc, char **argv)
00068 {
00069 
00070   // instantiate a model manager:
00071   ModelManager manager("test SuperPixel");
00072 
00073   // Instantiate our various ModelComponents:
00074 
00075   nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00076   manager.addSubComponent(ifs);
00077 
00078   //nub::ref<GraphBasedSegmenter> sps(new SuperPixelSegmenter(manager));
00079   //manager.addSubComponent(sps);
00080 
00081   nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00082   manager.addSubComponent(ofs);
00083 
00084   manager.exportOptions(MC_RECURSE);
00085 
00086   // Parse command-line:
00087   if (manager.parseCommandLine(argc, argv,
00088                                "[save_output_to_file] "
00089                                "[sigma] [k] [min_size]",
00090                                0, 4)
00091       == false) return(1);
00092 
00093   // get the operation mode
00094   bool saveOutput = false;
00095   std::string outFilename;
00096   if(manager.numExtraArgs() >  0)
00097     {
00098       saveOutput = true;
00099       outFilename = manager.getExtraArg(0);
00100       LINFO("save to: %s", outFilename.c_str());
00101     }
00102 
00103   // default parameters for the Superpixel segmentation
00104   float sigma = .5; uint k = 500; uint minSize = 20;
00105   if(manager.numExtraArgs() > 1)
00106     sigma = manager.getExtraArgAs<float>(1);
00107   if(manager.numExtraArgs() > 2)
00108     k = manager.getExtraArgAs<uint>(2);
00109   if(manager.numExtraArgs() > 3)
00110     minSize = manager.getExtraArgAs<uint>(3);
00111 
00112   // let's do it!
00113   manager.start();
00114 
00115    // bool keepGoing = true; uint index = 0;
00116    // while(keepGoing)
00117    //   {
00118 
00119   Timer timer(1000000); float time;
00120       
00121   ifs->updateNext();
00122   Image<PixRGB<byte> > ima = ifs->readRGB();
00123   if(!ima.initialized()) {}// keepGoing = false; }
00124   else
00125     {
00126       timer.reset();
00127       int num_ccs;
00128       Image<PixRGB<byte> > output =
00129         segment_image(ima, sigma, k, minSize, num_ccs);
00130           
00131       time = timer.get()/1000.0F;
00132       LINFO("time: %f", time);
00133       
00134       Image<PixRGB<byte> >
00135         dispIma(ima.getWidth()*2, ima.getHeight(), NO_INIT);
00136       inplacePaste(dispIma, ima, Point2D<int>(0, 0));
00137       inplacePaste(dispIma, output, Point2D<int>(ima.getWidth(), 0));
00138 //       inplacePaste(dispIma, output2, Point2D<int>(2*ima.getWidth(), 0));
00139       
00140       ofs->writeRGB(dispIma, "SuperPixel Segmentation");
00141       ofs->updateNext();
00142       Raster::waitForKey();
00143       
00144       if(saveOutput)
00145         Raster::WriteRGB(output, outFilename);
00146       
00147     }
00148 //     index++;
00149 //   }
00150 
00151 
00152   return 0;
00153 }
00154 
00155 // ######################################################################
00156 /* So things look consistent in everyone's emacs... */
00157 /* Local Variables: */
00158 /* indent-tabs-mode: nil */
00159 /* End: */
Generated on Sun May 8 08:04:48 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3