16 float clampd,
float cx,
float cy);
22 enableUpdate(UPD_SCALE|UPD_DATA);
28 if(!isModified())
return false;
29 if(source->getDim1Size()>0) {
30 if(m_SData.getSizeX() != source->getDim1Size() ||
31 m_SData.getSizeY() != source->getDim2Size()) {
32 m_SData.setSize(source->getDim1Size(), source->getDim2Size());
34 source->getDim2Size());
35 m_FT.initTransform(m_SData.getSizeX(), m_SData.getSizeY(),
36 m_SData.getData(), (
double*)m_FData.getData());
46 if(m_FFilter.initialized() && m_FData.initialized()) {
47 m_SData.convertFrom(values);
51 values.convertFrom(m_SData);
57 assert(source->getDim1Size()>0);
58 bool nosizematch = !(m_SFilter.getSizeX() == source->getDim1Size() &&
59 m_SFilter.getSizeY() == source->getDim2Size());
60 if(isModified(UPD_SCALE) || nosizematch) {
61 unsetModified(UPD_SCALE);
63 m_SFilter.setSize(source->getDim1Size(), source->getDim2Size());
65 m_SFilter.getSizeY());
66 m_FTflt.initTransform(m_SFilter.getSizeX(), m_SFilter.getSizeY(),
68 (
double*)m_FFilter.getData());
70 float ffltsize = pow(2,scale);
71 int fltsize = (int)ffltsize;
72 if(fltsize<1) fltsize=1;
73 m_AddSkip = fltsize/2+1;
74 double stdev = ffltsize*0.5*0.2;
76 m_SFilter.getSizeX()/2.0f,m_SFilter.getSizeY()/2.0f);
79 double factor = 1.0/m_SFilter.
getSize();
80 double nfactor = -factor;
81 complex<double>* freq = m_FFilter.getData();
82 for(
int j=0; j<m_FFilter.getSizeY(); j++) {
83 for(
int i=0; i<m_FFilter.getSizeX(); i++, freq++) {
84 if((i+j)&0x01) *freq *= nfactor;
88 setModified(UPD_DATA);
95 : m_NormalizeInput(true)
104 for(vector<sensor_ptr>::iterator s=
sources.begin();
107 (*s)->unrefSuperSensor( shared_from_this() );
113 vector<sensor_ptr>::iterator s=
sources.begin();
115 (*s)->unrefSuperSensor( shared_from_this() );
141 sources[id]->unrefSuperSensor( shared_from_this() );
145 _source->refSuperSensor( shared_from_this() );
157 const string& sid = _source->getID();
158 vector<sensor_ptr>::iterator s =
sources.begin();
159 while(s!=
sources.end() && (*s)->getID()!=sid)
170 TRACE(
"error replacing element <" << sid <<
"> in combi sensor - appending instead.");
172 setSource(std::const_pointer_cast<Sensor>(_source),1.f);
198 for(vector<sensor_ptr>::const_iterator s = crhs.
sources.begin();
199 s != crhs.
sources.end(); s++, sid++)
200 setSource(std::const_pointer_cast<Sensor>(*s), weights[sid], sid);
209 os <<
"s " <<
getID() <<
" ";
213 vector<float>::const_iterator w =
cweights.begin();
214 for(vector<sensor_ptr>::const_iterator s=
sources.begin();
217 os <<
" " << (*s)->getID() <<
" " << *w;
225 for(vector<sensor_ptr>::const_iterator s=
sources.begin();
228 (*s)->hprint(os, sc);
232 return (
print(os) << endl);
252 const string& fn = fname.empty() ? m_Filename : fname;
253 ifstream is(fn.c_str());
254 if(!is)
return false;
257 if(icov.sizeX() != 3 || icov.sizeY() != 3) {
258 icov = dmutil::makeIdentity<float>(3);
260 if(m.sizeX() != 1 || m.sizeY() != 3) {
263 if(!fname.empty()) m_Filename = fname;
269 const string& fn = fname.empty() ? m_Filename : fname;
270 ofstream os(fn.c_str());
271 if(!os)
return false;
274 if(!fname.empty()) m_Filename = fname;
281 {
"identity",
"clamplu",
"clampl",
"clampu",
"gaussnorm",
"mgaussnorm",
282 "mclampu",
"bias", 0};
300 <<
"f " << getMappingName();
301 for(vector<float>::const_iterator p=m_Param.begin(); p!=m_Param.end(); p++)
310 if(
id>=MS_LAST) m_MappingID = 0;
else m_MappingID = id;
317 while(mid < MS_LAST && mname != s_MappingNames[mid]) mid++;
318 return setMappingID(mid);
326 float para= -0.12347891f;
328 if(para != -0.12347891f) m_Param.push_back(para);
331 dword psize = m_Param.size();
332 if((m_MappingID == MS_CLAMPL ||
333 m_MappingID == MS_CLAMPU ||
334 m_MappingID == MS_GAUSSNORM ||
335 m_MappingID == MS_MGAUSSNORM ||
336 m_MappingID == MS_MCLAMPU ||
337 m_MappingID == MS_BIAS)
340 m_MappingID = MS_IDENTITY;
343 if(m_MappingID == MS_CLAMPLU && psize<2)
345 m_MappingID = MS_IDENTITY;
return false;
352 if(
source->getDim1Size()>0) {
353 bool doanalysis =
true;
354 switch(m_MappingID) {
359 if(m_Param.size() < 4) m_Param.resize(4);
360 m_Param[1] = m_Param[2] = m_Param[3] = 0.f;
367 for(j=0; j<
source->getDim2Size(); j++) {
368 for(i=0; i<
source->getDim1Size(); i++)
370 float v =
source->getValue(i,j);
371 switch(m_MappingID) {
389 switch(m_MappingID) {
391 m_Param[1] /= m_Param[3];
392 m_Param[2] /= m_Param[3];
393 m_Param[2] =
sqrt(m_Param[2]-m_Param[1]*m_Param[1]);
394 m_Param[1] = m_Param[1]+m_Param[2]*m_Param[0];
398 m_Param[1] /= m_Param[3];
399 m_Param[2] /= m_Param[3];
400 m_Param[2] =
sqrt(m_Param[2]-m_Param[1]*m_Param[1]);
401 m_Param[2] = 1/(m_Param[2]*m_Param[0]);
404 m_Param[1] /= m_Param[3];
405 m_Param[2] /= m_Param[3];
406 m_Param[2] =
sqrt(m_Param[2]-m_Param[1]*m_Param[1]);
407 m_Param[2] = 1/(m_Param[2]*m_Param[0]);
408 m_Param[1] = m_Param[1] - (m_Param[1]/m_Param[2]);
419 float clampd,
float cx,
float cy)
421 clampd = clampd*clampd;
426 TRACE(
"creating filter " << xsize <<
" " << ysize);
427 for(j=0; j<ysize; j++)
428 for(i=0; i<xsize; i++, pixel++) {
429 float ii = (float)i-cx;
430 float jj = (float)j-cy;
431 float d2 = ii*ii+jj*jj;
433 double value =
gaussd2(d2, stdev);
std::ostream & hprint(std::ostream &os, SensorCollection *sc) const
bool isModified(dword mask=UPD_ALL) const
Sensor & assign(const Sensor &rhs)
std::vector< sensor_ptr > sources
float gaussd2(float x2, double stdev)
CombiSensor(int nchannels=0)
static Image< double > & create2DGaussian(Image< double > &flt, double stdev, float clampd, float cx, float cy)
virtual void changeSource(sensor_cptr _source)
std::ostream & print(std::ostream &os) const
std::vector< float > cweights
multi-channel weights ('color')
bool readParams(std::istream &is)
virtual void calcAllValues()
std::shared_ptr< Sensor > sensor_ptr
Sensor & assign(const Sensor &rhs)
sensor_ptr getZeroSensor()
const std::vector< float > & getCWeights() const
std::ostream & print(std::ostream &os) const
bool isUpdate(dword udMask) const
void setPrinted(const std::string &id)
static const char * s_MappingNames[]
void enableUpdate(dword udMask)
bool saveConfig(const std::string &fname="") const
DMatrix< T > sum(const DMatrix< T > &mat)
Sensor & assign(const Sensor &rhs)
dword setMapping(const std::string &mname)
SmoothIntensitySensor(float _scale=0)
virtual bool performUpdate()
bool isPrinted(const std::string &id) const
void changeSource(sensor_cptr _source)
const T * getData() const
bool loadConfig(const std::string &fname="")
std::shared_ptr< const Sensor > sensor_cptr
DMatrix< T > stdev(const DMatrix< T > &mat)
std::vector< float > m_Param
Sensor & assign(const Sensor &rhs)
void setSource(sensor_ptr _source, float weight, int id)
const std::string & getID() const
float stdev
overall mean and stdev
dword setMappingID(dword id)
void setModified(dword mask=UPD_ALL)
virtual std::ostream & print(std::ostream &os) const
DMatrix< T > & sqrt(DMatrix< T > &mat)