calculation.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:backlight-indicator 作者: atareao 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号