MASH logo
Login | Register

cdubout/identity

User avatar

Core team

Author:
cdubout
Upload date:
April 20, 2010, 8:24 p.m.
Status:
Enabled
Summary:
Same as the example/identity heuristic except that it returns RGB values instead of grayscale.
Inspired by:
mash/identity
Evaluation:
Configuration Training error ( sd ) Test error ( sd )
adaboost-caltech 71.63% (2.5354) 76.24% (1.6315)
perceptron-mnist 7.54% (0.3067) 12.85% (0.1516)
/** Author: Charles Dubout (charles.dubout@idiap.ch)
 *
 *  Simple example of a heuristic: Identity. The features are a copy of the
 *  (rgb) pixels contained in the processed region of interest.
 */

#include <mash/heuristic.h>

using namespace Mash;

//------------------------------------------------------------------------------
/// The 'Identity' heuristic class
//------------------------------------------------------------------------------
class IdentityHeuristic: public Heuristic {
    //_____ Implementation of Heuristic __________
public:
    virtual unsigned int dim();

    virtual scalar_t computeFeature(unsigned int feature_index);
};

//------------------------------------------------------------------------------
/// Creation function of the heuristic
//------------------------------------------------------------------------------
extern "C" Heuristic* new_heuristic() {
    return new IdentityHeuristic();
}

/************************* IMPLEMENTATION OF Heuristic ************************/

unsigned int IdentityHeuristic::dim() {
    // We have has many features than pixels in the region of interest times 3
    unsigned int roi_size = roi_extent * 2 + 1;
    return roi_size * roi_size * 3;
}

scalar_t IdentityHeuristic::computeFeature(unsigned int feature_index) {
    // Compute the coordinates of the top-left pixel of the region of interest
    unsigned int x0 = coordinates.x - roi_extent;
    unsigned int y0 = coordinates.y - roi_extent;

    // Compute the coordinates of the pixel corresponding to the feature, in
    // the region of interest
    unsigned int roi_size = roi_extent * 2 + 1;
    unsigned int c = feature_index % 3;
    unsigned int x = (feature_index / 3) % roi_size;
    unsigned int y = (feature_index / 3) / roi_size;

    // Return the pixel value corresponding to the desired feature
    RGBPixel_t** pLines = image->rgbLines();

    if(c == 0) {
        return (scalar_t) pLines[y0 + y][x0 + x].r;
    }
    else if(c == 1) {
        return (scalar_t) pLines[y0 + y][x0 + x].g;
    }
    else {
        return (scalar_t) pLines[y0 + y][x0 + x].b;
    }
}