[SciPy-User] numpy.histogram is slow

Chris Weisiger cweisiger@msg.ucsf....
Tue Oct 16 15:04:24 CDT 2012

My use case is displaying camera image data to the user as it is
streamed to us; this includes a histogram showing the distribution of
intensities in the image. Thus I have a 512x512 array of pixel data
(unsigned 16-bit ints) that I need to generate a histogram for.
Unfortunately, numpy.histogram takes a significant amount of time --
about 15ms per call. That's over 60% of the cost of showing an image
to the user, which means that I can't quite display data as quickly as
it comes in. So I'm looking for some faster option.

My searches turned up numpy.bincount, which is nice and zippy, but
unfortunately omits bins where the total count is 0. This makes sense
considering that otherwise it would always generate a length-N array
where N is the maximum value in the input, but it doesn't work for my
purposes. Are there any better options?


More information about the SciPy-User mailing list