-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract.py
78 lines (73 loc) · 1.8 KB
/
extract.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
66
67
68
69
70
71
72
73
74
75
76
import csv
import extcolors
import colorpredictor
from pathlib import Path
def filtercolors(color):
item = []
for a in color:
item.append(a)
for i in range(len(item)):
if item[i] == "silver":
color.remove(item[i])
color.append("white")
if item[i] == "gray":
color.remove(item[i])
if item[i] == "maroon":
color.remove(item[i])
color.append("red")
if item[i] == "olive":
color.remove(item[i])
color.append("yellow")
if item[i] == "lime":
color.remove(item[i])
color.append("green")
if item[i] == "aqua" or item[i] == "teal" or item[i] == "navy":
color.remove(item[i])
color.append("blue")
if item[i] == "fuchsia":
color.remove(item[i])
color.append("purple")
if item[i] == "black":
color.remove(item[i])
return color
def coloriser(filename):
colors, pixel_count = extcolors.extract(filename)
rgb=[]
for item in colors:
rgb.append(item[0])
color1 = []
for item in rgb:
color1.append(colorpredictor.get_colour_name(item))
filtered_colors = set(color1)
colors_sorted=filtercolors(list(filtered_colors))
final = set(colors_sorted)
final = list(final)
row = []
filename_sorted = str(filename).split('/')
row.append(filename_sorted[-1])
for i in range(8):
row.append("0")
for items in final:
if items == "red":
row[1] = "1"
if items == "blue":
row[2] = "1"
if items == "green":
row[3] = "1"
if items == "white":
row[4] = "1"
if items == "pink":
row[5] = "1"
if items == "orange":
row[6] = "1"
if items == "yellow":
row[7] = "1"
if items == "purple":
row[8] = "1"
with open('onehotencoded.csv', 'a') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(row)
csvFile.close()
for filename in Path('/home/pranoy/Desktop/pookalam/static/pookalams').glob('**/*.jpg'):
print(filename)
coloriser(filename)