将低照度图像分别从hsi方向进行图像增强,其中亮度方向采用MSRCR算法增强的代码
时间: 2023-07-16 17:16:03 浏览: 116
以下是使用MSRCR算法对低照度图像进行亮度增强的Python代码:
```python
import cv2
import numpy as np
def gamma_correction(img, gamma=1.0):
"""
Gamma校正函数
:param img: 待处理图像
:param gamma: Gamma值
:return: Gamma校正后的图像
"""
inv_gamma = 1.0 / gamma
table = np.array([((i / 255.0) ** inv_gamma) * 255
for i in np.arange(0, 256)]).astype("uint8")
return cv2.LUT(img, table)
def HSI_enhancement(img, sigma_list=[15, 80, 250], gain=3, offset=10):
"""
HSI图像增强函数
:param img: 待处理图像
:param sigma_list: 高斯核尺度列表
:param gain: 增益
:param offset: 偏移
:return: 增强后的图像
"""
# 将图像转换为HSI空间
img_hsi = cv2.cvtColor(img, cv2.COLOR_BGR2HSV_FULL)
intensity = img_hsi[:, :, 2]
# 对亮度分量进行MSRCR算法增强
intensity_log = np.log(intensity.astype(np.float64) + 1.0)
intensity_log_mean = cv2.GaussianBlur(intensity_log, (0, 0), sigma_list[0])
intensity_log_sub = intensity_log - intensity_log_mean
intensity_log_var = cv2.GaussianBlur(intensity_log_sub ** 2, (0, 0), sigma_list[1])
intensity_log_std = np.sqrt(intensity_log_var)
intensity_log_norm = intensity_log_sub / intensity_log_std
intensity_log_enh = cv2.GaussianBlur(gain * intensity_log_norm + offset, (0, 0), sigma_list[2])
intensity_enh = np.exp(intensity_log_enh) - 1.0
# 将增强后的亮度分量替换原来的亮度分量
img_hsi[:, :, 2] = np.clip(intensity_enh, 0, 255).astype(np.uint8)
# 将图像转回BGR空间
img_enh = cv2.cvtColor(img_hsi, cv2.COLOR_HSV2BGR_FULL)
return img_enh
# 加载低照度图像
img = cv2.imread('low_light_image.jpg')
# 对亮度分量进行MSRCR算法增强
img_enhanced = HSI_enhancement(img)
# 显示增强后的图像
cv2.imshow('Enhanced Image', img_enhanced)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
其中,`gamma_correction`函数是Gamma校正函数,用于对增强后的亮度分量进行Gamma校正;`HSI_enhancement`函数是HSI图像增强函数,用于对低照度图像进行亮度增强。在`HSI_enhancement`函数中,首先将图像转换为HSI空间,然后对亮度分量进行MSRCR算法增强,最后将增强后的亮度分量替换原来的亮度分量,再将图像转回BGR空间。`sigma_list`参数是高斯核尺度列表,`gain`和`offset`参数是MSRCR算法的增益和偏移参数,可以根据具体情况进行调整。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)