8

I'm using the local_binary_pattern from skimage.feature with uniform mode like this:

>>> from skimage.feature import local_binary_pattern
>>> lbp_image=local_binary_pattern(some_grayscale_image,8,2,method='uniform')
>>> histogram=scipy.stats.itemfreq(lbp_image)
>>> print histogram
[[  0.00000000e+00   1.57210000e+04]
 [  1.00000000e+00   1.86520000e+04]
 [  2.00000000e+00   2.38530000e+04]
 [  3.00000000e+00   3.23200000e+04]
 [  4.00000000e+00   3.93960000e+04]
 [  5.00000000e+00   3.13570000e+04]
 [  6.00000000e+00   2.19800000e+04]
 [  7.00000000e+00   2.46530000e+04]
 [  8.00000000e+00   2.76230000e+04]
 [  9.00000000e+00   4.88030000e+04]]

As I'm taking 8 pixels in the neighborhood, it's expected to obtain 59 different LBP codes (because the uniform method), but instead it gives me only 9 different LBP codes. More generally, always return P+1 labels (where P is the number of neighbors).

It's another kind of uniform method, or I'm misunderstanding something?

maxymoo
  • 35,286
  • 11
  • 92
  • 119
mavillan
  • 365
  • 1
  • 2
  • 13

1 Answers1

19

Good question. Take a look at the LBP example in the gallery. Specifically, look at the following image:

LBP patterns

  • Uniformity: Since you chose 'uniform', the result only includes patterns where all black dots are adjacent and all white dots are adjacent. All other combinations are labeled 'non-uniform'.
  • Rotation invariance: Note that you chose 'uniform', not 'nri_uniform' (see the API docs), where "nri" means non-rotation invariant. That means 'uniform' is rotation invariant. As a result, an edge that is represented as 00001111 (0s and 1s represent black and white dots in the pic above) is collected into the same bin as 00111100 (the 0s are adjacent because we wrap around from front to back).
  • Rotation-invariant, uniform combinations: Considering rotation invariance, there are 9 unique, uniform combinations:
    • 00000000
    • 00000001
    • 00000011
    • 00000111
    • 00001111
    • 00011111
    • 00111111
    • 01111111
    • 11111111
  • Non-uniform results: If you look at your result more closely, there are actually 10 bins, not 9. The 10th bin lumps together all non-uniform results.

Hope that helps! If you haven't already, the LBP example is worth a look. I hear that somebody spent a lot of time on it ;)

Tony S Yu
  • 3,003
  • 30
  • 40
  • 2
    All makes sense now, thanks. By the way, I think the method names are a little confusing. In most of literature, uniform LBP stands for the simple no rotational invariant version. – mavillan Aug 20 '15 at 04:07
  • 1
    The "LBP example" link is broken – DarkCygnus May 02 '17 at 21:23
  • 1
    @GrayCygnus: Thanks for the notification! Links should be fixed now. – Tony S Yu May 03 '17 at 02:05
  • 1
    From the Master himself. Tony at some point in time was one of the Core developers of Scikit-image. – ultrasounder May 05 '17 at 18:03
  • To my understanding, `'nri_uniform'` is non-rotation invariant uniform and will give 59 dimensions vector, but I was given a 555 d vector. Why? How can I have 59-d descriptor? Where the 555-d descriptor comes from? Thanks! – huangbiubiu Feb 09 '18 at 03:47
  • @HuangYuheng I guess you used different number of neighbours. All those above-mentioned numbers are specifically for 8 neighbours. It would be great to see that level of detail for general N neighbours. – Matěj Račinský Oct 22 '18 at 08:54