2

I found that the local binary pattern in scikit-image is affected by re-scaling the image, but I was not expecting this. Since the LBP just involves greater/less than comparisons between nearby pixels, I thought a linear transformation would not affect things.

import numpy as np
import skimage
from skimage.feature import local_binary_pattern

im = skimage.data.cell()

out_im = local_binary_pattern(im, 16, 2, method='uniform')
out_im = out_im[20:-20, 20:-20] # remove edges
counts,bins = np.histogram(out_im)
print('counts=',counts)
print('bins=',bins)

This gives me

counts= [   896   2743   9555  14928 108466  94041  28682  14703   8728  33458]
bins= [ 0.   1.7  3.4  5.1  6.8  8.5 10.2 11.9 13.6 15.3 17. ]

But if I normalize the image:

im = (im-im.min())/(im.max()-im.min())

Then I get:

counts= [   937   2716   9504  16263 109302  92114  27753  14248   8667  34696]
bins= [ 0.   1.7  3.4  5.1  6.8  8.5 10.2 11.9 13.6 15.3 17. ]

Can someone explain why? The original image has values between 0 and 255.

4
  • The comparison is done on fixed positions. When you resize the image, you will compare with different content (the same fixed positions have a different content now) Commented Aug 7, 2022 at 22:47
  • I’m not resizing, just mapping the intensity to the range [0,1] Commented Aug 8, 2022 at 12:03
  • Can you tell min and max values? What happens in the image border, if 0 neighborhood is assumed outside of the image you will have additional "equal" patterns after scaling min to 0 Commented Aug 8, 2022 at 12:45
  • I added them in the post. They are 0 and 255. I also removed the edges. Commented Aug 9, 2022 at 15:40

1 Answer 1

1

I found that there is no difference when there are only 4 points in the kernel, which correspond to up/down/left/right. This suggests that the difference arises due to the floating point interpolation when the points are located at non-integer coordinates. I'm guessing that the floating point calculations occasionally mess up the greater/equal comparisons, leading to slightly different histograms.

Sign up to request clarification or add additional context in comments.

2 Comments

I think you're right, this is a floating-point rounding error issue. Note that the scaling itself already introduces rounding errors.
There are sometimes even differences when multiplying an integer image by another integer. The image remains integer-type, but if the number of kernel points is not 4, the floating point interpolation sometimes changes things.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.