[英]Analysis of images using PIL in Python
我发现以下代码:
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()
有关确切的链接,请看这里- 使用matplotlib绘制图像颜色直方图
我的问题是轴的含义是什么,如何生成这些值的表格? 我想进行一些统计,例如图片中绿色或红色的百分比...
谢谢
从PIL文档中 :
getcolors
im.getcolors()=>(计数,颜色)元组的列表或无
im.getcolors(maxcolors)=>(数量,颜色)元组的列表或无
所引用图形中的Y轴是该颜色的像素数,而X轴包括图形中的(未排序?)颜色列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.