Reputation: 1219
I have been able to implement a basic local binary pattern (LBP), without interpolation. Following is the code: (OpenCV)
int center = 0;
int center_lbp = 0;
for (int row = 1; row < Image.rows; row++)
{
for (int col = 1; col < Image.cols; col++)
{
center = Image.at<int>(row, col);
center_lbp = 0;
if ( center <= Image.at<int>(row-1, col-1) )
center_lbp += 1;
if ( center <= Image.at<int>(row-1, col) )
center_lbp += 2;
if ( center <= Image.at<int>(row-1, col+1) )
center_lbp += 4;
if ( center <= Image.at<int>(row, col-1) )
center_lbp += 8;
if ( center <= Image.at<int>(row, col+1) )
center_lbp += 16;
if ( center <= Image.at<int>(row+1, col-1) )
center_lbp += 32;
if ( center <= Image.at<int>(row+1, col) )
center_lbp += 64;
if ( center <= Image.at<int>(row+1, col+1) )
center_lbp += 128;
cout << "center lbp value: " << center_lbp << endl;
LBPImage.at<int>(row, col) = center_lbp;
}
}
Read lot of things...but can't figure out how to create histogram now with uniform patterns concept...did check few links...nothing much there....can anybody please help...
thanks!
Upvotes: 3
Views: 3586
Reputation: 1219
Your code seems that, you are using 8-neighborhood LBP with radius r=1. So you can get maximum 256(2^8) number of different values. To construct Histogram, declare a matrix containing single row and 256 columns(bins) and initialize it with 0 :-
Mat H(1,256,CV_8UC1,Scalar::all(0));
Now for each central pixel ( pixels not in border ) ,after applying LBP you will get a binary string of length 8, and it's decimal encoding ( stored in center_lbp
variable in your code segment ) represents corresponding bin of the histogram. So after calculating center_lbp
just increment the value into the corresponding bin of the histogram as follows :-
H.at
<uchar>
(center_lbp)+=1;
After parsing the image for each central pixel, you will get a LBP histogram for that image.
LBP With Uniform Patterns :-
A LBP is called uniform if the circular binary pattern ( clockwise ) contains maximum 2 transition from 0 to 1 and vice versa . For Ex:- 00111000 is uniform pattern but 10111000 is not. To construct LBP Histogram for uniform pattern, the rule is -
for p number of neighbouring points, we can get maximum p*(p-1)+2 number of uniform patterns. So the histogram for uniform pattern will contain p*(p-1)+3 number of bins.
To construct the histogram :-
Upvotes: 3