[英]Analysis of images using PIL in Python
I found this code: 我发现以下代码:
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()
For the exact link one can look here- Plot image color histogram using matplotlib 有关确切的链接,请看这里- 使用matplotlib绘制图像颜色直方图
My questions are what are the meaning of the axes, and how can I generate a table out these values? 我的问题是轴的含义是什么,如何生成这些值的表格? I would like to run some statistics, like percent of green, or red in the picture...
我想进行一些统计,例如图片中绿色或红色的百分比...
Thanks 谢谢
From the PIL Documentation : 从PIL文档中 :
getcolors
getcolors
im.getcolors() => a list of (count, color) tuples or None
im.getcolors()=>(计数,颜色)元组的列表或无
im.getcolors(maxcolors) => a list of (count, color) tuples or None
im.getcolors(maxcolors)=>(数量,颜色)元组的列表或无
The Y axis in the referred graph is the pixel count of that colour and the X axis comprises the (unsorted?) list of colours in the graph. 所引用图形中的Y轴是该颜色的像素数,而X轴包括图形中的(未排序?)颜色列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.