Image Dehazing
Module: Computer Vision | Difficulty: Intermediate
Atmospheric Scattering Model
where is scene radiance, is transmission, is atmospheric light.
Dark Channel Prior
Transmission Map
Scene Radiance Recovery
import cv2
import numpy as np
def dark_channel(img, size=15):
b, g, r = cv2.split(img)
dc = cv2.min(cv2.min(r, g), b)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (size, size))
return cv2.erode(dc, kernel)
def atmospheric_light(img, dark_ch):
_, _, _, top_left = cv2.minMaxLoc(dark_ch)
return img[top_left[1], top_left[0]]
def transmission_map(img, A, size=15, omega=0.95):
return 1 - omega * dark_channel(img / A, size)
def dehaze(img, A, t, t_min=0.1):
t = np.clip(t, t_min, 1)
return np.clip((img - A) / t + A, 0, 255).astype(np.uint8)
Key Takeaways
- Dark channel prior is effective for natural outdoor haze
- Transmission map estimation is key to dehazing quality
- Deep methods learn end-to-end dehazing without priors