-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixelProcessing.py
54 lines (37 loc) · 1.52 KB
/
pixelProcessing.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
from colorMath import *
from fileProcessing import outputDictToFile
from imageReading import readPixelsToDic
from collections import defaultdict
import csv
def comparePixelToColors(imagePixels):
pxColorNamed = defaultdict(int)
listOfColors = defaultdict(int)
with open('ColorList.csv') as infile:
reader = csv.DictReader(infile, delimiter=';')
for row in reader:
listColorRGB = (int(row['R']), int(row['G']), int(row['B']))
listOfColors[(listColorRGB)] = row['Name']
for color in imagePixels:
if color in listOfColors:
pxColorNamed[listOfColors[color]] += imagePixels[color]
else:
colorLAB1 = convRGBtoLAB(color)
bestMatch = [500, " "]
for listColor in listOfColors:
colorLAB2 = convRGBtoLAB(listColor)
dif = deltaE_1994(colorLAB1, colorLAB2)
if dif < bestMatch[0]:
bestMatch[0] = dif
bestMatch[1] = listOfColors[listColor]
pxColorNamed[bestMatch[1]] += imagePixels[color]
# outputDictToFile('imagePixels.csv', imagePixels)
# outputDictToFile('pxColorNamed.csv', pxColorNamed)
# outputDictToFile('listOfColors.csv', listOfColors)
return pxColorNamed
def determineDominateColor(pixelData):
dominateColor = [" ", 0]
for color in pixelData:
if pixelData[color] > dominateColor[1]:
dominateColor[0] = color
dominateColor[1] = pixelData[color]
return dominateColor