/** Author: Kanma This heuristic looks at 9x9 blocks of grayscale pixels an returns the index of the one which is the farther (intensity-wise) of the center one. The indices are: 0 1 2 7 C 3 6 5 4*/#include <mash/heuristic.h>usingnamespaceMash;//------------------------------------------------------------------------------// Declaration of the heuristic class//------------------------------------------------------------------------------classFartherPixelHeuristic:publicHeuristic{//_____ Construction / Destruction __________public:FartherPixelHeuristic();virtual~FartherPixelHeuristic();//_____ Implementation of Heuristic __________public:virtualunsignedintdim();virtualscalar_tcomputeFeature(unsignedintfeature_index);};//------------------------------------------------------------------------------// Creation function of the heuristic//------------------------------------------------------------------------------extern"C"Heuristic*new_heuristic(){returnnewFartherPixelHeuristic();}/************************* CONSTRUCTION / DESTRUCTION *************************/FartherPixelHeuristic::FartherPixelHeuristic(){}FartherPixelHeuristic::~FartherPixelHeuristic(){}/************************* IMPLEMENTATION OF Heuristic ************************/unsignedintFartherPixelHeuristic::dim(){// We have a margin of 1 pixel on each border of the region of interestunsignedintroi_size=roi_extent*2+1;return(roi_size-2)*(roi_size-2);}scalar_tFartherPixelHeuristic::computeFeature(unsignedintfeature_index){// Compute the coordinates of the top-left pixel of the reduced region of// interestunsignedintx0=coordinates.x-roi_extent+1;unsignedinty0=coordinates.y-roi_extent+1;// Compute the coordinates of the pixel corresponding to the feature, in// the region of interestunsignedintroi_size=((roi_extent-1)*2+1);unsignedintx=feature_index%roi_size;unsignedinty=(feature_index-x)/roi_size;// Return the index of the farther surrounding pixelconstintoffsets[][2]={{-1,-1},{0,-1},{1,-1},{0,1},{1,1},{0,1},{-1,1},{-1,0},};constunsignedintnbOffsets=sizeof(offsets)/(2*sizeof(int));intmaxSquaredDist=0;unsignedintresult=0;byte_t**pLines=image->grayLines();byte_tcenter=pLines[y0+y][x0+x];for(unsignedinti=0;i<nbOffsets;++i){byte_tpixel=pLines[y0+y+offsets[i][0]][x0+x+offsets[i][1]];intsquaredDist=((int)pixel-(int)center)*((int)pixel-(int)center);if(squaredDist>maxSquaredDist){maxSquaredDist=squaredDist;result=i;}}return(scalar_t)result;}