def calculate_brightness_for_image(image):
pix = image.load()
width, height = image.size
width = float(width)
height = float(height)
data = []
for y in range(0, int(height)):
for x in range(0, int(width)):
if (y < (1.0 - BODY_H - HEAD_H) * height) or\
(y > (1.0 - BODY_H - HEAD_H) * height and
y < (1.0 - HEAD_H) * height and
(x < (1.0 - HEAD_W) / 2.0 * width or
x > (1.0 + HEAD_W) / 2.0)) or\
(y > (1.0 - BODY_H) * height and
(x < (1.0 - BODY_W) / 2.0 * width or
x > (1.0 + BODY_W) / 2.0 * width)):
r, g, b = pix[x, y]
brightness = int(calculate_brightness_for_pixel(
r, g, b) / 255.0 * 100.0)
data.append(ponderate(brightness))
return int(statistics.mean(data))
评论列表
文章目录