예제 #1
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)
예제 #2
0
def test_rgb_to_xyz_3d():
    img = _img()
    float_img = transform.ensure_rgb_float(img)
    xyz_arr = _nphusl._rgb_to_xyz(img)
    for row in range(img.shape[0]):
        for col in range(img.shape[1]):
            _diff(xyz_arr[row, col], husl.rgb_to_xyz(float_img[row, col]))
예제 #3
0
def test_lch_to_rgb():
    img = _img()
    float_img = transform.ensure_rgb_float(img)
    lch = _nphusl._rgb_to_lch(float_img)
    rgb = _nphusl._lch_to_rgb(lch)
    int_rgb = transform.ensure_rgb_int(rgb)
    _diff(int_rgb, img, diff=1)
예제 #4
0
def test_rgb_to_xyz():
    rgb_arr = _img()[:, 0]
    float_arr = transform.ensure_rgb_float(rgb_arr)
    xyz_arr = _nphusl._rgb_to_xyz(rgb_arr)
    for xyz, rgb, rgbf in zip(xyz_arr, rgb_arr, float_arr):
        diff = xyz - husl.rgb_to_xyz(rgbf)
        _diff(xyz, husl.rgb_to_xyz(rgbf))
예제 #5
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)
예제 #6
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)
예제 #7
0
def test_to_husl_rgba():
    rgb = transform.ensure_rgb_float(_img())
    rgba = np.zeros(shape=rgb.shape[:-1] + (4, ), dtype=rgb.dtype)
    rgba[..., :3] = rgb
    rgba[..., 3] = 0.5  # 50% for a float RGBA array
    new_rgb = rgb * 0.5
    hsl_from_rgba = nphusl.to_husl(rgba)
    hsl_from_rgb = nphusl.to_husl(new_rgb)
    _diff_husl(hsl_from_rgba, hsl_from_rgb)
예제 #8
0
def test_husl_to_lch():
    img = _img()
    float_img = transform.ensure_rgb_float(img)
    lch = _nphusl._rgb_to_lch(float_img)
    husl = nphusl.to_husl(img)
    lch_2 = _nphusl._husl_to_lch(husl)
    img_2 = _nphusl._lch_to_rgb(lch_2)
    img_2 = transform.ensure_rgb_int(img_2)
    _diff(img_2, img, diff=1)
예제 #9
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)
예제 #10
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)
예제 #11
0
def test_luv_to_lch():
    rgb_arr = _img()[:, 14]
    float_arr = transform.ensure_rgb_float(rgb_arr)
    rgb_arr = rgb_arr.reshape((rgb_arr.size // 3, 3))
    xyz_arr = _nphusl._rgb_to_xyz(rgb_arr)
    luv_arr = _nphusl._xyz_to_luv(xyz_arr)
    lch_arr = _nphusl._luv_to_lch(luv_arr)
    for i in range(rgb_arr.shape[0]):
        xyz = husl.rgb_to_xyz(float_arr[i])
        _diff(xyz, xyz_arr[i])
        luv = husl.xyz_to_luv(xyz)
        _diff(luv, luv_arr[i])
        lch = husl.luv_to_lch(luv)
        _diff(lch, lch_arr[i])
예제 #12
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)