我找到了这段代码:
import PIL
from PIL import Image
from matplotlib import pyplot as plt
im = Image.open('./color_gradient.png')
w, h = im.size
colors = im.getcolors(w*h)
def hexencode(rgb):
r=rgb[0]
g=rgb[1]
b=rgb[2]
return '#%02x%02x%02x' % (r,g,b)
for idx, c in enumerate(colors):
plt.bar(idx, c[0], color=hexencode(c[1]),edgecolor=hexencode(c[1]))
plot.show()
对于确切的链接,可以在此处查看 - Plot image color histogram using matplotlib
我的问题是轴的含义是什么,我如何生成这些值的表?我想运行一些统计数据,比如图片中绿色或红色的百分比......
由于
答案 0 :(得分:1)
<强> getcolors 强>
im.getcolors()=&gt; (计数,颜色)元组列表或无
im.getcolors(maxcolors)=&gt; (计数,颜色)元组列表或无
参考图中的Y轴是该颜色的像素数,X轴包含图中的(未分类?)颜色列表。