简体   繁体   中英

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. 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. 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)?

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.

This is probably what you're looking for: http://tophattaylor.blogspot.de/2009/05/python-rgb-histogram.html

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.

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