import scipy.spatial as sp
input_color = (100, 50, 25)
websafe_colors = [(200, 100, 50), ...] # list of web-save colors
tree = sp.KDTree(websafe_colors) # creating k-d tree from web-save colors
ditsance, result = tree.query(input_color) # get Euclidean distance and index of web-save color in tree/list
nearest_color = websafe_colors[result]
或为多个
input_color
添加循环关于k-dimensional tree
尽管用词不当,web安全调色板确实对颜色量化非常有用。它简单、快速、灵活且无处不在。它还允许RGB十六进制速记,例如}。以下是演练:
#369
,而不是{00, 33, 66, 99, CC, FF
。因此,我们可以将最大RGB值255
除以5(比总可能值小1)得到一个倍数值51
。在255
来规范化通道值(这使其成为来自0-1
的值,而不是{5
,并对结果进行四舍五入以确保它保持精确。在乘以
51
得到最终的web安全值。总而言之,这看起来像:没有必要像其他人建议的那样疯狂地比较颜色或创建巨大的查找表。:-)
相关问题 更多 >
编程相关推荐