[Numpy-discussion] [nd_image] histograms of RGB images

Andrew Straw strawman at astraw.com
Mon Feb 20 11:59:02 EST 2006

See this example. You don't really need pylab/matplotlib -- you could
just use numpy.histogram.

import pylab
import matplotlib.numerix as nx
import Image

im = Image.open('data/lena.jpg')
imbuf = im.tostring('raw','RGB',0,-1)
imnx = nx.fromstring(imbuf,nx.UInt8)
imnx.shape = im.size[1], im.size[0], 3

bins = nx.arange(0,256)
pylab.hist( nx.ravel(imnx[:,:,0]), bins=bins, facecolor='r', edgecolor='r' )
pylab.hist( nx.ravel(imnx[:,:,1]), bins=bins, facecolor='g', edgecolor='g' )
pylab.hist( nx.ravel(imnx[:,:,2]), bins=bins, facecolor='b', edgecolor='b' )

Curzio Basso wrote:

>Hello everybody!
>I was wondering if someone already had the problem of computing
>histograms of RGB images for all channels simultaneously (that is
>getting a rank-3 array) rather than on the three channels separately.
>Just looking for a way to avoid writing the C function :-)
>This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
>for problems?  Stop!  Download the new AJAX search engine that makes
>searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
>Numpy-discussion mailing list
>Numpy-discussion at lists.sourceforge.net

More information about the NumPy-Discussion mailing list