From c8f3a662259ca97f7f3f8083ca7334fba1eafb90 Mon Sep 17 00:00:00 2001 From: capitanbatata Date: Fri, 8 Aug 2014 14:22:27 +0200 Subject: [PATCH] Added tests for the new functionality. --- skimage/color/colorconv.py | 9 +++-- skimage/color/tests/test_colorconv.py | 58 +++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/skimage/color/colorconv.py b/skimage/color/colorconv.py index 03fd8413..46268bd2 100644 --- a/skimage/color/colorconv.py +++ b/skimage/color/colorconv.py @@ -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 diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index 63336a76..faf9b9db 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -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