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

Andrew Straw strawman at astraw.com
Mon Feb 20 11:59:02 CST 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' )
pylab.show()

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 :-)
>
>cheers
>curzio
>
>
>-------------------------------------------------------
>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!
>http://sel.as-us.falkag.net/sel?cmd=k&kid3432&bid#0486&dat1642
>_______________________________________________
>Numpy-discussion mailing list
>Numpy-discussion at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>  
>





More information about the Numpy-discussion mailing list