import cv2, math
import numpy as np
def AddHaze00(img):
img_f=img/255
(row,col,chs)=img.shape
A=0.6#亮度
beta=0.08#浓度
size=math.sqrt(max(row, col))#雾化尺寸
center=(row//2,col//2)#雾化中心
for j in range(row):
for l in range(col):
d=-0.04*math.sqrt((j-center[0])**2+(l-center[1])**2)+size
td=math.exp(-beta*d)
img_f[j][l][:]=img_f[j][l][:]*td+A*(1-td)
return img_f
def AddHaze01(img):
img_h=img/255
A=np.random.uniform(0.6,0.95)
t=np.random.uniform(0.3,0.95)
img_h=img_h*t+A*(1-t)
return img_h
img_path='C:/Users/xpp/Desktop/Lena.png'
img=cv2.imread(img_path)
cv2.imshow("original",img)
result00=AddHaze00(img)
result01=AddHaze01(img)
cv2.imshow("result00",result00)
cv2.imshow("result01",result01)
cv2.waitKey()
算法:图像加雾仿真是降低亮度、对比度、和分辨率来模拟雾中场景成像接近真实雾霾场景。
本文分享自 图像处理与模式识别研究所 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有