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

Time:06-10

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?

example:

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?

CodePudding user response:

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.

  • Related