This heuristics computes a Local Binary Pattern (LBP)
Description:
It compares the pixel values to the center pixel.
x
x
x
x
o
x
x
x
x
The pixels x are compared to the value of the pixel o. Result returned is an LBP code value (8 bits example : 00100111). If x is greater than o the returned value is 1 otherwise 0.
In the following example:
110
160
205
111
150
130
90
155
85
the pixels are compared to the center pixel value 150 so the LBP code will be [01100010]
/** Author Flavio Tarsetti (Flavio.Tarsetti@idiap.ch) Declaration of the heuristic class This heuristics computes a Local Binary Pattern (LBP). It compares the pixel values to the center pixel. x x x x o x x x x The pixels 'x' are compared to the value of the pixel 'o' Result returned is an LBP code value (8 bits example : 00100111). if x is greater than o the returned value is 1 otherwise 0. example : 110 160 205 111 150 130 90 155 85 pixels are compared to the center pixel value 150 so the LBP code will be [01100010] */#include <mash/heuristic.h>#include <stdlib.h>usingnamespaceMash;classLBP:publicHeuristic{//_____ Construction / Destruction __________public:LBP();virtual~LBP();//_____ 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(){returnnewLBP();}/************************* CONSTRUCTION / DESTRUCTION *************************/LBP::LBP(){}LBP::~LBP(){}/************************* IMPLEMENTATION OF Heuristic ************************/unsignedintLBP::dim(){unsignedintroi_size=roi_extent*2+1;return(roi_size-2)*(roi_size-2);}scalar_tLBP::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;for(inti=-1;i<2;i++){for(intj=-1;j<2;j++){if(pLines[y0+(y+j)][x0+(x+i)]>pLines[y0+y][x0+x])result|=1<<countBits;countBits--;}}returnresult;}