void learnImage(Image<PixRGB<byte> > & img, int cls, DescriptorVec &descVec, Bayes &bayesNet, const char *objName) { //static int id = 0; const int learnNumSacc = 1; Point2D winner = evolveBrain(img, descVec); //evolve the brain for (int fix=0; fix<learnNumSacc; fix++) //learn the n most salient points in the image { //show winner if (debug){ Image<PixRGB<byte> > tmpImg = img; drawCircle(tmpImg, winner, 50, PixRGB<byte>(255, 0, 0), 3); SHOWIMG(tmpImg); } //get the descriptor descVec.setFovea(winner); if (debug){ //SHOWIMG(descVec.getFoveaImage()); } descVec.buildRawDV(); //build the descriptor vector //get the resulting feature vector std::vector<double> FV = descVec.getFV(); /* char filename[255]; sprintf(filename, "results/%i.ppm", id++); Raster::WriteRGB(descVec.getFoveaImage(), filename); printf("DV %i %s %i %ix%i: ",id, objName, sacc, winner.i, winner.j); for(uint i=0; i<FV.size(); i++) printf("%f ", FV[i]); printf("\n");*/ printf("OD: '%s' %i %i %i %i ",objName, cls, fix, winner.i, winner.j); for(uint i=0; i<FV.size(); i++) printf("%f ", FV[i]); printf("\n"); fflush(stdout); if (objName != NULL) { //LINFO("****Learning %s\n", objName); bayesNet.learn(FV, objName); } else bayesNet.learn(FV, cls); Image<PixRGB<byte> > nullImg; winner = evolveBrain(nullImg, descVec); //evolve the biased brain to get a new winner } }
int main(const int argc, const char **argv) { MYLOGVERB = LOG_INFO; mgr = new ModelManager("Test LabelMeSaliency"); //our brain nub::ref<StdBrain> brain2(new StdBrain(*mgr)); mgr->addSubComponent(brain2); mgr->exportOptions(MC_RECURSE); mgr->setOptionValString(&OPT_RawVisualCortexChans, "IOC"); //mgr.setOptionValString(&OPT_RawVisualCortexChans, "I"); //mgr->setOptionValString(&OPT_RawVisualCortexChans, "GNO"); //mgr.setOptionValString(&OPT_RawVisualCortexChans, "N"); //manager.setOptionValString(&OPT_UseOlderVersion, "false"); // set the FOA and fovea radii mgr->setOptionValString(&OPT_SaliencyMapType, "Fast"); mgr->setOptionValString(&OPT_SMfastInputCoeff, "1"); mgr->setOptionValString(&OPT_WinnerTakeAllType, "Fast"); mgr->setModelParamVal("FOAradius", 100, MC_RECURSE); mgr->setModelParamVal("FoveaRadius", 100, MC_RECURSE); mgr->setOptionValString(&OPT_IORtype, "Disc"); if (mgr->parseCommandLine( (const int)argc, (const char**)argv, "<path to images>", 1, 1) == false); mgr->start(); nub::ref<StdBrain> brain = dynCastWeak<StdBrain>(mgr->subComponent(0)); //"/lab/ilab15/tmp/objectsDB/mit/labelMe/05june05_static_indoor", TestImages testImages(mgr->getExtraArg(0).c_str(), TestImages::MIT_LABELME); printf("## \"Filename\", \"Size\", \"Number of objects\", \"Obj ID\", \"Size\"\n"); for(uint scene=0; scene<testImages.getNumScenes(); scene++) { //get the image LINFO("Get scene %i", scene); Image<PixRGB<byte> > img = testImages.getScene(scene); std::string sceneFile = testImages.getSceneFilename(scene); LINFO("Size %ix%i", img.getWidth(), img.getHeight()); if (testImages.getNumObj() > 0) //if we have any labled objects { for (uint obj=0; obj<testImages.getNumObj(); obj++) { Image<byte> objMask = testImages.getObjMask(obj); int objSize = -1; for(int y=0; y<objMask.getHeight(); y++) for(int x=0; x<objMask.getWidth(); x++) if (objMask.getVal(x,y) > 0) objSize++; // SHOWIMG(rescale(toRGB(objMask), 255, 255)); std::vector<Point2D<int> > objPoly = testImages.getObjPolygon(obj); Point2D<int> p1 = objPoly[0]; for(uint i=1; i<objPoly.size(); i++) { drawLine(img, p1, objPoly[i], PixRGB<byte>(255, 0, 0), 4); p1 = objPoly[i]; } drawLine(img, p1, objPoly[0], PixRGB<byte>(255, 0, 0), 4); //close the polygon printf("\"%s\",\"%ix%i\",\"%i\",\"%i\",\"%i\"\n", sceneFile.c_str(), img.getWidth(), img.getHeight(), testImages.getNumObj(), obj, objSize); } SHOWIMG(img); } else { printf("##%s has no objects \n", sceneFile.c_str()); } } }
int main(const int argc, const char **argv) { MYLOGVERB = LOG_INFO; mgr = new ModelManager("Test LabelMeSaliency"); nub::soft_ref<SimEventQueueConfigurator> seqc(new SimEventQueueConfigurator(*mgr)); mgr->addSubComponent(seqc); //our brain nub::ref<StdBrain> brain(new StdBrain(*mgr)); mgr->addSubComponent(brain); mgr->exportOptions(MC_RECURSE); mgr->setOptionValString(&OPT_RawVisualCortexChans, "IOC"); //mgr.setOptionValString(&OPT_RawVisualCortexChans, "I"); //mgr->setOptionValString(&OPT_RawVisualCortexChans, "GNO"); //mgr.setOptionValString(&OPT_RawVisualCortexChans, "N"); //manager.setOptionValString(&OPT_UseOlderVersion, "false"); // set the FOA and fovea radii mgr->setOptionValString(&OPT_SaliencyMapType, "Fast"); mgr->setOptionValString(&OPT_SMfastInputCoeff, "1"); mgr->setOptionValString(&OPT_WinnerTakeAllType, "Fast"); mgr->setOptionValString(&OPT_SimulationTimeStep, "0.2"); mgr->setModelParamVal("FOAradius", 128, MC_RECURSE); mgr->setModelParamVal("FoveaRadius", 128, MC_RECURSE); mgr->setOptionValString(&OPT_IORtype, "Disc"); if (mgr->parseCommandLine( (const int)argc, (const char**)argv, "<path to images>", 1, 1) == false); nub::soft_ref<SimEventQueue> seq = seqc->getQ(); mgr->start(); //nub::ref<StdBrain> brain = dynCastWeak<StdBrain>(mgr->subComponent("Brain")); //"/lab/ilab15/tmp/objectsDB/mit/labelMe/05june05_static_indoor", ComplexChannel *cc = &*dynCastWeak<ComplexChannel>(brain->getVC()); TestImages testImages(mgr->getExtraArg(0).c_str(), TestImages::MIT_LABELME); Image<float> allObjImg = Raster::ReadFloat("allObjImg.pfm", RASFMT_PFM); inplaceNormalize(allObjImg, 0.0F, 1.0F); printf("## \"Filename\", \"Size\",\"fovea Radius\",\"Number of objects\",\"Salient Location\", \"Hits\","); printf("\"Obj Saliency Max\",\"Obj Saliency Min\",\"Obj Saliency Sum\",\"Obj Saliency Area\""); printf("\"Dist Saliency Max\",\"Dist Saliency Min\",\"Dist Saliency Sum\",\"Dist Saliency Area\""); printf("\n"); for(uint scene=0; scene<testImages.getNumScenes(); scene++) { //get the image LINFO("Get scene %i", scene); Image<PixRGB<byte> > img = testImages.getScene(scene); std::string sceneFile = testImages.getSceneFilename(scene); LINFO("Size %ix%i", img.getWidth(), img.getHeight()); //set the fovea and foa radius to be 1/4 the size of the image width int fRadius = 128; //(img.getWidth()/16); //TODO: fixme //brain->getSM()->setFoveaRadius(fRadius); //brain->getSM()->setFOAradius(fRadius); initRandomNumbers(); if (testImages.getNumObj() > 0) //if we have any labled objects { //bias the vc Image<float> mask = rescale(allObjImg, img.getDims()); biasVC(*cc, mask); //evolve the brain Image<float> SMap; rutz::shared_ptr<SimEventInputFrame> //place the image in the queue e(new SimEventInputFrame(brain.get(), GenericFrame(img), 0)); seq->post(e); //set the task relevance map Point2D<int> winner; float interestLevel=100.0F; int nHits=0; int nTimes=95; printf("[ "); Point2D<int> lastLoc(-1,-1); while(interestLevel > 0.01F && nTimes < 100) //do until no more activation { nTimes++; LINFO("InterestLevel %f", interestLevel); Point2D<int> currentWinner = evolveBrain(img, SMap, &interestLevel, seq); if (debug) { if (lastLoc.isValid()) { drawLine(img, lastLoc, currentWinner, PixRGB<byte>(0, 255, 0), 4); } else { drawCircle(img, currentWinner, fRadius-10, PixRGB<byte>(255,0,0), 3); } lastLoc = currentWinner; drawCircle(img, currentWinner, fRadius, PixRGB<byte>(0,255,0), 3); } //check if the winner is inside an object (all objects) int hit = -1; for (uint obj=0; obj<testImages.getNumObj(); obj++) { int lineWidth = int(img.getWidth()*0.003); std::vector<Point2D<int> > objPoly = testImages.getObjPolygon(obj); if (debug) { Point2D<int> p1 = objPoly[0]; for(uint i=1; i<objPoly.size(); i++) { drawLine(img, p1, objPoly[i], PixRGB<byte>(255, 0, 0), lineWidth); p1 = objPoly[i]; } drawLine(img, p1, objPoly[0], PixRGB<byte>(255, 0, 0), lineWidth); //close the polygon } // if (testImages.pnpoly(objPoly, winner)) // hit = 1; if (testImages.pnpoly(objPoly, currentWinner)) { hit = obj; } } printf("%i ", hit); if (hit != -1) { winner = currentWinner; nHits++; } } if (debug) { Raster::WriteRGB(img, "IORSaliency.ppm"); Image<PixRGB<byte> > tmp = rescale(img, 512, 512); SHOWIMG(tmp); } printf("] "); printf("\"%s\",\"%ix%i\",\"%i\",\"%i\",\"(%i,%i)\",\"%i\"", sceneFile.c_str(), img.getWidth(), img.getHeight(), fRadius, testImages.getNumObj(), winner.i, winner.j, nHits); printf("\n"); if (debug) { Image<PixRGB<byte> > tmp = rescale(img, 512, 512); SHOWIMG(tmp); } //Compute the saliency ratio /*Image<byte> imgMask; //get the obj mask for (uint obj=0; obj<testImages.getNumObj(); obj++) { LINFO("Adding obj %i", obj); Image<byte> objMask = testImages.getObjMask(obj); if (imgMask.initialized()) imgMask += objMask; else imgMask = objMask; } if (debug) SHOWIMG(rescale((Image<float>)imgMask, 512, 512)); LINFO("Mask %ix%i", imgMask.getWidth(), imgMask.getHeight()); Image<float> distMask = chamfer34(imgMask, (byte)255); Image<float> objMask = binaryReverse(distMask, 255.0F); //normalize mask from 0 to 1 inplaceNormalize(objMask, 0.0F, 1.0F); inplaceNormalize(distMask, 0.0F, 1.0F); if (debug) SHOWIMG(rescale((Image<float>)objMask, 512, 512)); if (debug) SHOWIMG(rescale((Image<float>)distMask, 512, 512)); //resize the saliency map to the orig img size SMap = rescale(SMap, imgMask.getDims()); float objMin, objMax, objSum, objArea; getMaskedMinMaxSumArea(SMap, objMask, objMin, objMax, objSum, objArea); float distMin, distMax, distSum, distArea; getMaskedMinMaxSumArea(SMap, distMask, distMin, distMax, distSum, distArea); printf("\"%f\",\"%f\",\"%f\",\"%f\",\"%f\",\"%f\",\"%f\",\"%f\"", objMax, objMin, objSum, objArea, distMax, distMin, distSum, distArea); printf("\n"); */ } else { printf("##%s has no objects \n", sceneFile.c_str()); } } }