mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-06 05:16:40 +08:00
Added tests for the new functionality.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user