/** @file meanThreshold.cpp @author Philip Abbet (philip.abbet@idiap.ch) Example of a heuristic: MeanThreshold. The features indicates if the corresponding (grayscale) pixels is above or below the mean value of the processed region of interest.*/#include <mash/heuristic.h>usingnamespaceMash;//------------------------------------------------------------------------------/// @brief The 'MeanThreshold' heuristic class//------------------------------------------------------------------------------classMeanThresholdHeuristic:publicHeuristic{//_____ Construction / Destruction __________public:MeanThresholdHeuristic();virtual~MeanThresholdHeuristic();//_____ Implementation of Heuristic __________public:virtualunsignedintdim();virtualvoidprepareForCoordinates();virtualscalar_tcomputeFeature(unsignedintfeature_index);//_____ Attributes __________protected:float_mean;};//------------------------------------------------------------------------------/// @brief Creation function of the heuristic//------------------------------------------------------------------------------extern"C"Heuristic*new_heuristic(){returnnewMeanThresholdHeuristic();}/************************* CONSTRUCTION / DESTRUCTION *************************/MeanThresholdHeuristic::MeanThresholdHeuristic():_mean(0.0f){}MeanThresholdHeuristic::~MeanThresholdHeuristic(){}/************************* IMPLEMENTATION OF Heuristic ************************/unsignedintMeanThresholdHeuristic::dim(){// We have has many features than pixels in the region of interestunsignedintroi_size=roi_extent*2+1;returnroi_size*roi_size;}voidMeanThresholdHeuristic::prepareForCoordinates(){// Compute the coordinates of the top-left pixel of the region of interestunsignedintx0=coordinates.x-roi_extent;unsignedinty0=coordinates.y-roi_extent;// Compute the mean value of the region of interestbyte_t**pLines=image->grayLines();_mean=0.0f;for(unsignedinty=0;y<roi_extent*2+1;++y){for(unsignedintx=0;x<roi_extent*2+1;++x)_mean+=pLines[y0+y][x0+x];}_mean/=dim();}scalar_tMeanThresholdHeuristic::computeFeature(unsignedintfeature_index){// Compute the coordinates of the top-left pixel of the region of interestunsignedintx0=coordinates.x-roi_extent;unsignedinty0=coordinates.y-roi_extent;// Compute the coordinates of the pixel corresponding to the feature, in// the region of interestunsignedintroi_size=roi_extent*2+1;unsignedintx=feature_index%roi_size;unsignedinty=(feature_index-x)/roi_size;// Compute the feature valuebyte_t**pLines=image->grayLines();if(pLines[y0+y][x0+x]>=_mean)return1.0f;return0.0f;}