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?
sum
function here as being equal to the width*height of the image. Right now, @YvesDaoust's answer is making the most sense. A bin is incremented for each pixel in the image, so it would only follow that the sum of all bins is equal to the total number of pixels.