-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyse_dataset.py
65 lines (52 loc) · 1.81 KB
/
analyse_dataset.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d # unused?
import os
from os import sep
from PIL import Image as Im
from utils import util
fig = plt.figure()
axis = plt.axes(projection='3d')
input_folder = ".{0}input{0}".format(sep)
red_values = list()
green_values = list()
blue_values = list()
def avg_color(color_values):
agg_val = 0
for val in color_values:
agg_val += val
return agg_val / len(color_values)
def main():
idx_limit = util.check_file_count(input_folder)
idx = 1
for file in os.listdir(input_folder):
print("Processing file {} | {} of {} | {:.2f} percent".format(file, idx, idx_limit, (idx / idx_limit) * 100))
temp_red = list()
temp_green = list()
temp_blue = list()
file_path = input_folder + file
with Im.open(file_path, "r") as image:
image_data = image.load()
for x in range(image.width):
for y in range(image.height):
red, green, blue = image_data[x, y][0], image_data[x, y][1], image_data[x, y][2]
temp_red.append(red)
temp_green.append(green)
temp_blue.append(blue)
avg_colors = round(avg_color(temp_red)), round(avg_color(temp_green)), round(avg_color(temp_blue))
red_values.append(avg_colors[0])
green_values.append(avg_colors[1])
blue_values.append(avg_colors[2])
idx += 1
# axis.plot3D(red_values, green_values, blue_values)
print("\nPlotting...")
try:
axis.scatter(red_values, green_values, blue_values, color="black")
except Exception as e:
pass
axis.set_xlabel("Red")
axis.set_ylabel("Green")
axis.set_zlabel("Blue")
print("Done.")
plt.show()
if __name__ == "__main__":
main()