Direct Graphical Models  v.1.7.0
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()
{
if (argc != 3) {
print_help(argv[0]);
return 0;
}
Mat img = imread(argv[1], 1);
Mat coord = fex::CCoordinate::get(img);
// 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);
imwrite(argv[2], featureImg);
return 0;
}