00001 /*!@file AppMedia/enhanceImageGamma.C program to enhance salience of image at given locations */ 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/AppMedia/enhanceImageGamma.C $ 00035 // $Id: enhanceImageGamma.C 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 #ifndef APPMEDIA_ENHANCEIMAGEGAMMA_C_DEFINED 00039 #define APPMEDIA_ENHANCEIMAGEGAMMA_C_DEFINED 00040 00041 #include "Component/ModelManager.H" 00042 #include "GUI/XWinManaged.H" 00043 #include "Image/Image.H" 00044 #include "Image/Pixels.H" 00045 #include "Image/ShapeOps.H" // for rescale() 00046 #include "Image/FilterOps.H" //for correlation(); 00047 #include "Image/CutPaste.H" 00048 #include "Image/DrawOps.H" 00049 #include "Image/MathOps.H" 00050 #include "Image/ColorOps.H" 00051 #include "Neuro/getSaliency.H" 00052 #include "Raster/Raster.H" 00053 #include "Util/log.H" 00054 #include "Psycho/EyeTrace.H" 00055 #include "Image/MathOps.H" 00056 #include "Util/StringConversions.H" 00057 #include <fstream> 00058 #include <iostream> 00059 #include <stdio.h> 00060 #include <stdlib.h> 00061 00062 00063 //this code will take as input an image file and increase the salience of a region of an image by using the toPow function (gamma) 00064 00065 00066 int main(int argc, char** argv) 00067 { 00068 ModelManager manager("Enhance gamma on image"); 00069 00070 nub::ref<GetSaliency> saliency(new GetSaliency(manager)); 00071 manager.addSubComponent(saliency); 00072 if (manager.parseCommandLine(argc, argv, "<imagefile> <specDirectory> <outputfile> gamma", 4, 4) == false) 00073 return -1; 00074 00075 00076 manager.start(); 00077 00078 Dims dims(1000,1000); 00079 double gam = atof(manager.getExtraArg(3).c_str()); 00080 00081 00082 Image<PixRGB<float> > inputImg(1920,1080,NO_INIT); 00083 inputImg = Raster::ReadRGB(manager.getExtraArg(0).c_str()); 00084 00085 Image<float> r, g, b; 00086 getComponents(inputImg, r, g, b); 00087 00088 Image<float> r2 = toPower(r, gam); 00089 Image<float> g2 = toPower(g, gam); 00090 Image<float> b2 = toPower(b, gam); 00091 00092 inplaceNormalize(r2, 0.0f, 255.0f); 00093 inplaceNormalize(g2, 0.0f, 255.0f); 00094 inplaceNormalize(b2, 0.0f, 255.0f); 00095 00096 00097 Image<PixRGB<byte> > dispImg(640,360,NO_INIT); 00098 Image<PixRGB<byte> > enhancedImg(1920,1080,NO_INIT); 00099 00100 enhancedImg = makeRGB(Image<byte>(r2), Image<byte>(g2), 00101 Image<byte>(b2)); 00102 00103 00104 dispImg = rescale(enhancedImg,dispImg.getDims()); 00105 00106 const int numSalientSpotsTr = saliency->compute(enhancedImg, SimTime::SECS(1)); 00107 00108 std::string temp ="found" + convertToString(numSalientSpotsTr) + " salient spots"; 00109 00110 const Image<float> salmap = saliency->getSalmap(); 00111 writeText(dispImg,Point2D<int>(5,5),temp.c_str()); 00112 00113 XWinManaged *imgWin,*modImg; 00114 CloseButtonListener wList; 00115 modImg =new XWinManaged(Dims(1920,1080),0,0, manager.getExtraArg(0).c_str()); 00116 imgWin = new XWinManaged(dims,0,0, manager.getExtraArg(0).c_str()); 00117 wList.add(imgWin); 00118 wList.add(modImg); 00119 00120 00121 imgWin->drawImage(dispImg,0,0); 00122 imgWin->drawImage(rescale(salmap,dispImg.getDims()),0,360); 00123 00124 modImg->drawImage(enhancedImg); 00125 00126 char filename[255]; 00127 sprintf(filename,"/lab/farhan/research/exp1/stimMod/%fgamma.png",gam); 00128 00129 Raster::WriteRGB(enhancedImg,filename); 00130 00131 00132 Raster::waitForKey(); 00133 00134 manager.stop(); 00135 00136 return 0; 00137 } 00138 00139 // ###################################################################### 00140 /* So things look consistent in everyone's emacs... */ 00141 /* Local Variables: */ 00142 /* mode: c++ */ 00143 /* indent-tabs-mode: nil */ 00144 /* End: */ 00145 00146 #endif // APPMEDIA_ENHANCEIMAGEGAMMA_C_DEFINED