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) if image.size == 0: print("Error: Input image is empty.") img_arr = np.array(image) print(img_arr.shape) gray_img = image.convert('L') if gray_img.size == 0: print("Error: Input image is empty.") gray_img_arr = np.array(gray_img) print(gray_img_arr.shape) print(gray_img) 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