0
点赞
收藏
分享

微信扫一扫

基于单幅图像的快速去雾


开源地址:​​https://github.com/BBuf/Image-processing-algorithm​​

前言

这是OpenCV图像处理算法朴素实现用于单幅图像去雾的算法,作者来自清华大学。

算法流程

基于单幅图像的快速去雾_计算机视觉


python实现:C++实现请查看开源地址源码,或者​​【点击】​​

import cv2
import numpy as np


def single_image_defogging(img):
height,width = img.shape[:2]
img_min = np.min(img,axis=2)
img_max = np.max(img,axis=2)
img_min_sum = np.sum(img_min)
ave = img_min_sum/(height*width*255)
eps = 0.85 / ave
delta = min(0.9, eps * ave)

img_ave = cv2.boxFilter(img_min, -1, (51, 51))
img_L = np.minimum((img_ave*delta).astype(np.uint8),img_min)
A = np.max(img_max) + np.max(img_ave) * 0.5

temp = np.zeros((height,width,3),dtype=np.uint8)
temp[:,:,0] = np.subtract(img[:,:,0], img_L)
temp[:,:,1] = np.subtract(img[:,:,1], img_L)
temp[:,:,2] = np.subtract(img[:,:,2], img_L)
temp_AL = np.subtract(A, img_L)
temp_3AL = temp_AL[:, :,np.newaxis].repeat(3, axis=2)


img_dst = np.divide(np.multiply(A,temp),temp_3AL).astype(np.uint8)
img_dst = np.where(img_dst > 255, 255, img_dst)
img_dst = np.where(img_dst < 0, 0, img_dst)
return img_dst


if __name__ == '__main__':
img = cv2.imread("./fog.jpg")
result_img = single_image_defogging(img)
cv2.imwrite("./fog22.jpeg", result_img)
cv2.imshow("result_img",result_img)
cv2.waitKey(0)
cv2.destroyAllWindows()

显示效果还行。如下:(去雾之后图像变暗了,需要进行gamma校正)

基于单幅图像的快速去雾_计算机视觉_02


举报

相关推荐

PS快速去水印

0 条评论