|
@@ -1,11 +1,16 @@
|
|
|
#!/usr/bin/env python3
|
|
|
import csv
|
|
|
+import math
|
|
|
from collections import defaultdict
|
|
|
|
|
|
+# include X
|
|
|
+include_x = False
|
|
|
+# normalize q and Y
|
|
|
+normalize = True
|
|
|
# closeness coefficient
|
|
|
closeness = 2
|
|
|
# step size within RGB color space
|
|
|
-step = 8
|
|
|
+step = 4
|
|
|
|
|
|
data = []
|
|
|
with open("database.csv") as infile:
|
|
@@ -28,7 +33,17 @@ for r 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 - closeness * (r * yr - g * yg - b * yb), name) for name, x, yr, yg, yb in data)
|
|
|
+ norm_color = math.sqrt(r * r + g * g + b * b)
|
|
|
+ if norm_color == 0:
|
|
|
+ continue
|
|
|
+ best_score = None
|
|
|
+ best_name = None
|
|
|
+ for name, x, yr, yg, yb in data:
|
|
|
+ norm = (norm_color * math.sqrt(yr * yr + yg * yg + yb * yb)) if normalize else 1
|
|
|
+ score = (x if include_x else 0) - (closeness * (r * yr + g * yg + b * yb) / norm)
|
|
|
+ if best_score is None or score < best_score:
|
|
|
+ best_score = score
|
|
|
+ best_name = name
|
|
|
results[(r, g, b)] = (best_name, best_score)
|
|
|
counts[best_name] += 1
|
|
|
|