def test_lab2xyz(self): assert_array_almost_equal(lab2xyz(self.lab_array), self.xyz_array, decimal=3) # Test the conversion with the rest of the illuminants. for I in ["A", "B", "C", "d50", "d55", "d65"]: I = I.lower() for obs in ["2", "10", "R"]: obs = obs.lower() fname = "color/tests/data/lab_array_{0}_{1}.npy".format(I, obs) lab_array_I_obs = np.load(fetch(fname)) assert_array_almost_equal(lab2xyz(lab_array_I_obs, I, obs), self.xyz_array, decimal=3) for I in ["d75", "e"]: fname = "color/tests/data/lab_array_{0}_2.npy".format(I) lab_array_I_obs = np.load(fetch(fname)) assert_array_almost_equal(lab2xyz(lab_array_I_obs, I, "2"), self.xyz_array, decimal=3) # And we include a call to test the exception handling in the code. try: xs = lab2xyz(lab_array_I_obs, "NaI", "2") # Not an illuminant except ValueError: pass try: xs = lab2xyz(lab_array_I_obs, "d50", "42") # Not a degree except ValueError: pass
def test_lab2xyz(self): assert_array_almost_equal(lab2xyz(self.lab_array), self.xyz_array, decimal=3) # Test the conversion with the rest of the illuminants. for I in ["d50", "d55", "d65", "d75"]: for obs in ["2", "10"]: fname = "lab_array_{0}_{1}.npy".format(I, obs) lab_array_I_obs = np.load( os.path.join(os.path.dirname(__file__), '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_{0}_2.npy".format(I, obs) lab_array_I_obs = np.load( os.path.join(os.path.dirname(__file__), 'data', fname)) assert_array_almost_equal(lab2xyz(lab_array_I_obs, I, "2"), self.xyz_array, decimal=3) # And we include a call to test the exception handling in the code. try: xs = lab2xyz(lab_array_I_obs, "NaI", "2") # Not an illuminant except ValueError: pass try: xs = lab2xyz(lab_array_I_obs, "d50", "42") # Not a degree except ValueError: pass
def test_lab_full_gamut(self): a, b = np.meshgrid(np.arange(-100, 100), np.arange(-100, 100)) L = np.ones(a.shape) lab = np.dstack((L, a, b)) for value in [0, 10, 20]: lab[:, :, 0] = value with expected_warnings(['Color data out of range']): lab2xyz(lab)
def test_lab2xyz_user_warning(): """ Show how the xyz color space is not a complete superset of all possible L*a*b combinations. z should always be greater than zero but are not in this example. See: https://github.com/scikit-image/scikit-image/issues/4506 """ with pytest.warns(UserWarning): xyz_array = lab2xyz(numpy.array([[[0, -13.70470524, 27.88690567]]])) x, y, z = xyz_array[0, 0, :] expected_x = -0.00334555 expected_y = 0 expected_z = -0.01928643 assert math.isclose(x, expected_x, rel_tol=1e-06) assert math.isclose(y, expected_y) assert math.isclose(z, expected_z, rel_tol=1e-06)
def preserve_color_cielch(content, stylized, image_name): # extract info and convert to CIE-LCh for each image rgbContent = io.imread(content) labContent = color.lab2lch( color.xyz2lab(color.rgb2xyz(numpy.asarray(rgbContent)))) labContentArray = numpy.array(labContent) rgbStyle = io.imread(stylized) labStyle = color.lab2lch( color.xyz2lab(color.rgb2xyz(numpy.asarray(rgbStyle)))) labStyleArray = numpy.array(labStyle) # color transfer for i in range(len(labContentArray)): for j in range(len(labContentArray[0])): labContentArray[i][j][0] = labStyleArray[i][j][0] labContentArray = color.xyz2rgb( color.lab2xyz(color.lch2lab(labContentArray))) viewer = ImageViewer(labContentArray) viewer.show()
def test_lab2xyz_dtype(self): img = self.lab_array.astype('float64') img32 = img.astype('float32') assert lab2xyz(img).dtype == img.dtype assert lab2xyz(img32).dtype == img32.dtype
def test_lab2xyz(self): assert_array_almost_equal(lab2xyz(self.lab_array), self.xyz_array, decimal=3)
def test_lab_to_xyz_against_skimage(random_lab): assert np.allclose(random_lab.to_xyz(), skcolor.lab2xyz(random_lab), rtol=1e-2)
def test_lab2xyz_channel_axis(self, channel_axis): # test conversion with channels along a specified axis lab = np.moveaxis(self.lab_array, source=-1, destination=channel_axis) xyz = lab2xyz(lab, channel_axis=channel_axis) xyz = np.moveaxis(xyz, source=channel_axis, destination=-1) assert_array_almost_equal(xyz, self.xyz_array, decimal=3)
def to_xyz_from_lab(self): return Image(lab2xyz(self)).convert_type(self.dtype)