-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetColorInformation.py
More file actions
52 lines (33 loc) · 1.48 KB
/
Copy pathgetColorInformation.py
File metadata and controls
52 lines (33 loc) · 1.48 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from collections import Counter
import removeBlack
def getColorInformation(estimator_labels, estimator_cluster,hasThresholding=False):
# Variable to keep count of the occurance of each color predicted
occurance_counter = None
# Output list variable to return
colorInformation = []
#Check for Black
hasBlack =False
# If a mask has be applied, remove th black
if hasThresholding == True:
(occurance,cluster,black) = removeBlack.removeBlack(estimator_labels,estimator_cluster)
occurance_counter = occurance
estimator_cluster = cluster
hasBlack = black
else:
occurance_counter = Counter(estimator_labels)
# Get the total sum of all the predicted occurances
totalOccurance = sum(occurance_counter.values())
# Loop through all the predicted colors
for x in occurance_counter.most_common(len(estimator_cluster)):
index = (int(x[0]))
# Quick fix for index out of bound when there is no threshold
index = (index-1) if ((hasThresholding & hasBlack)& (int(index) !=0)) else index
# Get the color number into a list
color = estimator_cluster[index].tolist()
# Get the percentage of each color
color_percentage= (x[1]/totalOccurance)
#make the dictionay of the information
colorInfo = {"cluster_index":index , "color": color , "color_percentage" : color_percentage }
# Add the dictionary to the list
colorInformation.append(colorInfo)
return colorInformation