深入理解Retinex图像增强算法的原理和实践方法
最编程
2024-01-13 07:41:46
...
import cv2
import numpy as np
# 对图像进行单尺度 Retinex 处理
def single_scale_retinex(img, sigma):
retinex = np.log10(img) - np.log10(cv2.GaussianBlur(img, (0, 0), sigma))
return retinex
# 对图像进行多尺度 Retinex 处理
def multi_scale_retinex(img, sigma_list):
retinex = np.zeros_like(img)
for sigma in sigma_list:
retinex += single_scale_retinex(img, sigma)
retinex = retinex / len(sigma_list)
return retinex
# 进行颜色恢复
def color_restoration(img, alpha, beta):
img_sum = np.sum(img, axis=2, keepdims=True)
color_restoration = beta * (np.log10(alpha * img) - np.log10(img_sum))
return color_restoration
# 图像增强主函数,包括图像增强和颜色恢复
def retinex_process(img, sigma_list, G, b, alpha, beta):
img = np.float64(img) + 1.0
img_retinex = multi_scale_retinex(img, sigma_list)
img_color = color_restoration(img, alpha, beta)
img_retinex = G * (img_retinex * img_color + b)
# 将像素值限制在范围内
for i in range(img_retinex.shape[2]):
img_retinex[:, :, i] = np.clip(img_retinex[:, :, i], 0, 255)
img_retinex = np.uint8(img_retinex)
return img_retinex
def main():
# 读取图像
img = cv2.imread('WechatIMG9.jpeg')
# 尺度列表
sigma_list = [15, 80, 250]
# 增益参数
G = 5.0
# 偏置参数
b = 25.0
# 颜色恢复参数
alpha = 125.0
# 颜色恢复参数
beta = 46.0
# 进行图像增强
img_retinex = retinex_process(img, sigma_list, G, b, alpha, beta)
# 显示原始图像
cv2.imshow('1', img)
# 显示增强后的图像
cv2.imshow('Retinex', img_retinex)
# 等待按键
cv2.waitKey(0)
# 保存增强后的图片
cv2.imwrite('a.jpg', img_retinex)
if __name__ == "__main__":
main()
上一篇: 16进制颜色表与RGB颜色对照表:HTML颜色完全指南
下一篇: 将16进制颜色转换为RGB
推荐阅读
-
深度学习中的不确定性量化:2020年实用技术与应用大解析 - 61页精华解读" 这份报告深入剖析了近年来深度学习领域中不确定性量化(UQ)技术的最新发展,包括其在强化学习(RL)中的运用实例。探讨了贝叶斯近似和集成学习等主流UQ方法在各个具体场景中的广泛应用,比如自动驾驶、目标识别、图像修复、医疗影像分析(如分类和分割)、文本理解(如文本分类和风险评估)、以及生物信息学等多个领域。 报告进一步梳理了UQ方法在深度学习领域的关键应用案例,并针对当前面临的挑战及未来研究方向进行了概览和展望,为这一领域的研究人员和实践者提供了有价值的参考指南。
-
深入理解PyTorch nn.Linear的使用方法和工作原理,以及全连接层的介绍与实践应用
-
深入理解Retinex图像增强算法的原理和实践方法