Image Dehazing with Dark Channel Prior, from Scratch
Single-image dehazing with the Dark Channel Prior, written in NumPy alone with no OpenCV, SciPy or scikit-image, compared against a CLAHE baseline, with an analysis of where the method fails.
- Year
- 2026
- Kind
- Computer Vision
- Role
- Developer
- Duration
- Final project, Computer Vision course
- With
- Individual
- For
- Academic project, Computer Vision course
- Problem
- Haze removal means estimating two unknowns, the transmission map and the atmospheric light, from a single image.
- Approach
- A from-scratch implementation of the dark channel, atmospheric light estimation, transmission estimation and a guided filter built on integral images, validated on synthetic haze with ground truth and on real hazy photographs.
- Result
- On synthetic haze, Dark Channel Prior beat the CLAHE baseline on both PSNR and SSIM across the range of haze intensities tested. On real photographs it restored a city scene and produced artefacts in a scene with a large sky.
Built with
- Python
- NumPy
- Jupyter Notebook
- Matplotlib
The haze equation
A hazy image is modelled as I(x) = J(x) t(x) + A (1 - t(x)): the scene J attenuated by the transmission t, plus atmospheric light A. Dehazing inverts that equation, which means estimating t and A from the hazy image alone.
The Dark Channel Prior is an observation about haze-free outdoor images: in almost every local patch, at least one pixel is very dark in at least one colour channel. Haze breaks that rule in a systematic way, and the amount by which it is broken tells you how thick the haze is.
Dark channel and guided filter in NumPy
Everything is written in NumPy, with no OpenCV, SciPy or scikit-image: the dark channel, the estimate of atmospheric light, the transmission map, and a guided filter to refine it. The guided filter uses a box mean computed from an integral image, so its cost does not grow with the filter radius.
The method is tested two ways. Synthetic haze is added to a clear image, so PSNR and SSIM can be measured against the ground truth. Real hazy photographs have no ground truth, so mean gradient is used as an indication of recovered detail. Contrast-limited adaptive histogram equalisation (CLAHE) is the baseline.
Against CLAHE
On synthetic haze, the Dark Channel Prior improved on CLAHE in both PSNR and SSIM, and stayed ahead across haze intensities from 0.8 to 2.5. A patch size of about 15 worked best: smaller patches gave noisy estimates and larger ones produced halos around objects.
On real photographs the picture is mixed. A city scene recovered its detail with few artefacts. A field with a large sky did not: bright sky violates the prior, and the result shows it.
Limits
- Sky and large white objects break the prior and produce artefacts.
- Patch size, omega, the transmission floor and the guided filter's radius are set by hand and matter a great deal.
- Mean gradient is only an indication: an artefact can raise it without improving the image.
- The synthetic haze uses a simple vertical depth model, which real haze does not follow.