Example #1
0
def test_rgb_to_husl():
    rgb_arr = _img()
    husl_new = nphusl.rgb_to_husl(rgb_arr)
    for i in range(rgb_arr.shape[0]):
        for j in range(rgb_arr.shape[1]):
            assert _diff_hue(husl_new[i, j],
                             husl.rgb_to_husl(*rgb_arr[i, j]))
Example #2
0
def test_to_husl_2d():
    img = _img()[0]
    rgb_arr = img  * 255
    husl_new = nphusl.to_husl(rgb_arr)
    for row in range(rgb_arr.shape[0]):
        husl_old = husl.rgb_to_husl(*img[row])
        assert _diff(husl_new[row], husl_old)
Example #3
0
def test_rgb_to_husl_3d():
    rgb_arr = np.ascontiguousarray(_img()[:5, :5])
    husl_new = nphusl.rgb_to_husl(rgb_arr)
    for row in range(husl_new.shape[0]):
        for col in range(husl_new.shape[1]):
            husl_old = husl.rgb_to_husl(*rgb_arr[row][col])
            assert _diff_hue(husl_new[row, col], husl_old)
Example #4
0
def test_to_husl_2d():
    img = np.ascontiguousarray(_img()[:, 4])
    float_img = transform.ensure_rgb_float(img)
    husl_new = nphusl.to_husl(img)
    for row in range(img.shape[0]):
        husl_old = husl.rgb_to_husl(*float_img[row])
        _diff_husl(husl_new[row], husl_old)
Example #5
0
def test_cython_rgb_to_husl():
    from nphusl import _nphusl_cython as cy
    rgb = np.ndarray(dtype=float, shape=(2, 2, 3))
    rgb[:] = 200.0, 90.2, 240.4
    rgb[:] /= 255.0
    hsl = cy.rgb_to_husl(rgb)
    hsl_std = husl.rgb_to_husl(*(200.0/255, 90.2/255, 240.4/255))
    assert _diff(hsl, hsl_std, 0.1)
Example #6
0
def test_to_husl_3d():
    img = _img()
    rgb_arr = img  * 255
    husl_new = nphusl.to_husl(rgb_arr)
    for row in range(rgb_arr.shape[0]):
        for col in range(rgb_arr.shape[1]):
            husl_old = husl.rgb_to_husl(*img[row, col])
            assert _diff_hue(husl_new[row, col], husl_old)
Example #7
0
def test_to_husl_3d():
    img = _img()
    float_img = transform.ensure_rgb_float(img)
    husl_new = nphusl.to_husl(img)
    for row in range(img.shape[0]):
        for col in range(img.shape[1]):
            husl_old = husl.rgb_to_husl(*float_img[row, col])
            _diff_husl(husl_new[row, col], husl_old)
Example #8
0
 def husl(self):
     HUSL_Value = self.HUSL_Value
     _vmap = self._vmap
     result = _vmap.get("husl")
     if result is None:
         h, s, l = husl.rgb_to_husl(*self.rgb)
         result = _vmap["husl"] = HUSL_Value(h, s / 100., l / 100.)
     return result
Example #9
0
def test_rgb_to_husl_3d():
    rgb_arr = np.ascontiguousarray(_img()[:5, :5])
    float_arr = transform.ensure_rgb_float(rgb_arr)
    husl_new = _nphusl._rgb_to_husl(rgb_arr)
    for row in range(husl_new.shape[0]):
        for col in range(husl_new.shape[1]):
            husl_old = husl.rgb_to_husl(*float_arr[row, col])
            _diff_husl(husl_new[row, col], husl_old)
Example #10
0
 def husl (self) :
     HUSL_Value  = self.HUSL_Value
     _vmap       = self._vmap
     result      = _vmap.get ("husl")
     if result is None :
         h, s, l = husl.rgb_to_husl (* self.rgb)
         result  = _vmap ["husl"] = HUSL_Value (h, s / 100., l / 100.)
     return result
Example #11
0
def test_to_hue_vs_old():
    img = _img()
    rgb_arr = img  * 255
    hue_new = nphusl.to_hue(rgb_arr)
    for row in range(rgb_arr.shape[0]):
        for col in range(rgb_arr.shape[1]):
            husl_old = husl.rgb_to_husl(*img[row, col])
            diff = 5.0 if husl_old[1] < 1 else 0.0001
            assert _diff(hue_new[row, col], husl_old[0], diff=diff)
Example #12
0
def test_to_husl_gray():
    img = _img()
    img[..., 1] = img[..., 0]
    img[..., 2] = img[..., 0]
    rgb_arr = img[..., 0] * 255  # single channel
    husl_new = nphusl.to_husl(rgb_arr)
    for row in range(rgb_arr.shape[0]):
        for col in range(rgb_arr.shape[1]):
            husl_old = husl.rgb_to_husl(*img[row, col])
            assert _diff_hue(husl_new[row, col], husl_old)
Example #13
0
def test_to_husl_gray():
    img = transform.ensure_rgb_float(_img())
    img[..., 1] = img[..., 0]
    img[..., 2] = img[..., 0]
    gray_arr = img[..., 0]  # single channel
    husl_new = nphusl.to_husl(gray_arr)
    for row in range(gray_arr.shape[0]):
        for col in range(gray_arr.shape[1]):
            husl_old = husl.rgb_to_husl(*img[row, col])
            _diff_husl(husl_new[row, col], husl_old)
Example #14
0
def test_to_hue_gray():
    img = _img()
    img[..., 1] = img[..., 0]
    img[..., 2] = img[..., 0]
    rgb_arr = img[..., 0] * 255  # single channel
    hue_new = nphusl.to_hue(rgb_arr)
    for row in range(rgb_arr.shape[0]):
        for col in range(rgb_arr.shape[1]):
            hue_old = husl.rgb_to_husl(*img[row, col])
            diff = 5.0 if hue_old[1] < 1 else 0.0001
            assert _diff(hue_new[row, col], hue_old[0], diff=diff)
Example #15
0
def test_to_hue_gray():
    img = _img()
    img = transform.ensure_rgb_float(img)
    img[..., 1] = img[..., 0]
    img[..., 2] = img[..., 0]
    gray_arr = img[..., 0]  # single channel
    hue_new = nphusl.to_hue(gray_arr)
    for row in range(gray_arr.shape[0]):
        for col in range(gray_arr.shape[1]):
            husl_old = husl.rgb_to_husl(*img[row, col])
            assert husl_old[1] < 1  # low saturation
            # inaccurate hue values at low saturation
            _diff(hue_new[row, col], husl_old[0], diff=5)
Example #16
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])
Example #17
0
def test_to_husl_gray_3d():
    img = _img()
    img[..., 1] = img[..., 0]  # makes things gray
    img[..., 2] = img[..., 0]  # makes things gray
    img_float = transform.ensure_rgb_float(img)
    husl_new = nphusl.to_husl(img)
    was_wrong = False
    for row in range(img.shape[0]):
        for col in range(img.shape[1]):
            husl_old = husl.rgb_to_husl(*img_float[row, col])
            a = husl.husl_to_rgb(*husl_old)
            b = husl.husl_to_rgb(*husl_new[row, col])
            a = np.asarray(a)
            b = np.asarray(b)
            i = row * img.shape[1] * 3 + col * 3
            _diff_husl(husl_new[row, col], husl_old)
Example #18
0
def _ref_to_husl(rgb):
    asfloat = (c / 255.0 for c in rgb)
    return husl.rgb_to_husl(*asfloat)