def test_snapshot(self):
        for hex_color, colors in self.snapshot.items():

            # Test forward functions
            test_rgb = husl.hex_to_rgb(hex_color)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            test_xyz = husl.rgb_to_xyz(test_rgb)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_luv = husl.xyz_to_luv(test_xyz)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_lch = husl.luv_to_lch(test_luv)
            self.assertTuplesClose(test_lch, colors['lch'])
            test_husl = husl.lch_to_husl(test_lch)
            self.assertTuplesClose(test_husl, colors['husl'])
            test_huslp = husl.lch_to_huslp(test_lch)
            self.assertTuplesClose(test_huslp, colors['huslp'])

            # Test backward functions
            test_lch = husl.husl_to_lch(colors['husl'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_lch = husl.huslp_to_lch(colors['huslp'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_luv = husl.lch_to_luv(test_lch)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_xyz = husl.luv_to_xyz(test_luv)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_rgb = husl.xyz_to_rgb(test_xyz)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            self.assertEqual(husl.rgb_to_hex(test_rgb), hex_color)

            # Full test
            self.assertEqual(husl.husl_to_hex(*colors['husl']), hex_color)
            self.assertTuplesClose(husl.hex_to_husl(hex_color), colors['husl'])
            self.assertEqual(husl.huslp_to_hex(*colors['huslp']), hex_color)
            self.assertTuplesClose(husl.hex_to_huslp(hex_color), colors['huslp'])
Exemple #2
0
def test_lch_to_husl_3d():
    img = _img()
    lch_new = nphusl.rgb_to_lch(img)
    hsl_new = nphusl.lch_to_husl(lch_new)
    for row in range(lch_new.shape[0]):
        for col in range(lch_new.shape[1]):
            lch_old = husl.rgb_to_lch(*img[row, col])
            assert _diff(lch_old, lch_new[row, col])
            hsl_old = husl.lch_to_husl(lch_old)
            assert _diff(hsl_new[row, col], hsl_old)
Exemple #3
0
def test_lch_to_husl_3d():
    img = _img()
    lch_new = _nphusl._rgb_to_lch(img)
    hsl_new = _nphusl._lch_to_husl(lch_new)
    for row in range(lch_new.shape[0]):
        for col in range(lch_new.shape[1]):
            lch_old = _ref_to_lch(img[row, col])
            _diff(lch_old, lch_new[row, col])
            hsl_old = husl.lch_to_husl(lch_old)
            _diff(hsl_new[row, col], hsl_old)
Exemple #4
0
def test_lch_to_husl():
    rgb_arr = _img()
    lch_arr = nphusl.rgb_to_lch(rgb_arr)
    hsl_from_lch_arr = nphusl.lch_to_husl(lch_arr)
    hsl_from_rgb_arr = nphusl.rgb_to_husl(rgb_arr)
    print(rgb_arr[30:34, 0])
    print(hsl_from_lch_arr[30:34, 0])
    print(hsl_from_rgb_arr[30:34, 0])
    for i in range(rgb_arr.shape[0]):
        old_lch = husl.rgb_to_lch(*rgb_arr[i, 0])
        hsl_old = husl.lch_to_husl(old_lch)
        hsl_old = husl.rgb_to_husl(*rgb_arr[i, 0])
        assert _diff(lch_arr[i, 0], old_lch)
        assert _diff_hue(hsl_from_lch_arr[i, 0], hsl_from_rgb_arr[i, 0])
        assert _diff_hue(hsl_from_lch_arr[i, 0], hsl_from_rgb_arr[i, 0])
Exemple #5
0
    def test_snapshot(self):
        for hex_color, colors in self.snapshot.items():

            # Test forward functions
            test_rgb = husl.hex_to_rgb(hex_color)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            test_xyz = husl.rgb_to_xyz(test_rgb)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_luv = husl.xyz_to_luv(test_xyz)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_lch = husl.luv_to_lch(test_luv)
            self.assertTuplesClose(test_lch, colors['lch'])
            test_husl = husl.lch_to_husl(test_lch)
            self.assertTuplesClose(test_husl, colors['husl'])
            test_huslp = husl.lch_to_huslp(test_lch)
            self.assertTuplesClose(test_huslp, colors['huslp'])

            # Test backward functions
            test_lch = husl.husl_to_lch(colors['husl'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_lch = husl.huslp_to_lch(colors['huslp'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_luv = husl.lch_to_luv(test_lch)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_xyz = husl.luv_to_xyz(test_luv)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_rgb = husl.xyz_to_rgb(test_xyz)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            self.assertEqual(husl.rgb_to_hex(test_rgb), hex_color)

            # Full test
            self.assertEqual(husl.husl_to_hex(*colors['husl']), hex_color)
            self.assertTuplesClose(husl.hex_to_husl(hex_color), colors['husl'])
            self.assertEqual(husl.huslp_to_hex(*colors['huslp']), hex_color)
            self.assertTuplesClose(husl.hex_to_huslp(hex_color),
                                   colors['huslp'])