代码实现图像光照增强
时间: 2023-08-20 18:05:56
浏览: 108
图像光照增强是一种常见的图像处理技术,可以提高图像的亮度和对比度,使图像更加清晰、鲜明。下面是一份 Python [代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083)实现图像光照增强的示例:
```python
import cv2
import numpy as np
def adjust_gamma([image](https://geek.csdn.net/educolumn/1defff92b42756fda40b623df99f03da?spm=1055.2569.3001.10083), gamma=1.0):
# 将输入图像的像素值进行伽马变换,增强图像的亮度和对比度
invGamma = 1.0 / gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).[ast](https://geek.csdn.net/educolumn/1d2c256574d93ae646d4473629b198e6?spm=1055.2569.3001.10083)ype("uint8")
return cv2.LUT([image](https://geek.csdn.net/educolumn/1defff92b42756fda40b623df99f03da?spm=1055.2569.3001.10083), table)
def histeq(image):
# 对输入图像进行直方图均衡化,增强图像的对比度
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
equ = cv2.equalizeHist(gray)
return cv2.merge((equ,equ,equ))
def en[han](https://geek.csdn.net/educolumn/0d22b54eaf6bcf967d9625e1679d00b4?spm=1055.2569.3001.10083)ce_image(image, gamma=1.0):
# 将输入图像进行光照增强
image = adjust_gamma(image, gamma=gamma)
image = histeq(image)
return image
# 加载图像
image = cv2.im
```