-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_colors.py
41 lines (32 loc) · 1.37 KB
/
test_colors.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
import numpy
from colormath.color_objects import sRGBColor, LabColor
from colormath.color_diff import delta_e_cie1994, delta_e_cie2000
from colormath.color_conversions import convert_color
from chromaticity.conversion import rgb2lab, cie94, ciede2000
from chromaticity.palettes import Iterator
def test_rgb2lab():
expected = numpy.array([[ 53.24, 80.09, 67.20],
[ 87.73, -86.18, 83.18],
[ 32.30, 79.19, -107.86]])
actual = rgb2lab(numpy.eye(3))
assert numpy.max(abs(expected - actual)) < 1e-2
def test_cie94():
for p in numpy.eye(3):
for q in numpy.eye(3):
cp = convert_color(sRGBColor(*p), LabColor)
cq = convert_color(sRGBColor(*q), LabColor)
assert abs(delta_e_cie1994(cp, cq) - cie94(rgb2lab(p), rgb2lab(q))) < 1e-2
def test_ciede2000():
for p in numpy.eye(3):
for q in numpy.eye(3):
cp = convert_color(sRGBColor(*p), LabColor)
cq = convert_color(sRGBColor(*q), LabColor)
# print(p, q, delta_e_cie2000(cp, cq), ciede2000(rgb2lab(p), rgb2lab(q)))
# TODO: what does this actually assert?
def test_iterator():
it = Iterator()
colors = set()
for i in range(1000):
color = '%02x%02x%02x' % tuple(int(round(z*255)) for z in it[i])
assert color not in colors
colors.add(color)