1 | initial version |
first of all, LBP features are mostly used with histograms, rarely by themselves, and uniform LBP is used for compressing the histograms from 256 bins to 59, which gives quite some speedup when comparing them later.
i hope, you read the paper
so, nice, you finished the first step of it ;) , steps 2 and 3 would be:
2: in your lbp function, calculate a histogram from the center_lbp values
Mat hist(1,256,CV_32F); // 256 bins, float for later interpolation
// later, inside the loop:
// increment the counter for each seen value, hist with 256 elements
hist.at<float>(0,center_lbp) += 1;
// or, if uniform LBP, you'd use the lookup:
hist.at<float>(0,lookup[center_lbp]) += 1; // hist with 59 elements
3: don't do that for the whole image, but divide it into , like 8x8 patches, collect a histogram for each small patch, and in the end, concat them to a big 1-d feature vector , the final product.
Mat spatial_histogram(Mat src, int grid_x, int grid_y, uchar lookup[256] ) {
// calculate LBP patch size
int width = src.cols/grid_x;
int height = src.rows/grid_y;
Mat result = Mat::zeros(0, 0, CV_32F);
// iterate through grid
for(int i = 0; i < grid_y; i++) {
for(int j = 0; j < grid_x; j++) {
Mat patch(src, Range(i*height,(i+1)*height), Range(j*width,(j+1)*width));
int len = isUniform ? 59 : 256;
Mat hist = Mat::zeros(1,len,CV_32F);
// !! your code here (minus the img loading) : lbp(patch,hist,lookup);
result.push_back(hist);
}
}
return result;
}
the uniform lookup itself is not too difficult.
i'm actually getting lazy, for code look here