-
Notifications
You must be signed in to change notification settings - Fork 0
/
task2.py
28 lines (19 loc) · 707 Bytes
/
task2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import cv2 as cv
import numpy as np
class B:
def __init__(self):
pass
def centroid_histogram(self, kmeans):
numLabels = np.arange(0, len(np.unique(kmeans.labels_)) + 1)
(hist, _) = np.histogram(kmeans.labels_, bins=numLabels)
hist = hist.astype("float")
hist /= hist.sum()
return hist
def plot_colors(self, hist, centroids):
bar = np.zeros((50, 300, 3), dtype="uint8")
startX = 0
for(percent, color) in zip(hist, centroids):
endX = startX + (percent * 300)
cv.rectangle(bar, (int(startX), 0), (int(endX), 50), color.astype("uint8").tolist(), -1)
startX = endX
return bar