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
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 :
getcolors
im.getcolors() => a list of (count, color) tuples or None
im.getcolors(maxcolors) => a list of (count, color) tuples or None
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.