EP03_04 📊 Histogram Equalization (L bits)
In remote sensing satellite images, variation in illumination throughout the day produces low-contrast images. Histogram equalization is automatically applied in satellites such as Landsat to redistribute tones, revealing details of vegetation, relief, and urban areas that are invisible in the original image.
See Figure 3.29 for a simulation of this EP.
📋 Implementation Guidelines
Dimensions: Read the integers \(L\) (rows), \(C\) (columns), and \(B\) (number of bits, with \(L_{\max} = 2^B\) ).
Data: Read the pixel matrix \(f\) with values in \([0, 2^B - 1]\) .
Histogram: Compute \(h[k]\) = number of pixels with intensity \(k\) , for \(k = 0 \ldots 2^B-1\) .
Probability: \(p[k] = h[k] / (L \cdot C)\) .
CDF: \(\text{cdf}[k] = \sum_{j=0}^{k} p[j]\) ; cumulative distribution function.
LUT: \(\text{lut}[k] = \text{round}\left(\text{cdf}[k] \cdot (2^B - 1)\right)\) ; Look-Up Table .
Application: \(g[i,j] = \text{lut}[f[i,j]]\) .
Output: Display the equalized matrix of size \(L \times C\) .
📌 Computational Constraints
Rounding: Use mathematical rounding (round) in the LUT.
Bits: The number of levels is \(2^B\) (e.g., \(B=3 \Rightarrow 8\) levels, \(B=8 \Rightarrow 256\) levels).
Cumulative CDF: \(\text{cdf}[k] = \sum_{j=0}^{k} p[j]\) , with \(\text{cdf}[2^B-1] = 1.0\) .
🧠 Theoretical Foundation
1
Histogram
\(h[k] \leftarrow\) number of pixels with intensity \(k\)
2
Probability
\(p[k] = h[k] / (L \cdot C)\)
3
CDF
\(\text{cdf}[k] = \sum_{j=0}^{k} p[j]\)
4
LUT
\(\text{lut}[k] = \text{round}(\text{cdf}[k] \cdot (2^B-1))\)
5
Application
\(g[i,j] = \text{lut}[f[i,j]]\)
📌 Examples
5
5
3
3 4 2 3 4
4 3 3 4 3
2 3 4 3 2
3 4 3 2 3
4 3 2 3 4
5 7 1 5 7
7 5 5 7 5
1 5 7 5 1
5 7 5 1 5
7 5 1 5 7
Example with 3 bits from the chapter
1
4
3
0 0 7 7
0 0 7 7
Extreme bimodal histogram
Figure 3.29: Simulator EP03_04: Histogram Equalization (Levels L = 2^B)
%% writefile EP03_04.cpp
// your solution
TestSuite("EP03_04.cpp" ).run()
✔️ EP03_04.cases already exists in casos/
📋 5 case(s) loaded from casos/EP03_04.cases
🔍 Testing C++: EP03_04.cpp
⚠️ EP03_04.cpp: Empty file (fewer than 3 lines). Tests skipped.