-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolour.py
79 lines (62 loc) · 2.09 KB
/
colour.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
77
78
79
import pandas as pd
from pandas import DataFrame
import csv
import urllib
import sys
import Image
import pprint
import cooperhewitt.roboteyes.shannon as shannon
import cooperhewitt.roboteyes.colors.palette as palette
from roygbiv import *
import urllib
import json
import csv
import cooperhewitt.swatchbook as sb
input ="input2.csv"
df = pd.read_csv(input)
r=open("AppliedArts.csv","ab")
rr=csv.writer(r)
headings = [['id','image','entropy','c1','c2','c3','c4','c5','C11','C22','C33','C44','C55']]
rr.writerows(headings)
for index, row in df.iterrows():
try:
pic = row['image']
Id = row['url']
urllib.urlretrieve(pic,'1.jpg')
im = Image.open('1.jpg')
roy = Roygbiv(im)
entropy = shannon.entropy(im)
ref = 'crayola'
rsp = palette.extract_roygbiv(im, ref)
parsed_json = json.loads(json.dumps(rsp))
A1 = parsed_json['palette'][0]['color']
C1 = sb.closest('css3', A1)
C11 = sb.closest('naturalcolorsystem', A1)
A2 = parsed_json['palette'][1]['color']
C2 = sb.closest('css3', A2)
C22 = sb.closest('naturalcolorsystem', A2)
A3 = parsed_json['palette'][2]['color']
C3 = sb.closest('css3', A3)
C33 = sb.closest('naturalcolorsystem', A3)
A4 = parsed_json['palette'][3]['color']
C4 = sb.closest('css3', A4)
C44 = sb.closest('naturalcolorsystem', A4)
A5 = parsed_json['palette'][4]['color']
C5 = sb.closest('css3', A5)
C55 = sb.closest('naturalcolorsystem', A5)
data = [[Id,pic,entropy,C1,C2,C3,C4,C5,C11,C22,C33,C44,C55]]
print data
rr.writerows(data)
except IndexError:
print("<5 colours")
data =[[Id,pic,'error']]
rr.writerows(data)
except ValueError:
print("value error")
data =[[Id,pic,' Value error']]
rr.writerows(data)
except IOError:
print("IO image error")
data =[[Id,pic,'IO image error']]
rr.writerows(data)
rr.close()