File size: 825 Bytes
25ab7f8
654f874
cffc8b0
 
1b4e6a4
cffc8b0
 
 
 
 
 
287f384
cffc8b0
 
 
287f384
 
cffc8b0
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
        gray_img = imgage.convert('L')
        lbp = feature.local_binary_pattern(image, 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)
		# return the histogram of Local Binary Patterns
		return hist