[Numpy-discussion] index into a 3d histogram

Chris Colbert sccolbert@gmail....
Sun May 3 18:55:22 CDT 2009

solved my own question:

for future googlers:

newarray = histogram[img[:, :, 0], img[:, :, 1], img[:, :, 2])

where histogram is the 3d histogram and img is the 3d img of (r, g, b)
histogram localization bins.

This version is also 300x faster than nested for loops.

On Sun, May 3, 2009 at 7:34 PM, Chris Colbert <sccolbert@gmail.com> wrote:

> Lets say I have histogram of a color image that is of size [16, 16, 16].
> Now, I have a function that converts my rgb image into the format where
> each rgb color (i.e. img[x, y, :] = (r, g, b)) is an integer in the range(0,
> 16)
> I want create a new 2d array where new2darray[x, y] = hist[img[x,y, :]]
> that is, for each 3 tuple in img, use that as an index into the 3d
> histogram and store the value of the histogram into the (x,y) position of
> the 2d array.
> I've prototyped all the algorithms using for loops, now im just trying to
> speed it up.
> I can't quite wrap my head fully around this fancy indexing yet.
> Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090503/93223b70/attachment.html 

More information about the Numpy-discussion mailing list