代码实现图像的批量光照增强
时间: 2023-08-20 15:07:16
浏览: 57
批量光照增强可以通过数据增强来实现。下面是一个使用Python和OpenCV库实现的示例[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083):
```python
import cv2
import os
# 设置光照增强的参数
gamma = 1.5
# 定义光照增强[函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)
def adjust_gamma([image](https://geek.csdn.net/educolumn/1defff92b42756fda40b623df99f03da?spm=1055.2569.3001.10083), gamma=1.0):
invGamma = 1.0 / gamma
table = []
for i in range(256):
table.append(((i / 255.0) ** invGamma) * 255)
table = np.array(table).[ast](https://geek.csdn.net/educolumn/1d2c256574d93ae646d4473629b198e6?spm=1055.2569.3001.10083)ype("uint8")
return cv2.LUT(image, table)
# 定义图像路径
image_path = 'your_image_folder_path'
# 遍历图像文件夹中的所有图像文件进行光照增强
for filename in os.listdir(image_path):
image = cv2.imread(os.path.join(image_path, filename))
# 对图像进行光照增强
image_gamma = adjust_gamma(image, gamma=gamma)
# 保存光照增强后的图像
cv2.imwrite(os.path.join(image_path, 'gamma_' + filename), image_gamma)
在这个示例[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083)中,我们首