基于gamma矫正的照片亮度调整(python和opencv实现)

python 复制代码
import cv2
import numpy as np

def adjust_gamma(image, gamma=1.0):
    invGamma = 1.0 / gamma
    table = np.array(
        [((i / 255.0) ** invGamma) * 255 for i in np.arange(0, 256)]
    ).astype("uint8")
    return cv2.LUT(image, table)

# 读取图像
original = cv2.imread("test.png", 1)

# gamma矫正
gamma = 1.8 # 矫正系数:越大越亮、越小越暗
adjusted = adjust_gamma(original, gamma=gamma)
cv2.imwrite("result.jpg", adjusted)

矫正前后效果如下:

相关推荐
ZZHow10241 小时前
02OpenCV基本操作
python·opencv·计算机视觉
计算机学长felix1 小时前
基于Django的“酒店推荐系统”设计与开发(源码+数据库+文档+PPT)
数据库·python·mysql·django·vue
站大爷IP1 小时前
Python随机数函数全解析:5个核心工具的实战指南
python
悟乙己1 小时前
使用 Python 中的强化学习最大化简单 RAG 性能
开发语言·python·agent·rag·n8n
max5006001 小时前
图像处理:实现多图点重叠效果
开发语言·图像处理·人工智能·python·深度学习·音视频
AI原吾1 小时前
玩转物联网只需十行代码,可它为何悄悄停止维护
python·物联网·hbmqtt
云动雨颤2 小时前
Python单元测试入门:3个核心断言方法,帮你快速定位代码bug
python·单元测试
SunnyDays10112 小时前
Python 实现 HTML 转 Word 和 PDF
python·html转word·html转pdf·html转docx·html转doc
跟橙姐学代码3 小时前
Python异常处理:告别程序崩溃,让代码更优雅!
前端·python·ipython
AI 嗯啦3 小时前
计算机视觉opencv----银行卡号码识别
人工智能·opencv·计算机视觉