void stats(std:: valarray<float> map, float &mean, float &sigma, float &kurt, float &skew) { float sum = map.sum(); int n = map.size(); mean = map.sum()/float(n); std:: valarray <float> maps(n); valarray<float> maps2(n),maps3(n),maps4(n); for(int i=0; i<n; i++) { maps2[i] = gsl_pow_2(map[i] - mean); maps3[i] = gsl_pow_3(map[i] - mean); maps4[i] = gsl_pow_4(map[i] - mean); } sum = maps2.sum(); sigma = sqrt(sum/(float(n)-1.)); sum = maps3.sum(); double mu3 = sum/(float(n)-1.); sum = maps4.sum(); double mu4 = sum/(float(n)-1.); kurt = mu4/gsl_pow_4(sigma) -3; skew = mu3/gsl_pow_3(sigma); }
bool LineFit(float &kk,float &bb,float &ee,std::valarray <float> &data_x,std::valarray <float> &data_y) { if(data_x.size()<=1) { ROS_WARN("Line fit point is less than one!"); return false; } double A =0.0; double B =0.0; double C =0.0; double D =0.0; A = (data_x*data_x).sum(); B = data_x.sum(); C = (data_x*data_y).sum(); D = data_y.sum(); float k,b,tmp =0; if(tmp=(A*data_x.size()-B*B)) { k = (C*data_x.size()-B*D)/tmp; b = (A*D-C*B)/tmp; } else { k=0; b=B/data_x.size(); ROS_WARN("k is zero!"); } kk=k; bb=b; std::valarray <float> error(data_x.size()); error=data_x*k+b-data_y; ee=(error*error).sum()/error.size(); return true; }
// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated void _runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput) { // apply tone mapping on the multiplexed image // -> photoreceptors local adaptation (large area adaptation) _multiuseFilter->runFilter_LPfilter(grayImageInput, grayImageOutput, 0); // compute low pass filtering modeling the horizontal cells filtering to acess local luminance _multiuseFilter->setV0CompressionParameterToneMapping(1.f, grayImageOutput.max(), _meanLuminanceModulatorK*grayImageOutput.sum()/(float)_multiuseFilter->getNBpixels()); _multiuseFilter->runFilter_LocalAdapdation(grayImageInput, grayImageOutput, _temp2); // adapt contrast to local luminance // -> ganglion cells local adaptation (short area adaptation) _multiuseFilter->runFilter_LPfilter(_temp2, grayImageOutput, 1); // compute low pass filtering (high cut frequency (remove spatio-temporal noise) _multiuseFilter->setV0CompressionParameterToneMapping(1.f, _temp2.max(), _meanLuminanceModulatorK*grayImageOutput.sum()/(float)_multiuseFilter->getNBpixels()); _multiuseFilter->runFilter_LocalAdapdation(_temp2, grayImageOutput, grayImageOutput); // adapt contrast to local luminance }
// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated void RetinaFilter::_runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput, const float PhotoreceptorsCompression, const float ganglionCellsCompression) { // stability controls value update ++_ellapsedFramesSinceLastReset; std::valarray<float> temp2(grayImageInput.size()); // apply tone mapping on the multiplexed image // -> photoreceptors local adaptation (large area adaptation) _photoreceptorsPrefilter.runFilter_LPfilter(grayImageInput, grayImageOutput, 2); // compute low pass filtering modeling the horizontal cells filtering to acess local luminance _photoreceptorsPrefilter.setV0CompressionParameterToneMapping(PhotoreceptorsCompression, grayImageOutput.sum()/(float)_photoreceptorsPrefilter.getNBpixels()); _photoreceptorsPrefilter.runFilter_LocalAdapdation(grayImageInput, grayImageOutput, temp2); // adapt contrast to local luminance // high pass filter //_spatiotemporalLPfilter(_localBuffer, _filterOutput, 2); // compute low pass filtering (high cut frequency (remove spatio-temporal noise) //for (unsigned int i=0;i<_NBpixels;++i) // _localBuffer[i]-= _filterOutput[i]/2.0; // -> ganglion cells local adaptation (short area adaptation) _photoreceptorsPrefilter.runFilter_LPfilter(temp2, grayImageOutput, 1); // compute low pass filtering (high cut frequency (remove spatio-temporal noise) _photoreceptorsPrefilter.setV0CompressionParameterToneMapping(ganglionCellsCompression, temp2.max(), temp2.sum()/(float)_photoreceptorsPrefilter.getNBpixels()); _photoreceptorsPrefilter.runFilter_LocalAdapdation(temp2, grayImageOutput, grayImageOutput); // adapt contrast to local luminance }