Skip to content
Advertisement

how to generate per-pixel histogram from many images in numpy?

I have tens of thousands of images. I want to generate a histogram for each pixel. I have come up with the following code using NumPy to do this that works:

JavaScript

histogram for a single pixel

I would like to know if anyone can help me vectorize the for loops? I can’t think of how to index into the perpix_hist array properly. I have tens/hundreds of thousands of images and each image is ~1500×1500 pixels, and this is too slow.

Advertisement

Answer

You can vectorize it using np.meshgrid and providing indices for first, second and third dimension (the last dimension you already have).

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement