f01–f05
Structure and local variation
Mean-subtracted contrast-normalized (MSCN) variance, variances of nonnegative and nonpositive vertical MSCN products, mean local standard deviation and mean coefficient of variation.
PAPER IMPLEMENTATION / PYTHON
This is a fog density evaluation tool I implemented in Python based on the FADE paper. It needs no paired fog-free image: a single RGB image is enough to compute a FADE score and a local fog density map.
The paper proposes FADE (Fog Aware Density Evaluator) to estimate perceptual fog density from a single image using natural scene statistics, without a paired fog-free image.
It also uses FADE to guide the DEFADE defogging method. This project implements the fog density evaluation part, producing a whole-image score and local heatmap.
Referenceless Prediction of Perceptual Fog Density and Perceptual Image DefoggingLark Kwon Choi, Jaehee You, Alan Conrad Bovik
IEEE Transactions on Image Processing, 24(11), 3888–3901, November 2015.
01 / FADE
Each image produces two results: a numeric FADE score reflecting fog density across the whole image, and a heatmap showing local fog density. Choose an example to compare the original image with its grayscale heatmap.
Higher FADE scores indicate denser fog.
The mountain scene has the lowest whole-image FADE score of these three examples.

576 × 768 px

Density map grid: 72 × 96 patches · Patches with no valid result: 2
The city street has a higher whole-image FADE score than the mountain scene.

600 × 800 px

Density map grid: 75 × 100 patches · Patches with no valid result: 7
The lake scene has the highest whole-image FADE score of these three examples.

800 × 531 px

Density map grid: 100 × 66 patches · Patches with no valid result: 0
Shared local density scale
No valid result (NaN)
These examples show three different scenes, not different fog levels added to the same photograph.
Each map cell represents an 8×8-pixel image patch. All three maps share one grayscale scale, from zero to the highest finite local value across the examples. Incomplete patches at the bottom and right edges are omitted.
The whole-image score is computed from the aggregated reference distances; it is not the average of the local map, a percentage, or a physical measurement of fog concentration.
Example images: fade_py / test_image ↗02 / FADE
FADE compares perceptual features with statistical reference models of fog-free and foggy natural images. A paired clear image is not required, while the reference statistics are loaded from the package’s precomputed .mat files.
Fog changes local contrast, texture, brightness and color. FADE measures these changes through 12 features. The flow below describes the current Python implementation, including its patch processing and distance aggregation.
f01–f05
Mean-subtracted contrast-normalized (MSCN) variance, variances of nonnegative and nonpositive vertical MSCN products, mean local standard deviation and mean coefficient of variation.
f06–f09
Mean contrast energy in the gray, yellow–blue and red–green channels, plus grayscale patch entropy.
f10–f12
Mean pixel-wise dark-channel intensity, mean saturation and colorfulness.
Crop the RGB image to multiples of 8, retaining its upper-left region. Prepare grayscale, color channels, MSCN and contrast energy through a shared context.
Compute f01–f12 for non-overlapping 8×8 patches. Each feature produces a grid with H//8 rows and W//8 columns.
Flatten the feature grids in row-major order and join them into an N×12 matrix. Apply the natural-log transform log1p to each value.
Calculate a sample variance across the 12 transformed components of each patch. This scalar supplies the current implementation’s covariance proxy.
Read the 12-dimensional mean and 12×12 covariance for the fog-free and foggy classes. These parameters are cached; inference does not fit new reference models.
Compute Mahalanobis-like distances by mixing the variance proxy with each reference covariance and solving linear systems in batches. Each patch yields a distance to the fog-free model and one to the foggy model.
Take nanmean of the distances to each class separately, ignoring each group’s NaN values. Divide the mean distance to the fog-free model by the sum of the mean distance to the foggy model and 1.
For each patch, divide its distance to the fog-free model by the sum of its distance to the foggy model and 1, then place the results back into the patch grid.
Df is the mean distance to the fog-free reference; Dff is the mean distance to the foggy reference. d_free(b) and d_foggy(b) are the corresponding distances for patch b.
The whole-image score is a ratio of two distance means, so it generally differs from the mean of the local heatmap. Local values are not normalized to [0,1]; the grayscale scale above is only for display.
03 / PYTHON
The FADE algorithm comes from the paper. My work is its Python implementation and engineering improvements in fade_py.
I implemented the feature extraction and scoring pipeline with NumPy and SciPy, exposing fade() for a score and fade_with_map() for a score and map.
I separated the perceptual features, numerical operations, reference data and pipeline, making the implementation easier to inspect and maintain.
I vectorized patch entropy and distance calculations, reused intermediate results and cached reference statistics. Batching bounds temporary working memory.