|
@@ -14,7 +14,7 @@ def ingest_png(file_name: str) -> tuple[str, int, int, int, int]:
|
|
|
# X metric - mean sq norm of all pixels
|
|
|
x = sum(x * x + y * y + z * z for x, y, z in pixels) / len(pixels)
|
|
|
|
|
|
- # Y metrics - 2 * mean of color components
|
|
|
+ # Y metrics - mean of color components
|
|
|
yr_sum = 0
|
|
|
yg_sum = 0
|
|
|
yb_sum = 0
|
|
@@ -22,9 +22,8 @@ def ingest_png(file_name: str) -> tuple[str, int, int, int, int]:
|
|
|
yr_sum += r
|
|
|
yg_sum += g
|
|
|
yb_sum += b
|
|
|
- yfactor = 2 / len(pixels)
|
|
|
|
|
|
- return name, x, yr_sum * yfactor, yg_sum * yfactor, yb_sum * yfactor
|
|
|
+ return name, x, yr_sum / len(pixels), yg_sum / len(pixels), yb_sum / len(pixels)
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
@@ -34,4 +33,10 @@ if __name__ == "__main__":
|
|
|
data = [ingest_png("pngs/" + fn) for f in os.listdir("pngs") if (fn := os.fsdecode(f)).endswith(".png")]
|
|
|
with open("database.csv", "w") as outfile:
|
|
|
writer = csv.writer(outfile, delimiter=",", quotechar="'")
|
|
|
- writer.writerows(data)
|
|
|
+ writer.writerows(data)
|
|
|
+
|
|
|
+ with open("database.js", "w") as outfile:
|
|
|
+ outfile.write("const database = [\n")
|
|
|
+ for name, x, yr, yg, yb in data:
|
|
|
+ outfile.write(f' [ "{name}", {x}, {yr}, {yg}, {yb} ],\n')
|
|
|
+ outfile.write("];\n")
|