def test_rgb_to_lch_chain(): rgb_arr = _img()[:, 0] xyz_arr = nphusl.rgb_to_xyz(rgb_arr) luv_arr = nphusl.xyz_to_luv(xyz_arr) lch_arr = nphusl.luv_to_lch(luv_arr) lch_arr2 = nphusl.rgb_to_lch(rgb_arr) assert np.all(lch_arr == lch_arr2)
def test_rgb_to_lch_3d(): rgb_arr = _img() lch_arr = nphusl.rgb_to_lch(rgb_arr) for row in range(lch_arr.shape[0]): for col in range(lch_arr.shape[1]): old_lch = husl.rgb_to_lch(*rgb_arr[row, col]) assert _diff(lch_arr[row, col], old_lch)
def test_lch_to_luv(): img = _img() lch = nphusl.rgb_to_lch(img) luv = nphusl.lch_to_luv(lch) # we're testing this xyz = nphusl.rgb_to_xyz(img) luv_2 = nphusl.xyz_to_luv(xyz) lch_2 = nphusl.luv_to_lch(luv_2) assert _diff(lch_2, lch) # just a sanity check on RGB -> LCH assert _diff(luv, luv_2)
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)
def test_max_lh_for_chroma(): rgb_arr = _img()[:, 0] lch_arr = nphusl.rgb_to_lch(rgb_arr) with np.errstate(invalid="ignore"): mx_arr = nphusl._max_lh_chroma(lch_arr) arrays = zip(mx_arr, lch_arr, rgb_arr) for mx, lch, rgb in arrays: try: mx_old = husl.max_chroma_for_LH(float(lch[0]), float(lch[2])) except ZeroDivisionError: # NOTE: Divide by zero is avoided in nphusl.py # we're taking a backdoor here by using max_chroma_for_LH directly assert np.isinf(mx) else: assert _diff(mx, mx_old)
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])
def test_husl_to_lch(): img = _img() lch = nphusl.rgb_to_lch(img) husl = nphusl.rgb_to_husl(img) lch_2 = nphusl.husl_to_lch(husl) assert _diff(lch, lch_2)
def test_lch_to_rgb(): img = _img() lch = nphusl.rgb_to_lch(img) rgb = nphusl.lch_to_rgb(lch) assert _diff(rgb, img)
def test_rgb_to_lch(): rgb_arr = _img()[:, 0] lch_arr = nphusl.rgb_to_lch(rgb_arr) for lch, rgb in zip(lch_arr, rgb_arr): diff = lch - husl.rgb_to_lch(*rgb) assert _diff(lch, husl.rgb_to_lch(*rgb))