Spaces:
Runtime error
Runtime error
Samuel Schmidt
commited on
Commit
·
a10ade2
1
Parent(s):
287f384
Fix: Intendation
Browse files- src/LBP.py +18 -16
src/LBP.py
CHANGED
@@ -2,21 +2,23 @@ from skimage import feature
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
|
|
|
5 |
class LBPImageEncoder:
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
gray_img =
|
16 |
-
lbp = feature.local_binary_pattern(
|
17 |
(hist, _) = np.histogram(lbp.ravel(), bins=np.arange(0, self.numPoints + 3), range=(0, self.numPoints + 2))
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
|
5 |
+
|
6 |
class LBPImageEncoder:
|
7 |
+
def __init__(self, numPoints, radius):
|
8 |
+
# store the number of points and radius
|
9 |
+
self.numPoints = numPoints
|
10 |
+
self.radius = radius
|
11 |
+
|
12 |
+
def describe(self, image, eps=1e-7):
|
13 |
+
# compute the Local Binary Pattern representation
|
14 |
+
# of the image, and then use the LBP representation
|
15 |
+
# to build the histogram of patterns
|
16 |
+
gray_img = image.convert('L')
|
17 |
+
lbp = feature.local_binary_pattern(gray_img, self.numPoints, self.radius, method="uniform")
|
18 |
(hist, _) = np.histogram(lbp.ravel(), bins=np.arange(0, self.numPoints + 3), range=(0, self.numPoints + 2))
|
19 |
+
# normalize the histogram
|
20 |
+
hist = hist.astype("float")
|
21 |
+
hist /= (hist.sum() + eps)
|
22 |
+
print(hist)
|
23 |
+
# return the histogram of Local Binary Patterns
|
24 |
+
return hist
|