Every time I look up a question that displays example code on here or Git I usually see the letter L listed in the explanation. For example the code below for finding the average brightness of an image. (I'm trying to find average brightness of a set of images in a user-specified directory and this is where I was starting.)
I have tried to research it however every time I look it up it comes up with seemingly irrelevant explanations. I want to state that the code I'm showing is NOT MINE and I will link the original user below
import sys
from PIL import Image
def calculate_brightness(image):
greyscale_image = image.convert('L') # THIS IS THE 'L'
histogram = greyscale_image.histogram()
pixels = sum(histogram)
brightness = scale = len(histogram)
for index in range(0, scale):
ratio = histogram[index] / pixels
brightness += ratio * (-scale + index)
return 1 if brightness == 255 else brightness / scale
if __name__ == '__main__':
for file in sys.argv[1:]:
image = Image.open(file)
print("%s\t%s" % (file, calculate_brightness(image)))
The link for the original user and their code is: https://gist.github.com/kmohrf/8d4653536aaa88965a69a06b81bcb022