Samuel Schmidt
Update src/LBP.py
b999e24
raw
history blame
954 Bytes
from skimage import feature
import numpy as np
from PIL import Image
class LBPImageEncoder:
def __init__(self, numPoints, radius):
# store the number of points and radius
self.numPoints = numPoints
self.radius = radius
def describe(self, image, eps=1e-7):
# compute the Local Binary Pattern representation
# of the image, and then use the LBP representation
# to build the histogram of patterns
print(image)
gray_img = image.convert('L')
print(gray_img)
lbp = feature.local_binary_pattern(gray_img, self.numPoints, self.radius, method="uniform")
(hist, _) = np.histogram(lbp.ravel(), bins=np.arange(0, self.numPoints + 3), range=(0, self.numPoints + 2))
# normalize the histogram
hist = hist.astype("float")
hist /= (hist.sum() + eps)
print(hist)
# return the histogram of Local Binary Patterns
return hist