[Numpy-discussion] Fast histogram
Thu Apr 17 12:00:42 CDT 2008
On Thu, Apr 17, 2008 at 6:54 PM, Zachary Pincus <firstname.lastname@example.org> wrote:
> Hi, and thanks for the suggestion!
> > How many bits per pixel does your camera actually generate !?
> > If its for example a 12 bit camera, you could just fill in directly
> > into 4096 preallocated bins.
> > You would not need any sorting !!
> > That's what I did for a 16 bit camera -- but I wrote it in C and I had
> > 4 cameras at 30 Hz.
> That approach avoids the bin-index calculation line:
> indices = numpy.clip(((array.astype(float) - min) * bins / (max -
> min)).astype(int), 0, bins-1)
> But even if indices = array, one still needs to do something like:
> for index in indices: histogram[index] += 1
> Which is slow in python and fast in C.
> I'm guessing that there's no utility function in numpy that does a
> loop like this? If so, that would be handy, but if now, I think I need
> to dig out the numpy book and write a little extension...
I thought of a broadcasting approach... what are the chances that a simple
bins[:] = 0
bins[ img.flat ] += 1
works !? Or something along those lines ....
More information about the Numpy-discussion