Direct Graphical Models  v.1.5.2
Demo Feature Extraction

In this example we extract 3 features from the input image Original Image.jpg. These features are NDVI, Variance of intensity and saturation. The features are calculated for every pixel of the input image and thus are represented as images of the same resolution as the input one. It is often convenient to have a set of features in form of one multi-channel image. For storing such a multi-channel image is usually split into a number of 3-channels RGB images. Hence, for sake of simplicity, we extract only 3 features in this example.

Input
Output
Original Image.jpg
Resulting Feature Vector
#include "FEX.h"
using namespace DirectGraphicalModels;
int main()
{
Mat img = imread("Original Image.jpg", 1);
// Extracting 3 features
Mat ndvi = fExtractor.getNDVI(10).get(); // NDVI feature
Mat variance = fExtractor.getIntensity(CV_RGB(0.0, 0.5, 0.5)).getVariance().get(); // Variance of intensity feature
Mat saturation = fExtractor.getSaturation().invert().get(); // Inverted saturation feature
// Storing 3 features in a 3 channel RGB image
Mat featureImg;
vec_mat_t channels;
channels.push_back(ndvi); // blue channel
channels.push_back(variance); // green channel
channels.push_back(saturation); // red channel
merge(channels, featureImg);
imshow("Feature Vector", featureImg);
cvWaitKey();
return 0;
}