Number of different output labels in Local Binary Pattern
A pattern with uniformity measure exactly&nbsp;2 is determined by: the value&nbsp;$b$ of bit&nbsp;0, the position&nbsp;$i&gt;0$ of the first bit that is different from bit&nbsp;0 and the position&nbsp;$j$ of the first bit after the $i$th that is different from bit&nbsp;$i$.  (We may have $j=0$, for example in the pattern 00001111, which has $b=0$, $i=4$, $j=0$.)  How many choices are there for the triple $(b,i,j)$? Clearly, there are two choices for&nbsp;$b$.  For $i$ and&nbsp;$j$, there are  $\tfrac12(P-1)(P-2)$ choices with $i&lt;j$ and $P-1$ choices where $j=0$. Thus, the total number of choices for $i$ and&nbsp;$j$ is
$$ \tfrac12(P-1)(P-2) + P-1 = \tfrac12P(P-1)\,.$$

To that, you need to add three more labels: all zeroes, all ones and the label for all patterns of uniformity measure strictly more than&nbsp;2.