00001 /*!@file Surprise/runRemoveSurprise.C attempt to remove surprise from image */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // 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: T. Nathan Mundhenk <mundhenk@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Surprise/runRemoveSurprise.C $ 00035 // $Id: runRemoveSurprise.C 14376 2011-01-11 02:44:34Z pez $ 00036 // 00037 00038 #ifndef RUN_REMOVE_SURPRISE_C_DEFINED 00039 #define RUN_REMOVE_SURPRISE_C_DEFINED 00040 00041 #include "Surprise/ScaleRemoveSurprise.H" 00042 #include "GUI/XWindow.H" 00043 #include "Raster/Raster.H" 00044 #include "Image/Normalize.H" 00045 00046 #define USE_SCALES true 00047 00048 using std::string; 00049 00050 int main(const int argc, const char **argv) 00051 { 00052 if(argc < 2) 00053 LFATAL("Usage: runRemoveSurprise frames rawImagePrefix"); 00054 00055 uint frames = atoi(argv[1]); 00056 string rawImagePrefix = argv[2]; 00057 string confName; 00058 if(argc >= 2) 00059 { 00060 confName = argv[3]; 00061 } 00062 else 00063 { 00064 confName = "null"; 00065 } 00066 00067 Image<float> salmap; 00068 Image<float> COmap; 00069 Image<float> MOmap; 00070 Image<float> ORmap; 00071 Image<float> INmap; 00072 Image<byte> tbyte; 00073 00074 Image<PixRGB<float> > rawImage; 00075 Image<PixRGB<float> > outImage; 00076 Image<PixRGB<float> > diffImage; 00077 Image<PixRGB<byte> > tpbyte; 00078 00079 string start = "000000.png"; 00080 string raw = rawImagePrefix + start; 00081 00082 tpbyte = Raster::ReadRGB(raw); 00083 00084 00085 if(!USE_SCALES) 00086 { 00087 RemoveSurprise<PixH2SV1<float>,PixHyper<float,4>,float> 00088 rs(tpbyte.getWidth(),tpbyte.getHeight()); 00089 rs.RSsetAxisBias(0.5F,0.5F,1.0F); 00090 rs.RScreateSepFilters(3,3,4.0); 00091 rs.RSfindConvolutionEndPoints(); 00092 rs.RSsetConspicBias(1.5F, 1.5F, 1.5F, 0.0F); 00093 rs.RSuseTrueKalman(false); 00094 rs.RSsetLambda(0.80F); 00095 // set INmap to all 1's if we do not have it 00096 00097 INmap.resize(tpbyte.getWidth(),tpbyte.getHeight()); 00098 for(int i = 0; i < INmap.getWidth(); i++) 00099 { 00100 for(int j = 0; j < INmap.getHeight(); j++) 00101 { 00102 INmap.setVal(i,j,1.0F); 00103 } 00104 } 00105 LINFO("RUNNING FRAMES"); 00106 for(uint i = 0; i < frames; i++) 00107 { 00108 char c[100]; 00109 string a, Myname; 00110 string b = ".png"; 00111 string p = "."; 00112 const uint frameNumber = i; 00113 00114 00115 if(frameNumber < 10) 00116 sprintf(c,"00000%d",frameNumber); 00117 else if(frameNumber < 100) 00118 sprintf(c,"0000%d",frameNumber); 00119 else if(frameNumber < 1000) 00120 sprintf(c,"000%d",frameNumber); 00121 else if(frameNumber < 10000) 00122 sprintf(c,"00%d",frameNumber); 00123 else if(frameNumber < 100000) 00124 sprintf(c,"0%d",frameNumber); 00125 else 00126 sprintf(c,"%d",frameNumber); 00127 00128 // read raw image 00129 raw = rawImagePrefix + c + b; 00130 tpbyte = Raster::ReadRGB(raw); 00131 rawImage = tpbyte; 00132 rs.RSinputRawImage(rawImage,i); 00133 00134 // read salmap 00135 string d = ".pnm"; 00136 b = "#.ppm-SM"; 00137 raw = rawImagePrefix + b + c + d; 00138 tbyte = Raster::ReadGray(raw); 00139 salmap = tbyte; 00140 rs.RSinputSalMap(salmap); 00141 00142 // read CO consp map 00143 b = "#.ppm-COcolor-"; 00144 raw = rawImagePrefix + b + c + d; 00145 tbyte = Raster::ReadGray(raw); 00146 COmap = tbyte; 00147 rs.RSinputConspicCO(COmap); 00148 00149 // read MO consp map 00150 b = "#.ppm-COmotion-"; 00151 raw = rawImagePrefix + b + c + d; 00152 tbyte = Raster::ReadGray(raw); 00153 MOmap = tbyte; 00154 rs.RSinputConspicMO(MOmap); 00155 00156 // read OR consp map 00157 b = "#.ppm-COorientation-"; 00158 raw = rawImagePrefix + b + c + d; 00159 tbyte = Raster::ReadGray(raw); 00160 ORmap = tbyte; 00161 rs.RSinputConspicOR(ORmap); 00162 00163 rs.RSinputConspicIN(INmap); 00164 00165 // process this frame 00166 rs.RSprocessFrameSeperable(); 00167 00168 // get processed frame 00169 outImage = rs.RSgetFrame(); 00170 tpbyte = outImage; 00171 b = ".ReduceSup2."; 00172 raw = rawImagePrefix + b + c + d; 00173 Raster::WriteRGB(tpbyte,raw); 00174 } 00175 } 00176 else 00177 { 00178 ScaleRemoveSurprise<float> 00179 srs(tpbyte.getWidth(),tpbyte.getHeight(),confName); 00180 00181 // input set of weights from an image (or set?) as anit removal 00182 //srs.SRSsetAntiWeights(); 00183 //srs.SRSsetAntiWeightsInteract(10,10); 00184 string bb = "#.png"; 00185 string basepre = "org."; 00186 string antipre = "plane."; 00187 string antiFileSetName = antipre + bb; 00188 string baseFileSetName = basepre + bb; 00189 string fileSetName = rawImagePrefix + bb; 00190 //srs.SRScomputeBayesFeatureBias(10,baseFileSetName, antiFileSetName); 00191 //srs.SRSopenBayesFeatureBias(baseFileSetName, antiFileSetName); 00192 diffImage.resize(tpbyte.getWidth(),tpbyte.getHeight()); 00193 LINFO("RUNNING FRAMES"); 00194 for(uint i = 0; i < frames; i++) 00195 { 00196 char c[100]; 00197 string a, Myname; 00198 string b = ".png"; 00199 string p = "."; 00200 const uint frameNumber = i; 00201 00202 if(frameNumber < 10) 00203 sprintf(c,"00000%d",frameNumber); 00204 else if(frameNumber < 100) 00205 sprintf(c,"0000%d",frameNumber); 00206 else if(frameNumber < 1000) 00207 sprintf(c,"000%d",frameNumber); 00208 else if(frameNumber < 10000) 00209 sprintf(c,"00%d",frameNumber); 00210 else if(frameNumber < 100000) 00211 sprintf(c,"0%d",frameNumber); 00212 else 00213 sprintf(c,"%d",frameNumber); 00214 00215 // read raw image 00216 raw = rawImagePrefix + c + b; 00217 tpbyte = Raster::ReadRGB(raw); 00218 rawImage = tpbyte; 00219 srs.SRSinputRawImage(rawImage,i); 00220 00221 // find bayesian maps for current image 00222 //srs.SRScomputeBayesFeatureCurrent(i,fileSetName); 00223 00224 // read salmap 00225 string d = ".pnm"; 00226 b = "#.png-SM"; 00227 raw = rawImagePrefix + b + c + d; 00228 tbyte = Raster::ReadGray(raw); 00229 salmap = tbyte; 00230 srs.SRSinputSalMap(salmap); 00231 00232 00233 // process this frame 00234 srs.SRSprocessFrame(); 00235 00236 d = ".png"; 00237 00238 // get processed frame 00239 outImage = srs.SRSgetFrame(); 00240 tpbyte = outImage; 00241 b = ".ReduceSupScale."; 00242 raw = rawImagePrefix + b + c + d; 00243 Raster::WriteRGB(tpbyte,raw); 00244 00245 diffImage = srs.SRSgetDiffImage(); 00246 tpbyte = diffImage; 00247 b = ".ReduceSupScale.diff."; 00248 raw = rawImagePrefix + b + c + d; 00249 Raster::WriteRGB(tpbyte,raw); 00250 /* 00251 std::vector<Image<PixRGB<float> > > diffParts = srs.SRSgetDiffParts(); 00252 b = ".ReduceSupScale.diffParts."; 00253 for(uint i = 2; i < diffParts.size(); i++) 00254 { 00255 char part[100]; 00256 sprintf(part,"%d",i); 00257 string spart = part; 00258 raw = rawImagePrefix + b + c + p + spart + d; 00259 Image<PixRGB<byte> > bimage = diffParts[i]; 00260 Raster::WriteRGB(bimage,raw); 00261 } 00262 00263 std::vector<Image<float> > betaParts = srs.SRSgetBetaParts(); 00264 b = ".ReduceSupScale.betaParts."; 00265 for(uint i = 0; i < betaParts.size(); i++) 00266 { 00267 char part[100]; 00268 sprintf(part,"%d",i); 00269 string spart = part; 00270 raw = rawImagePrefix + b + c + p + spart + d; 00271 betaParts[i] = normalizeFloat(betaParts[i],FLOAT_NORM_0_255); 00272 Image<byte> bimage = betaParts[i]; 00273 Raster::WriteGray(bimage,raw); 00274 } 00275 */ 00276 } 00277 } 00278 return 0; 00279 } 00280 00281 #endif