我想知道基于 9 RGB 颜色范围的最接近或最接近的 RGB 值
我知道有类似的问题。 查找图像中每个像素最接近的 RGB 颜色
但是我的是我想知道基于颜色的范围。
#the brighter values of colors
low_color = [(0, 0, 0), #black
(0, 90, 10), #brown
(255, 0, 0), #red
(211, 104, 62), #orange
(255, 255, 0), #yellow
(0, 255, 0), #green
(0, 0, 255), #blue
(200, 0, 255), #violet
(128, 128, 128), #gray
(255, 255, 255)] #white
#the darker values of colors
high_color = [(179, 255, 93), #black
(15, 250, 100), #brown
(204, 0, 0), #red
(199, 90, 57), #orange
(255, 204, 102), #yellow
(6, 85, 28), #green
(40, 73, 86), #blue
(110, 0, 51), #violet
(73, 65, 62), #gray
(250, 250, 250)] #white
我如何仅使用 rgb 值检查这些范围(c[0],c[1])的颜色基础。 我想知道颜色最匹配的索引。
前任。如果寻找的颜色是 rgb=(93, 30, 38) 它应该选择第二个索引(棕色)
def findNearest(rgb):
dist = ((low_color[0][0]-rgb[0])*0.3)**2 + ((low_color[0][1]-rgb[1])*0.59)**2 + ((low_color[0][2]-rgb[2])*0.11)**2
index = 0
for i in range(1,len(high_color)):
d = ((low_color[i][0]-rgb[0])*0.3)**2 + ((low_color[i][1]-rgb[1])*0.59)**2 + ((low_color[i][2]-rgb[2])*0.11)**2
if d < dist:
dist = d
index = i
return low_color[index]
i know there are similar question like this one. Find closest RGB color for every pixel in image
But mine is i want to know base on the range of the color.
#the brighter values of colors
low_color = [(0, 0, 0), #black
(0, 90, 10), #brown
(255, 0, 0), #red
(211, 104, 62), #orange
(255, 255, 0), #yellow
(0, 255, 0), #green
(0, 0, 255), #blue
(200, 0, 255), #violet
(128, 128, 128), #gray
(255, 255, 255)] #white
#the darker values of colors
high_color = [(179, 255, 93), #black
(15, 250, 100), #brown
(204, 0, 0), #red
(199, 90, 57), #orange
(255, 204, 102), #yellow
(6, 85, 28), #green
(40, 73, 86), #blue
(110, 0, 51), #violet
(73, 65, 62), #gray
(250, 250, 250)] #white
how would i check the color base on these ranges(c[0],c[1]) using rgbvalues only.
I would like to know the index where the color is best matched of.
ex. if the sought out color is rgb=(93, 30, 38) it should select the 2nd index(brown)
def findNearest(rgb):
dist = ((low_color[0][0]-rgb[0])*0.3)**2 + ((low_color[0][1]-rgb[1])*0.59)**2 + ((low_color[0][2]-rgb[2])*0.11)**2
index = 0
for i in range(1,len(high_color)):
d = ((low_color[i][0]-rgb[0])*0.3)**2 + ((low_color[i][1]-rgb[1])*0.59)**2 + ((low_color[i][2]-rgb[2])*0.11)**2
if d < dist:
dist = d
index = i
return low_color[index]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论