Computer Vision Lab Algorithms Histogram equalisation
Histogram equalisation
Histogram equalization
Redistributing the intensities to flatten the histogram.
This content was prepared automatically from documented sources and its human scientific review is not yet complete. If you find an error, let us know.
Mathematical formula
s_k = \operatorname{round}\!\left(255 \sum_{j=0}^{k} p(r_j)\right)Explanation
The cumulative distribution function is used as the transform, so the values spread over the whole range and the global contrast increases.
Detailed explanation
Intuition
If an image's intensities are gathered in a narrow part of the range, it looks dull. Histogram equalisation spreads the intensities over the whole range so that the resulting histogram is roughly flat. The tool is the cumulative distribution function (CDF): we use it as the transform itself, so dense levels move apart and rare ones move together.
How it works step by step
- Compute the histogram
h(k)and normalise it to probabilitiesp(k). - Compute the cumulative distribution.
- Multiply the cumulative distribution by 255 and round it to get a lookup table.
- Apply the table to each pixel.
Mathematical formulation
s_k = \operatorname{round}\!\Big(255 \sum_{j=0}^{k} p(r_j)\Big)In the continuous case, if s = F_r(r) where F_r is the cumulative distribution function, then s is perfectly uniformly distributed. In the discrete case the flattening is approximate because levels cannot be split.
Computational complexity
O(HW + L).
Advantages
- Automatic and parameter-free.
- A large improvement in dull images.
- Reveals hidden details in medical and satellite images.
Limitations
- Global: it may over-amplify noise in uniform regions, or weaken an important contrast in a small region.
- It may produce an unnatural appearance.
- For colour images, it should be applied to the luminance channel only (such as Y in YCrCb), not to each colour channel.
When do you use it?
To improve display and visual analysis. When the lighting varies across the image or the noise is amplified, use CLAHE.
Code example (Python + OpenCV)
eq = cv2.equalizeHist(gray)
ycc = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb); ycc[..., 0] = cv2.equalizeHist(ycc[..., 0])Applications
Improving dull images.
Limitations
It amplifies noise and may change the appearance unnaturally.
References
- OpenCV (2024).OpenCV documentation: Image Processing (imgproc module). docs.opencv.org. docs.opencv.org
- R. Szeliski (2022).Computer Vision: Algorithms and Applications (2nd ed.). Springer, Texts in Computer Science. doi:10.1007/978-3-030-34372-9
