-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcolor-calculator2.py
39 lines (30 loc) · 1.03 KB
/
color-calculator2.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
29
30
31
32
33
34
35
36
37
38
39
from PIL import Image
import os
import json
import matplotlib.pyplot as plt
import numpy as np
outfit_color_pairs = {}
graph_list = []
for filename in os.listdir('generated'):
img = Image.open('generated/' + filename)
pixels = img.load()
unique_colors = []
for i in range(img.size[0]): # for every pixel:
for j in range(img.size[1]):
pixel = pixels[i,j]
maximum = max(pixel)
newcolor=[]
if maximum == 0:
newcolor = [0, 0, 0]
else:
for color in pixel:
newcolor.append(int(round(color/16)))
if newcolor not in unique_colors:
unique_colors.append(newcolor)
outfit_color_pairs[filename] = len(unique_colors)
graph_list.append(len(unique_colors))
pairs_sorted = {k: v for k, v in sorted(outfit_color_pairs.items(), key=lambda item: item[1])}
plt.hist(graph_list, density=True, bins=50)
plt.show()
with open('colors_in_generated.json', 'w') as f:
json.dump(pairs_sorted, f)