🖼️1. What is an Image Histogram?
A histogram shows how brightness (pixel intensity) is distributed in an image.
X-axis: Pixel intensity levels (from 0 to 255)
o 0 = black, 255 = white
Y-axis: Number of pixels with that intensity value
👉 Example:
If many pixels are dark (values near 0), the histogram will have high bars on the left.
If many pixels are bright (values near 255), bars will be on the right.
Purpose:
To analyze how bright or dark an image is.
To measure contrast — how much the brightness levels vary.
⚙️2. What is Histogram Equalization?
Histogram Equalization is a contrast enhancement technique used in Digital Image
Processing.
1. 🧠 The main idea:
It redistributes pixel intensities so that they cover the entire range (0–255).
Dark areas become a bit brighter.
Bright areas become a bit darker.
The image appears clearer, balanced, and more detailed.
👉 Example:
An image that originally used only values 50–150 will, after equalization, use almost the full
range 0–255 — making it more vibrant.
🧮 3. The Concept Behind Equalization
In a normal image:
Pixel values may cluster in a narrow intensity range.
o Example: Mostly gray, little contrast.
After equalization:
Intensities are spread out evenly across all possible levels.
🎯 Goal:
To make the image visually balanced — so both dark and bright regions show details.
🧩 4. Mathematical Explanation
Let’s understand how it’s calculated step by step:
2. Step 1 — Define variables
rkr_krk: input pixel intensity
sks_ksk: output (equalized) pixel intensity
P(rk)P(r_k)P(rk): probability of each intensity
LLL: total number of possible gray levels (usually 256 for 8-bit images)
3. Step 2 — Transformation formula
sk=(L−1)∑j=0kP(rj)s_k = (L - 1) \sum_{j=0}^{k} P(r_j)sk=(L−1)j=0∑kP(rj)
This means:
The new output value sks_ksk depends on how frequently intensities less than or
equal to rkr_krk appear in the image.
The summation ∑P(rj)\sum P(r_j)∑P(rj) is the Cumulative Distribution Function
(CDF).
CDF ensures that pixel values are evenly spread across the range.
🧾 5. Example (from your presentation)
We are given a 3×3 grayscale image:
[525561597961766179]\begin{bmatrix} 52 & 55 & 61 \\ 59 & 79 & 61 \\ 76 & 61 & 79 \
end{bmatrix}525976557961616179
Total pixels n=9n = 9n=9.
4. Step 1: Compute Histogram
Count how many times each value appears.
Intensity Frequency
52 1
55 1
59 1
61 3
76 1
79 2
Total 9
5. Step 2: Compute Probability
P(rk)=nknP(r_k) = \frac{n_k}{n}P(rk)=nnk
Intensity Frequency Probability P(rk)P(r_k)P(rk)
52 1 1/9 = 0.11
55 1 1/9 = 0.11
59 1 1/9 = 0.11
61 3 3/9 = 0.33
76 1 1/9 = 0.11
79 2 2/9 = 0.22
6. Step 3: Compute Cumulative Distribution Function (CDF)
The CDF adds all probabilities up to each intensity:
Intensity Probability CDF (sum of all previous P(r)P(r)P(r))
52 0.11 0.11
55 0.11 0.22
59 0.11 0.33
61 0.33 0.66
76 0.11 0.77
79 0.22 0.99
✅ CDF values = [0.11, 0.22, 0.33, 0.66, 0.77, 0.99]
7. Step 4: Compute New Pixel Values
sk=round(CDF(rk)×(L−1))s_k = \text{round}(CDF(r_k) \times (L - 1))sk=round(CDF(rk
)×(L−1))
where L=256L = 256L=256
So, multiply each CDF by 255 and round:
Intensity CDF New value sks_ksk
52 0.11 28
55 0.22 56
59 0.33 84
61 0.66 168
76 0.77 197
79 0.99 252
8. Step 5: Replace old pixel values
Now map every pixel in the original image to its new equalized value.
Old New
52 28
55 56
61 168
59 84
79 252
76 197
So, the new image (equalized) looks like:
[285616884252168197168252]\begin{bmatrix} 28 & 56 & 168 \\ 84 & 252 & 168 \\ 197 &
168 & 252 \end{bmatrix}288419756252168168168252
The contrast is clearly increased — the new image uses the whole brightness range.
💡 6. Why This Works
The CDF redistributes intensities so each range of brightness appears equally often.
The formula sk=(L−1)CDF(rk)s_k = (L - 1) CDF(r_k)sk=(L−1)CDF(rk) ensures the
output uses all 0–255 values.
The equalized histogram becomes almost flat — evenly spread pixel distribution.
💻 7. Python Code Explanation
import cv2
import [Link] as plt
# Read image in grayscale
img = [Link]('[Link]', 0)
# Apply histogram equalization
equalized = [Link](img)
# Display before and after
[Link](1,2,1)
[Link]('Original Image')
[Link](img, cmap='gray')
[Link](1,2,2)
[Link]('Equalized Image')
[Link](equalized, cmap='gray')
[Link]()
Explanation:
[Link]('[Link]', 0) → reads image in grayscale.
[Link](img) → automatically applies histogram equalization using the
CDF formula.
The imshow function shows both images side by side.
📚 8. Applications
Medical Imaging (X-rays, MRI) — clearer internal structures.
Remote Sensing — improves satellite image clarity.
Document Scanning — enhances faded text.
Security Cameras — improves visibility in low light.
⚖️9. Advantages and Limitations
Advantages Limitations
Simple and easy to implement May over-enhance noise
Increases global contrast Not suitable for all image types
Makes hidden details visible Uneven lighting can cause artifacts
🔄 10. Variants
AHE (Adaptive Histogram Equalization):
Works on small regions instead of the whole image.
CLAHE (Contrast Limited Adaptive Histogram Equalization):
Prevents over-amplification of noise; balances local contrast carefully.
🧠 11. Summary
Histogram Equalization redistributes pixel intensities using the CDF formula.
It enhances image contrast and reveals hidden details.
It’s widely used in image preprocessing, especially for scientific and low-light
imaging.