How does LBP work? To learn that, I decided to calculate by hand for the matrix but the problem is about the rotation pixel over the image based on the radius and neighbor of LBP. I do it clockwise and top most left then top most right, but the result is still different from the result in "skimage" lib.
With the example like this:
[[5, 4, 2, 2, 1],
[3, 5, 8, 1, 3],
[2, 5, 4, 1, 2],
[4, 3, 7, 2, 7],
[1, 4, 4, 2, 6]]
and with rad=2, n=8, method='ror'
:
I try make it by hand with p(2,2) = 4
is:
[[ 5 2 1 ]
[ 2 4 2 ]
[ 3 4 2 ]]
so it may be is: 12243252 -> 00010010?
Otherwise, The result is in skimage:
[[ 1. 3. 7. 3. 7.]
[ 7. 0. 0. 31. 5.]
[ 15. 0. 9. 127. 15.]
[ 3. 3. 5. 23. 1.]
[ 7. 3. 5. 13. 0.]]
and code is:
from skimage import feature
import cv2
import numpy as np
import matplotlib.pyplot as plt
image = np.array([[5, 4, 2, 2, 1],
[3, 5, 8, 1, 3],
[2, 5, 4, 1, 2],
[4, 3, 7, 2, 7],
[1, 4, 4, 2, 6]])
radius = 2
neighbors = 8
lbp_result = feature.local_binary_pattern(image, neighbors, radius, 'ror')
plt.subplot(1, 2, 1)
plt.imshow(image, cmap='gray')
plt.title('Original Image')
plt.subplot(1, 2, 2)
plt.imshow(lbp_result, cmap='gray')
plt.title('LBP Image (r=2, 8 directions)')
print(image)
print()
print(lbp_result)
plt.show()
Can anyone help me with this, please? And by the way, how to rotate if the r > 2
and neighbor > 8
?Thank you so much for helping me.