简体   繁体   English

在python中绘制颜色直方图

[英]Plotting a color histogram in python

I have a jpeg image and want to plot a histogram of how frequently each color occurs in the image. 我有一个jpeg图像,想要绘制图像中每种颜色出现频率的直方图。 I am able to generate a frequency table using pymorph.histogram(), but I don't know the actual color that each of the 256 colors indices correspond to. 我能够使用pymorph.histogram()生成频率表,但我不知道每个256色指数对应的实际颜色。 How can I generate this palette? 如何生成此调色板?
Further, is there an way to just generate a histogram plot of all these numbers, with the colors indicated (not a number in the range 0-255, but the actual color displayed)? 此外,有没有办法只生成所有这些数字的直方图,并显示颜色(不是0-255范围内的数字,而是显示实际颜色)?

My frequency list is generated using this code: 我的频率列表是使用以下代码生成的:

import pymorph
import Image

im=Image.open('image.jpg')
im=np.asarray(im)
hist_im=pymorph.histogram(im)

Well, I'm not sure with pymorph, but if it's not producing what you expected, there's no harm trying alternatives and that's the wonder of python programming. 嗯,我不确定pymorph,但如果它没有产生你所期望的,那么尝试替代品就没有什么害处,这就是python编程的奇迹。

This is probably what you're looking for: http://tophattaylor.blogspot.de/2009/05/python-rgb-histogram.html 这可能是你正在寻找的: http//tophattaylor.blogspot.de/2009/05/python-rgb-histogram.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM