getSaliency.C
Go to the documentation of this file.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 #include "Neuro/getSaliency.H"
00040
00041 #include "Channels/ChannelMaps.H"
00042 #include "Channels/ChannelOpts.H"
00043 #include "Component/OptionManager.H"
00044 #include "Media/MediaSimEvents.H"
00045 #include "Neuro/NeuroSimEvents.H"
00046 #include "Neuro/NeuroOpts.H"
00047 #include "Neuro/VisualCortex.H"
00048 #include "Util/log.H"
00049 #include "Image/MathOps.H"
00050 #include "Image/CutPaste.H"
00051 #include "Image/ShapeOps.H"
00052 #include <string>
00053
00054
00055 GetSaliency::GetSaliency(OptionManager& mgr) :
00056 StdBrain(mgr),
00057 SIMCALLBACK_INIT(SimEventWTAwinner),
00058 itsQ(new SimEventQueue(mgr)),
00059 itsSalmap(), itsCoords(), itsTimes()
00060 {
00061 this->addSubComponent(itsQ);
00062
00063
00064
00065
00066 }
00067
00068
00069
00070 GetSaliency::~GetSaliency()
00071 { }
00072
00073
00074 void GetSaliency::
00075 onSimEventWTAwinner(SimEventQueue& q, rutz::shared_ptr<SimEventWTAwinner>& e)
00076 {
00077 itsCoords.push_back(e->winner().p);
00078 itsTimes.push_back(q.now());
00079 }
00080
00081
00082 const int GetSaliency::compute(const Image< PixRGB<byte> >& img,
00083 const SimTime& max_time)
00084 {
00085 LINFO("Start at %.2fms", itsQ->now().msecs());
00086
00087 SimTime end_time = itsQ->now() + max_time;
00088
00089
00090 rutz::shared_ptr<SimEventInputFrame> e(new SimEventInputFrame(this, GenericFrame(img), 0));
00091 itsQ->post(e);
00092
00093
00094 itsCoords.clear(); itsTimes.clear();
00095
00096
00097 while (itsQ->now() < end_time) itsQ->evolve();
00098
00099
00100 if (SeC<SimEventVisualCortexOutput> e = itsQ->check<SimEventVisualCortexOutput>(this))
00101 itsSalmap = e->vco();
00102
00103
00104 return itsTimes.size();
00105 }
00106
00107
00108 const Image<float>& GetSaliency::getSalmap()
00109 { return itsSalmap; }
00110
00111
00112 const std::vector<Point2D<int> >& GetSaliency::getCoords()
00113 { return itsCoords; }
00114
00115
00116 const std::vector<SimTime>& GetSaliency::getTimes()
00117 { return itsTimes; }
00118
00119
00120 const std::vector<subMap>& GetSaliency::getSubMaps()
00121 {
00122
00123 rutz::shared_ptr<SimReqVCXmaps> vcxm(new SimReqVCXmaps(this));
00124 itsQ->request(vcxm);
00125 rutz::shared_ptr<ChannelMaps> chm = vcxm->channelmaps();
00126
00127 uint numSubmaps = chm->numSubmaps();
00128 Dims mapDims = chm->getMap().getDims();
00129 std::vector<subMap> theSubMaps(numSubmaps);
00130
00131 for(uint i=0;i < numSubmaps; i++)
00132 {
00133 NamedImage<float> tempMap = chm->getRawCSmap(i);
00134 theSubMaps[i].itsSubMap = tempMap;
00135 theSubMaps[i].itsSubMapName = tempMap.name();
00136
00137 if (theSubMaps[i].itsSubMap.getWidth() > mapDims.w())
00138 theSubMaps[i].itsSubMap = downSize(theSubMaps[i].itsSubMap, mapDims);
00139 else if (theSubMaps[i].itsSubMap.getWidth() < mapDims.w())
00140 theSubMaps[i].itsSubMap = rescale(theSubMaps[i].itsSubMap, mapDims);
00141 }
00142 itsSubMaps = theSubMaps;
00143 return itsSubMaps;
00144 }
00145
00146 Image<float> GetSaliency::getVCXmap(const Image<PixRGB<byte> > &img)
00147 {
00148 SimStatus status = itsQ->evolve();
00149 if (status != SIM_CONTINUE) LFATAL("Quitting! Queue Status is %d", status);
00150
00151
00152 itsQ->post(rutz::make_shared(
00153 new SimEventRetinaImage(
00154 this,
00155 InputFrame(InputFrame::fromRgb(&img, itsQ->now())),
00156 Rectangle(Point2D<int>(0,0), img.getDims()),
00157 Point2D<int>(0,0)
00158 )
00159 )
00160 );
00161
00162 Image<float> vcMap;
00163
00164 if (SeC<SimEventVisualCortexOutput> e = itsQ->check<SimEventVisualCortexOutput>(this, SEQ_ANY))
00165 vcMap = e->vco(1.0F);
00166
00167
00168 return vcMap;
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180