/** Author Flavio Tarsetti (Flavio.Tarsetti@idiap.ch) Declaration of the heuristic class This heuristics computes an Local Binary Pattern (ILBP). It compares each pixel values to the mean pixel value. x x x x o x x x x The pixels 'x' are compared to the mean value of the pixel 'o' and 'x' Result returned is an ILBP code value (8 bits example : 00100111). if x is greater than the mean value the returned value is 1 otherwise 0. example : 110 160 205 111 150 130 90 155 85 pixels are compared to the mean pixel value 133 so the ILBP code will be [01100010] */#include <mash/heuristic.h>#include <stdlib.h>usingnamespaceMash;classILBP:publicHeuristic{//_____ Construction / Destruction __________public:ILBP();virtual~ILBP();//_____ Implementation of Heuristic __________public://--------------------------------------------------------------------------// Returns the number of features this heuristic computes//// When this method is called, the 'roi_extent' attribute is initialized//--------------------------------------------------------------------------virtualunsignedintdim();//--------------------------------------------------------------------------// Computes the specified feature//// When this method is called, the following attributes are initialized:// - roi_extent// - image// - coordinates//--------------------------------------------------------------------------virtualscalar_tcomputeFeature(unsignedintfeature_index);//_____ Attributes __________protected:};//------------------------------------------------------------------------------// Creation function of the heuristic//------------------------------------------------------------------------------extern"C"Heuristic*new_heuristic(){returnnewILBP();}/************************* CONSTRUCTION / DESTRUCTION *************************/ILBP::ILBP(){}ILBP::~ILBP(){}/************************* IMPLEMENTATION OF Heuristic ************************/unsignedintILBP::dim(){unsignedintroi_size=roi_extent*2+1;return(roi_size-2)*(roi_size-2);}scalar_tILBP::computeFeature(unsignedintfeature_index){unsignedintx0=coordinates.x-roi_extent;unsignedinty0=coordinates.y-roi_extent;div_tv=div(feature_index,(roi_extent*2+1-2));unsignedinty=v.quot+1;unsignedintx=v.rem+1;byte_t**pLines=image->grayLines();unsignedcharresult=0;intcountBits=7;intnum_pixels=0;floatmean_pixels_value=0;for(inti=-1;i<2;i++){for(intj=-1;j<2;j++){num_pixels++;mean_pixels_value+=pLines[y0+(y+j)][x0+(x+i)];}}mean_pixels_value/=num_pixels;for(inti=-1;i<2;i++){for(intj=-1;j<2;j++){if(pLines[y0+(y+j)][x0+(x+i)]>mean_pixels_value)result|=1<<countBits;countBits--;}}returnresult;}