0x0002 - Undestanding LBP feature dimensions
LBP is really cool!
I was working with Local Binary Patterns (LBP) [1] recently to extract texture from facial images and I could not understand why my feature space was so huge (16384). So I did what I should have done a few years back and then took some time to carefully read the paper, as long as a few other sources, and here is my explanation to myself of it. Here you will find different informations about the subject merged with my thought process to understand it.
Next image is basic LBP as you may know it. We take a central pixel and compare it with its neighbours, assigning 1 when the neighbour is greater than or equal to the central pixel and 0 otherwise. It yields a binary string that might be interpreted as a decimal number. Considering the regular LBP with 8 neighbours, we get a range of 2^8 numbers (8 bits in the string -> [0-255] in decimal).

We basically have two options now: we can go further and apply LBP to the image as a whole and get an histogram out of that, or we can divide the image in smaller blocks and concatenate the smaller histograms into a big one.

This basic operator was then expanded [1, 2]. Now we can use a different number of neighbours, as well a different radius (distance from the central pixel).

Another idea that came later was “uniform” LBP [2]. An LBP is uniform when it has at most two transitions 1-0 or 0-1. Example: 11000011 is uniform because it has just two transitions while 10110101 is not uniform with its six transitions. If we consider a fixed neighborhood of 8, we might reduce histogram size from 256 to 59. That’s because there are 58 uniform numbers in the range [0-255] (run the python code below and you will see it). We assign a histogram bin for each uniform number and leave an extra bin for every non-uniform one (58 + 1). The number of uniform values can be estimated as P*(P-1)+2 [5] for P neighbours.
for number in range(0, 256):
print(str(number) + " => " + "{0:b}".format(number))
SO, my feature dimension was 16384 because I was using regular LBP (not uniform) with 8 neighbours, a radius of 1, and dividing the image in 64 regions. That means I had 64 histograms with 256 bins each. 256 * 64 = 16384! Wow! I excel at Math, I know that.
References and sources
[4] uniform LBP - mapping using lookup table
[5] I don’t understand how uniform pattern of LBP reduces its bin to 59? please answer me?
You can sign this feed if you want.