00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "Component/ModelManager.H"
00041 #include "Image/Image.H"
00042 #include "Image/ImageSet.H"
00043 #include "Image/ShapeOps.H"
00044 #include "Image/DrawOps.H"
00045 #include "Image/FilterOps.H"
00046 #include "Image/ColorOps.H"
00047 #include "Image/Transforms.H"
00048 #include "Image/MathOps.H"
00049 #include "Neuro/StdBrain.H"
00050 #include "Neuro/VisualCortex.H"
00051 #include "Neuro/NeuroOpts.H"
00052 #include "Neuro/NeuroSimEvents.H"
00053 #include "Neuro/TaskRelevanceMap.H"
00054 #include "Neuro/SaliencyMap.H"
00055 #include "Media/TestImages.H"
00056 #include "Media/SceneGenerator.H"
00057 #include "Media/MediaSimEvents.H"
00058 #include "Channels/DescriptorVec.H"
00059 #include "Channels/ComplexChannel.H"
00060 #include "Simulation/SimEventQueue.H"
00061 #include "Simulation/SimulationOpts.H"
00062 #include "Simulation/SimEventQueueConfigurator.H"
00063 #include "Channels/SubmapAlgorithmBiased.H"
00064 #include "GUI/DebugWin.H"
00065 #include "ObjRec/MaskBiaser.H"
00066
00067
00068
00069 Point2D<int> evolveBrain(Image<PixRGB<byte> > &img, Image<float> &SMap, float *interestLevel,
00070 nub::soft_ref<SimEventQueue> seq);
00071
00072 ModelManager *mgr;
00073 void biasVC(ComplexChannel &vc, Image<float> &mask);
00074 bool debug = 1;
00075 int main(const int argc, const char **argv)
00076 {
00077
00078 MYLOGVERB = LOG_INFO;
00079 mgr = new ModelManager("Test LabelMeSaliency");
00080
00081 nub::soft_ref<SimEventQueueConfigurator>
00082 seqc(new SimEventQueueConfigurator(*mgr));
00083 mgr->addSubComponent(seqc);
00084
00085
00086 nub::ref<StdBrain> brain(new StdBrain(*mgr));
00087 mgr->addSubComponent(brain);
00088
00089
00090 mgr->exportOptions(MC_RECURSE);
00091 mgr->setOptionValString(&OPT_RawVisualCortexChans, "IOC");
00092
00093
00094
00095
00096
00097 mgr->setOptionValString(&OPT_SaliencyMapType, "Fast");
00098 mgr->setOptionValString(&OPT_SMfastInputCoeff, "1");
00099
00100 mgr->setOptionValString(&OPT_WinnerTakeAllType, "Fast");
00101 mgr->setOptionValString(&OPT_SimulationTimeStep, "0.2");
00102
00103 mgr->setModelParamVal("FOAradius", 128, MC_RECURSE);
00104 mgr->setModelParamVal("FoveaRadius", 128, MC_RECURSE);
00105
00106 mgr->setOptionValString(&OPT_IORtype, "Disc");
00107
00108 if (mgr->parseCommandLine(
00109 (const int)argc, (const char**)argv, "<path to images>", 1, 1) == false);
00110
00111 nub::soft_ref<SimEventQueue> seq = seqc->getQ();
00112
00113 mgr->start();
00114
00115
00116
00117
00118 ComplexChannel *cc =
00119 &*dynCastWeak<ComplexChannel>(brain->getVC());
00120
00121 TestImages testImages(mgr->getExtraArg(0).c_str(), TestImages::MIT_LABELME);
00122
00123 Image<float> allObjImg = Raster::ReadFloat("allObjImg.pfm", RASFMT_PFM);
00124 inplaceNormalize(allObjImg, 0.0F, 1.0F);
00125
00126 printf("## \"Filename\", \"Size\",\"fovea Radius\",\"Number of objects\",\"Salient Location\", \"Hits\",");
00127 printf("\"Obj Saliency Max\",\"Obj Saliency Min\",\"Obj Saliency Sum\",\"Obj Saliency Area\"");
00128 printf("\"Dist Saliency Max\",\"Dist Saliency Min\",\"Dist Saliency Sum\",\"Dist Saliency Area\"");
00129 printf("\n");
00130
00131 for(uint scene=0; scene<testImages.getNumScenes(); scene++)
00132 {
00133
00134
00135 LINFO("Get scene %i", scene);
00136 Image<PixRGB<byte> > img = testImages.getScene(scene);
00137 std::string sceneFile = testImages.getSceneFilename(scene);
00138 LINFO("Size %ix%i", img.getWidth(), img.getHeight());
00139
00140
00141
00142 int fRadius = 128;
00143
00144
00145
00146
00147 initRandomNumbers();
00148
00149 if (testImages.getNumObj() > 0)
00150 {
00151
00152
00153 Image<float> mask = rescale(allObjImg, img.getDims());
00154 biasVC(*cc, mask);
00155
00156
00157 Image<float> SMap;
00158
00159 rutz::shared_ptr<SimEventInputFrame>
00160 e(new SimEventInputFrame(brain.get(), GenericFrame(img), 0));
00161 seq->post(e);
00162
00163
00164
00165 Point2D<int> winner;
00166 float interestLevel=100.0F;
00167 int nHits=0;
00168 int nTimes=95;
00169
00170 printf("[ ");
00171 Point2D<int> lastLoc(-1,-1);
00172 while(interestLevel > 0.01F && nTimes < 100)
00173 {
00174 nTimes++;
00175 LINFO("InterestLevel %f", interestLevel);
00176 Point2D<int> currentWinner = evolveBrain(img, SMap, &interestLevel, seq);
00177
00178 if (debug)
00179 {
00180 if (lastLoc.isValid())
00181 {
00182 drawLine(img, lastLoc, currentWinner,
00183 PixRGB<byte>(0, 255, 0), 4);
00184 } else {
00185 drawCircle(img, currentWinner, fRadius-10, PixRGB<byte>(255,0,0), 3);
00186 }
00187 lastLoc = currentWinner;
00188
00189
00190 drawCircle(img, currentWinner, fRadius, PixRGB<byte>(0,255,0), 3);
00191 }
00192
00193
00194 int hit = -1;
00195 for (uint obj=0; obj<testImages.getNumObj(); obj++)
00196 {
00197 int lineWidth = int(img.getWidth()*0.003);
00198 std::vector<Point2D<int> > objPoly = testImages.getObjPolygon(obj);
00199 if (debug)
00200 {
00201 Point2D<int> p1 = objPoly[0];
00202 for(uint i=1; i<objPoly.size(); i++)
00203 {
00204 drawLine(img, p1, objPoly[i], PixRGB<byte>(255, 0, 0), lineWidth);
00205 p1 = objPoly[i];
00206 }
00207 drawLine(img, p1, objPoly[0], PixRGB<byte>(255, 0, 0), lineWidth);
00208 }
00209
00210
00211
00212 if (testImages.pnpoly(objPoly, currentWinner))
00213 {
00214 hit = obj;
00215 }
00216
00217 }
00218 printf("%i ", hit);
00219 if (hit != -1)
00220 {
00221 winner = currentWinner;
00222 nHits++;
00223 }
00224
00225 }
00226
00227 if (debug)
00228 {
00229 Raster::WriteRGB(img, "IORSaliency.ppm");
00230 Image<PixRGB<byte> > tmp = rescale(img, 512, 512);
00231 SHOWIMG(tmp);
00232 }
00233 printf("] ");
00234 printf("\"%s\",\"%ix%i\",\"%i\",\"%i\",\"(%i,%i)\",\"%i\"",
00235 sceneFile.c_str(), img.getWidth(), img.getHeight(), fRadius,
00236 testImages.getNumObj(), winner.i, winner.j, nHits);
00237 printf("\n");
00238
00239 if (debug)
00240 {
00241 Image<PixRGB<byte> > tmp = rescale(img, 512, 512);
00242 SHOWIMG(tmp);
00243
00244 }
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 } else {
00287 printf("##%s has no objects \n", sceneFile.c_str());
00288 }
00289 }
00290
00291 }
00292
00293 Point2D<int> evolveBrain(Image<PixRGB<byte> > &img, Image<float> &SMap, float *interestLevel,
00294 nub::soft_ref<SimEventQueue> seq)
00295 {
00296
00297 nub::ref<StdBrain> brain = dynCastWeak<StdBrain>(mgr->subComponent("Brain"));
00298
00299
00300 *interestLevel = 0.0F;
00301 if (mgr->started() && img.initialized()){
00302
00303
00304 SimTime end_time = seq->now() + SimTime::MSECS(3.0);
00305 while (seq->now() < end_time)
00306 {
00307 brain->evolve(*seq);
00308
00309
00310 if (SeC<SimEventWTAwinner> e = seq->check<SimEventWTAwinner>(brain.get()))
00311 {
00312 const Point2D<int> winner = e->winner().p;
00313 const float winV = e->winner().sv;
00314 *interestLevel = (winV * 1000.0f) * 1;
00315 LINFO("##### Winner (%d,%d) at %fms : %.4f #####\n",
00316 winner.i, winner.j, seq->now().msecs(), winV * 1000.0f);
00317
00318
00319 if (debug)
00320 {
00321 if (SeC<SimEventSaliencyMapOutput> smo =
00322 seq->check<SimEventSaliencyMapOutput>(brain.get(), SEQ_ANY))
00323 {
00324
00325
00326
00327 }
00328 }
00329 seq->evolve();
00330
00331 return winner;
00332 }
00333 seq->evolve();
00334 }
00335 }
00336
00337 return Point2D<int>();
00338
00339 }
00340
00341 void biasVC(ComplexChannel &vc, Image<float> &mask)
00342 {
00343
00344 MaskBiaser mb(mask, true);
00345 vc.accept(mb);
00346
00347 setSubmapAlgorithmBiased(vc);
00348 }
00349