/** Author: Wenqi You (wenqi.you@epfl.ch) Simple example of a heuristic: Hue. Compute the hue of the pixels of the ROI.*/#include <mash/heuristic.h>#include <algorithm>usingnamespaceMash;//------------------------------------------------------------------------------/// The 'Hue' heuristic class//------------------------------------------------------------------------------classHueHeuristic:publicHeuristic{//_____ Implementation of Heuristic __________public:virtualunsignedintdim();virtualscalar_tcomputeFeature(unsignedintfeature_index);};//------------------------------------------------------------------------------/// Creation function of the heuristic//------------------------------------------------------------------------------extern"C"Heuristic*new_heuristic(){returnnewHueHeuristic();}/************************* IMPLEMENTATION OF Heuristic ************************/unsignedintHueHeuristic::dim(){// We have has many features than pixels in the region of interestunsignedintroi_size=roi_extent*2+1;returnroi_size*roi_size;}scalar_tHueHeuristic::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 featureRGBPixel_t**pLines=image->rgbLines();scalar_tR=pLines[y0+y][x0+x].r;scalar_tG=pLines[y0+y][x0+x].g;scalar_tB=pLines[y0+y][x0+x].b;scalar_tmin=std::min(std::min(R,G),B);scalar_tmax=std::max(std::max(R,G),B);scalar_tdelta=max-min;scalar_thue;if(delta==0){return-1;}if(R==max){hue=(G-B)/delta;}elseif(G==max){hue=2+(B-R)/delta;}else{hue=4+(R-G)/delta;}hue*=60;if(hue<0){hue+=360;}returnhue;}