Theory
The histogram of an 8-bit grayscale image counts how many pixels hold each intensity: h(k) for k = 0 to 255. Dividing by the number of pixels N gives the normalized histogram p(k) = h(k) / N, an estimate of the probability of each gray level.
A histogram says nothing about where pixels are, but it describes exposure and contrast at a glance. Values bunched at the left mean an underexposed image, bunched at the right an overexposed one, and a narrow spread means low contrast. Mean, standard deviation, minimum and maximum can all be computed from the histogram alone.
Contrast stretching
A linear stretch maps the darkest value present to 0 and the brightest to 255:
s = (r − r_min) / (r_max − r_min) × 255
It cannot help when a few outlier pixels already reach both ends, which is why percentile-based stretching is often preferred.
Histogram equalization
Equalization remaps intensities so the output histogram is as flat as possible, using the cumulative distribution function
CDF(k) = Σ p(j) for j = 0 to k, and s_k = round(255 × CDF(k)).
Frequent intensities get spread apart and rare ones get compressed, which raises global contrast automatically. It can also amplify noise and wash out regions that were already well exposed.
CLAHE
Contrast Limited Adaptive Histogram Equalization divides the image into tiles and equalizes each one separately. Before equalizing, each tile's histogram is clipped at a limit and the excess is redistributed, which caps how much noise can be amplified. Tiles are blended with bilinear interpolation to hide their borders.
For color images, equalize only a brightness channel (Y of YCrCb, L of LAB or V of HSV). Equalizing R, G and B separately shifts the colors.
Workbench
Compare histograms before and after each enhancement on the same image.
Input
Input preview
Parameters
Readout
- n/a
- n/a
Export
Procedure
- Load the Underexposed sample and plot its grayscale histogram and CDF. Record min, max, mean and standard deviation.
- Plot the separate R, G and B histograms of Street at dusk.
- Apply contrast stretching to the underexposed image and compare histograms.
- Apply global histogram equalization and compare again.
- Apply CLAHE with tile grids of 4×4 and 8×8 and clip limits of 2 and 4.
- Equalize a color image through its luminance channel and through each RGB channel separately; compare the colors.
- Repeat with your own low-contrast photograph.
- Save before and after figures with their histograms.
Results and Discussion
To be completed
Add your histograms and observations: how each method reshaped the distribution, where equalization amplified noise, and how the CLAHE settings changed local detail.
Conclusion
To be completed
Summarize when to use stretching, global equalization or CLAHE, in your own words.