Added tests for the new functionality.

This commit is contained in:
capitanbatata
2014-08-08 14:22:27 +02:00
parent ba664df275
commit c8f3a66225
2 changed files with 63 additions and 4 deletions
+5 -4
View File
@@ -392,15 +392,16 @@ def get_xyz_coords(illuminant, observer):
"""
illuminant = illuminant.upper()
if illuminant in illuminants.keys():
idx = 100;
if observer == 2:
idx = 0
elif observer == 10:
idx = 10
idx = 1
else:
ValueError("Unknown observer \"{}\"".format(observer))
raise ValueError("Unknown observer \"{}\"".format(observer))
return illuminants[illuminant][idx]
else:
ValueError("Unknown illuminant \"{}\"".format(illuminant))
raise ValueError("Unknown illuminant \"{}\"".format(illuminant))
# Haematoxylin-Eosin-DAB colorspace
@@ -745,7 +746,7 @@ def gray2rgb(image):
else:
raise ValueError("Input image expected to be RGB, RGBA or gray.")
def xyz2lab(xyz, illuminant = "D65", observer = 2999999999):
def xyz2lab(xyz, illuminant = "D65", observer = 2):
"""XYZ to CIE-LAB color space conversion.
Parameters
+58
View File
@@ -233,10 +233,39 @@ class TestColorconv(TestCase):
assert_array_almost_equal(xyz2lab(self.xyz_array),
self.lab_array, decimal=3)
## Thest the conversion with the rest of the illuminants.
for I in ["d50", "d55", "d65", "d75"]:
for obs in [2, 10]:
print("testing illuminant={}, observer={}".format(I, obs))
fname = "lab_array_{}_{}.npy".format(I, obs)
lab_array_I_obs = np.load(os.path.join('data', fname))
assert_array_almost_equal(lab_array_I_obs,
xyz2lab(self.xyz_array, I, obs), decimal=2)
for I in ["a", "e"]:
print("testing illuminant={}, observer=2".format(I))
fname = "lab_array_{}_2.npy".format(I)
lab_array_I_obs = np.load(os.path.join('data', fname))
assert_array_almost_equal(lab_array_I_obs,
xyz2lab(self.xyz_array, I, 2), decimal=2)
def test_lab2xyz(self):
assert_array_almost_equal(lab2xyz(self.lab_array),
self.xyz_array, decimal=3)
## Thest the conversion with the rest of the illuminants.
for I in ["d50", "d55", "d65", "d75"]:
for obs in [2, 10]:
fname = "lab_array_{}_{}.npy".format(I, obs)
lab_array_I_obs = np.load(os.path.join('data', fname))
assert_array_almost_equal(lab2xyz(lab_array_I_obs, I, obs),
self.xyz_array, decimal=3)
for I in ["a", "e"]:
fname = "lab_array_{}_2.npy".format(I, obs)
lab_array_I_obs = np.load(os.path.join('data', fname))
assert_array_almost_equal(lab2xyz(lab_array_I_obs, I, 2),
self.xyz_array, decimal=3)
def test_rgb2lab_brucelindbloom(self):
"""
Test the RGB->Lab conversion by comparing to the calculator on the
@@ -267,10 +296,39 @@ class TestColorconv(TestCase):
assert_array_almost_equal(xyz2luv(self.xyz_array),
self.luv_array, decimal=3)
## Thest the conversion with the rest of the illuminants.
for I in ["d50", "d55", "d65", "d75"]:
for obs in [2, 10]:
print("testing illuminant={}, observer={}".format(I, obs))
fname = "luv_array_{}_{}.npy".format(I, obs)
luv_array_I_obs = np.load(os.path.join('data', fname))
assert_array_almost_equal(luv_array_I_obs,
xyz2luv(self.xyz_array, I, obs), decimal=2)
for I in ["a", "e"]:
print("testing illuminant={}, observer=2".format(I))
fname = "luv_array_{}_2.npy".format(I)
luv_array_I_obs = np.load(os.path.join('data', fname))
assert_array_almost_equal(luv_array_I_obs,
xyz2luv(self.xyz_array, I, 2), decimal=2)
def test_luv2xyz(self):
assert_array_almost_equal(luv2xyz(self.luv_array),
self.xyz_array, decimal=3)
## Thest the conversion with the rest of the illuminants.
for I in ["d50", "d55", "d65", "d75"]:
for obs in [2, 10]:
fname = "luv_array_{}_{}.npy".format(I, obs)
luv_array_I_obs = np.load(os.path.join('data', fname))
assert_array_almost_equal(luv2xyz(luv_array_I_obs, I, obs),
self.xyz_array, decimal=3)
for I in ["a", "e"]:
fname = "luv_array_{}_2.npy".format(I, obs)
luv_array_I_obs = np.load(os.path.join('data', fname))
assert_array_almost_equal(luv2xyz(luv_array_I_obs, I, 2),
self.xyz_array, decimal=3)
def test_rgb2luv_brucelindbloom(self):
"""
Test the RGB->Lab conversion by comparing to the calculator on the