def lab_reduce_colors(colors, weights, threshold=30, return_rgb=True):
"""
Reduce colors by L*a*b* space.
"""
_colors = np.array([colors], dtype=np.uint8) # cv2.cvtColor only accept 2d array
lab_colors = cv2.cvtColor(_colors, cv2.COLOR_RGB2LAB)[0].astype(np.double)
inds = []
for i, color in enumerate(lab_colors):
dist = np.linalg.norm(hsv_colors_xyz[inds] - color, axis=1)
if not dist.size or dist.min() > threshold:
inds.append(i)
if return_rgb:
ret = colors[inds]
else:
ret = lab_colors[inds]
return ret
评论列表
文章目录