图像处理------亮度

python 复制代码
from PIL import Image

def change_brightness(img: Image, level: float) -> Image:
    """
    按照给定的亮度等级,改变图片的亮度
    """

    def brightness(c: int) -> float:
        return 128 + level + (c - 128)

    if not -255.0 <= level <= 255.0:
        raise ValueError("level must be between -255.0 (black) and 255.0 (white)")
    return img.point(brightness)


if __name__ == "__main__":
    # 加载图片
    with Image.open("image_data/test.jpg") as img:
        # 改变亮度到100
        brigt_img = change_brightness(img, 100)
        brigt_img.save("image_data/test_brightness.png", format="png")

图片亮度处理前:

图片亮度处理后:

【欢迎关注编码小哥,学习更多实用的编程方法】

相关推荐
happylifetree32 分钟前
Python09:核心语法-数据存储与运算-字面量
python
心之语歌41 分钟前
Tkinter 画布基本梳理
运维·服务器·python
Wx-bishekaifayuan1 小时前
django个性化旅游路线推荐平台49005-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
小燕子~~2 小时前
Photoshop2026新版 AI 功能实测,看这一篇就够了
图像处理·人工智能·ai·aigc·photoshop
小白快快跑哦2 小时前
python-字符串全解(六):正则表达式-量词
python·正则表达式·字符串
禹凕2 小时前
机器学习之Selenium(Machina Learning about Selenium)
爬虫·python·selenium·测试工具·机器学习
ebiobiz4 小时前
基于 GD32 Embedded Builder (GEB) 与 Nimmake 的 MCU 工程搭建指南
c++·python·单片机·嵌入式硬件·mcu
老歌老听老掉牙5 小时前
穿越时空的物流密码:VRP与VRPTW的深度剖析及实战求解
python·物流·vrp
FYKJ_20105 小时前
django电影推荐系统55066-计算机课程设计、毕业设计
vue.js·spring boot·python·mysql·typescript·spark·django
ShyanZh5 小时前
【Python3基础】13-Python 常用设计模式
开发语言·python·设计模式