-
Notifications
You must be signed in to change notification settings - Fork 0
/
removeHaze.py
30 lines (26 loc) · 1.1 KB
/
removeHaze.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import cv2
import numpy as np
import copy
def removeHaze(HazeImg, Transmission, A, delta):
'''
:param HazeImg: Hazy input image
:param Transmission: estimated transmission
:param A: estimated airlight
:param delta: fineTuning parameter for dehazing --> default = 0.85
:return: result --> Dehazed image
'''
# This function will implement equation(3) in the paper
# " https://www.cv-foundation.org/openaccess/content_iccv_2013/papers/Meng_Efficient_Image_Dehazing_2013_ICCV_paper.pdf "
epsilon = 0.0001
Transmission = pow(np.maximum(abs(Transmission), epsilon), delta)
HazeCorrectedImage = copy.deepcopy(HazeImg)
if(len(HazeImg.shape) == 3):
for ch in range(len(HazeImg.shape)):
temp = ((HazeImg[:, :, ch].astype(float) - A[ch]) / Transmission) + A[ch]
temp = np.maximum(np.minimum(temp, 255), 0)
HazeCorrectedImage[:, :, ch] = temp
else:
temp = ((HazeImg.astype(float) - A[0]) / Transmission) + A[0]
temp = np.maximum(np.minimum(temp, 255), 0)
HazeCorrectedImage = temp
return(HazeCorrectedImage)