Ejemplo n.º 1
0
PseudorandomNumber::PseudorandomNumber()
	:_gen(110)
	,_dis(0, M_PI)
{
	initRandomNumbers();
}
// selfPresetLoaded is called whenever a new preset is triggered
// it'll be called right before selfBegin() and you may wish to
// refresh anything that a preset may offset, such as stored colors or particles
void CloudsVisualSystemRandomDigits2::selfPresetLoaded(string presetPath)
{
    initRandomNumbers();
}
void CloudsVisualSystemRandomDigits2::selfGuiEvent(ofxUIEventArgs &e)
{
    if(e.widget->getName() == "Update Number Placing") {
        initRandomNumbers();
    }
}
Ejemplo n.º 4
0
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());
                }
        }

}