Is the sum of an images histogram not just the area of the image?


I’ve seen a few times in scientific papers people referring to the sum of an image’s histogram, and then in the reference source code they’re using the python sum() function over an openCV’s calcHistogram output. Surely this just equal to the area of the image and it’s probably more computationally efficient just to multiply the image width and height?


def clip_histogram_(self, hists, threshold = 10.0):
        all_sum = sum(hists)
        threshold_value = all_sum / len(hists) * threshold

Where the histogram here is just an array of length 255 with the index representing the color and the representing integer being the frequency of that color.

Unless Python does some magic with their sum function, this can’t be an efficient way of doing things?


If the variable hists indeed contains the histogram of an image, you are quite right, the bins sum to the image size.

It appears that the function does not receive the image, so this is an alternative way to get that size.

Though it may seem a waste to perform this inefficient operation, its cost is usually neglectable compared to the time to compute the histogram itself.

Answered By – Yves Daoust

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published