Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

if you imagine an lbp value as bits, i.e:

1 0 0 1 0 0 0 1

it is said to be "uniform", if the number of (circular) 0->1 and 1->0 crossings is <= 2, in other words:

1 1 1 0 0 0 1 1 // uniform
1 0 0 1 0 0 0 1 // not uniform
0 0 0 1 1 1 1 1 // uniform

now, for 8 bits, we can precalculate the values for each combination,

static int uniform[256] = // for exactly 8 bits / neighbours !
{  
    0,1,2,3,4,58,5,6,7,58,58,58,8,58,9,10,11,58,58,58,58,58,58,58,12,58,58,58,13,58,
    14,15,16,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,17,58,58,58,58,58,58,58,18,
    58,58,58,19,58,20,21,22,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,
    58,58,58,58,58,58,58,58,58,58,58,58,23,58,58,58,58,58,58,58,58,58,58,58,58,58,
    58,58,24,58,58,58,58,58,58,58,25,58,58,58,26,58,27,28,29,30,58,31,58,58,58,32,58,
    58,58,58,58,58,58,33,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,34,58,58,58,58,
    58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,
    58,35,36,37,58,38,58,58,58,39,58,58,58,58,58,58,58,40,58,58,58,58,58,58,58,58,58,
    58,58,58,58,58,58,41,42,43,58,44,58,58,58,45,58,58,58,58,58,58,58,46,47,48,58,49,
    58,58,58,50,51,52,58,53,54,55,56,57
};

since we're applying histograms later, each uniform value gets it's own "bin", all non-uniform values go into the "noise" bin (58)

now, if you calculated your lbp feature image, to make this "uniform" all you need to do is to replace each value with the one from the lookup table. we could do this in a loop, replacing v[i] with uniform[v[i]], but it's far easier to use opencv's LUT

Mat lbp = ...
Mat uniform_lbp;
LUT(lbp, uniform, uniform_lbp);

after that, you can build histograms on grid patches as usual, only difference is, that your range is {0,58} instead of {0,255}, and the histSize is 59, not 256.

if you imagine an lbp value as bits, i.e:

1 0 0 1 0 0 0 1

it is said to be "uniform", if the number of (circular) 0->1 and 1->0 crossings is <= 2, in other words:

1 1 1 0 0 0 1 1 // uniform
1 0 0 1 0 0 0 1 // not uniform
0 0 0 1 1 1 1 1 // uniform

now, for 8 bits, we can precalculate the values for each combination,

static int uniform[256] = // for exactly 8 bits / neighbours !
{  
    0,1,2,3,4,58,5,6,7,58,58,58,8,58,9,10,11,58,58,58,58,58,58,58,12,58,58,58,13,58,
    14,15,16,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,17,58,58,58,58,58,58,58,18,
    58,58,58,19,58,20,21,22,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,
    58,58,58,58,58,58,58,58,58,58,58,58,23,58,58,58,58,58,58,58,58,58,58,58,58,58,
    58,58,24,58,58,58,58,58,58,58,25,58,58,58,26,58,27,28,29,30,58,31,58,58,58,32,58,
    58,58,58,58,58,58,33,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,34,58,58,58,58,
    58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,
    58,35,36,37,58,38,58,58,58,39,58,58,58,58,58,58,58,40,58,58,58,58,58,58,58,58,58,
    58,58,58,58,58,58,41,42,43,58,44,58,58,58,45,58,58,58,58,58,58,58,46,47,48,58,49,
    58,58,58,50,51,52,58,53,54,55,56,57
};

since we're applying histograms later, each uniform value gets it's own "bin", all non-uniform values go into the "noise" bin (58)

now, if you calculated your lbp feature image, to make this "uniform" all you need to do is to replace each value with the one from the lookup table. we could do this in a loop, replacing v[i] lbp[i] with uniform[v[i]], uniform[lbp[i]], but it's far easier to use opencv's LUT

Mat lbp = ...
Mat uniform_lbp;
LUT(lbp, uniform, uniform_lbp);

after that, you can build histograms on grid patches as usual, only difference is, that your range is {0,58} instead of {0,255}, and the histSize is 59, not 256.