|
@@ -2,6 +2,11 @@
|
|
|
import csv
|
|
|
from collections import defaultdict
|
|
|
|
|
|
+# closeness coefficient
|
|
|
+closeness = 2
|
|
|
+# step size within RGB color space
|
|
|
+step = 8
|
|
|
+
|
|
|
data = []
|
|
|
with open("database.csv") as infile:
|
|
|
for name, *nums in csv.reader(infile, delimiter=",", quotechar="'"):
|
|
@@ -17,14 +22,13 @@ try:
|
|
|
except:
|
|
|
pass # file not found, assume no prior results
|
|
|
|
|
|
-step = 8
|
|
|
for r in range(0, 256, step):
|
|
|
for g in range(0, 256, step):
|
|
|
for b in range(0, 256, step):
|
|
|
if (known := results.get((r, g, b), None)) is not None:
|
|
|
counts[known[0]] += 1
|
|
|
continue
|
|
|
- best_score, best_name = min((x - r * yr - g * yg - b * yb, name) for name, x, yr, yg, yb in data)
|
|
|
+ best_score, best_name = min((x - closeness * (r * yr - g * yg - b * yb), name) for name, x, yr, yg, yb in data)
|
|
|
results[(r, g, b)] = (best_name, best_score)
|
|
|
counts[best_name] += 1
|
|
|
|