/** Author: Andre Beinrucker (andre.beinrucker@uni-potsdam.de)//This is a very crude edge detector, inspired by the one described in www.idiap.ch/~fleuret/papers/fleuret-jmlr2004.pdf (Figure 3)*/#include <mash/heuristic.h>#include <math.h>usingnamespaceMash;//------------------------------------------------------------------------------/// The 'Identity' heuristic class//------------------------------------------------------------------------------classsimple_edgedetector:publicHeuristic{//_____ Construction / Destruction __________public:simple_edgedetector();virtual~simple_edgedetector();//_____ Implementation of Heuristic __________public:virtualunsignedintdim();virtualscalar_tcomputeFeature(unsignedintfeature_index);};//------------------------------------------------------------------------------/// Creation function of the heuristic//------------------------------------------------------------------------------extern"C"Heuristic*new_heuristic(){returnnewsimple_edgedetector();}/************************* CONSTRUCTION / DESTRUCTION *************************/simple_edgedetector::simple_edgedetector(){}simple_edgedetector::~simple_edgedetector(){}/************************* IMPLEMENTATION OF Heuristic ************************/unsignedintsimple_edgedetector::dim(){// We have has many features than pixels in the region of interestunsignedintroi_size=roi_extent*2+1;returnroi_size*roi_size;}scalar_tsimple_edgedetector::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;// Return the pixel value corresponding to the desired featurebyte_t**pLines=image->grayLines();//Detect horizontal edgesif((y<roi_size-2)&&(x<roi_size-1)&&(y>0)&&(x>0)){inthorizontal_difference=0;inthorizontal_average_of_differences=0;horizontal_difference=((pLines[y0+y][x0+x]-pLines[y0+y-1][x0+x]));horizontal_average_of_differences=(fabs(pLines[y0+y][x0+x-1]-pLines[y0+y][x0+x])+fabs(pLines[y0+y][x0+x]-pLines[y0+y][x0+x+1])+//fabs(pLines[y0 + y - 1][x0 + x ] - pLines[y0 + y ][x0 + x ]) +fabs(pLines[y0+y+1][x0+x-1]-pLines[y0+y+1][x0+x])+fabs(pLines[y0+y+1][x0+x]-pLines[y0+y+1][x0+x+1])//+//fabs(pLines[y0 + y + 1][x0 + x ] - pLines[y0 + y + 2][x0 + x ]));if(fabs(horizontal_difference)>2*fabs(horizontal_average_of_differences))return1.0f;}return0.0f;}