Histogram Equalization
Improves image contrast by redistributing intensity values. Flattens histogram to use full dynamic range. Automatic contrast enhancement.
Visualization
Interactive visualization for Histogram Equalization
Histogram Equalization:
- • Enhance contrast
Interactive visualization with step-by-step execution
Implementation
1function histogramEqualization(image: number[][]): number[][] {
2 const h = image.length, w = image[0].length;
3 const L = 256; // 8-bit image
4 const hist = new Array(L).fill(0);
5
6 // Calculate histogram
7 for (let i = 0; i < h; i++) {
8 for (let j = 0; j < w; j++) {
9 hist[Math.floor(image[i][j])]++;
10 }
11 }
12
13 // Calculate CDF
14 const cdf = new Array(L);
15 cdf[0] = hist[0];
16 for (let i = 1; i < L; i++) {
17 cdf[i] = cdf[i - 1] + hist[i];
18 }
19
20 // Normalize and map
21 const cdfMin = cdf.find(v => v > 0) || 0;
22 const result: number[][] = [];
23
24 for (let i = 0; i < h; i++) {
25 result[i] = [];
26 for (let j = 0; j < w; j++) {
27 const val = Math.floor(image[i][j]);
28 result[i][j] = Math.round(((cdf[val] - cdfMin) / (h * w - cdfMin)) * (L - 1));
29 }
30 }
31
32 return result;
33}Deep Dive
Theoretical Foundation
Creates cumulative distribution function (CDF) from histogram. Maps input intensities to output using CDF: out = (CDF(in) - CDF_min) × (L-1) / (w×h - CDF_min). L = intensity levels (256 for 8-bit).
Complexity
Time
O(w×h)
O(w×h)
O(w×h)
Space
O(L)
Applications
Industry Use
Medical imaging enhancement (X-rays, MRI)
Satellite and aerial image processing
Low-light photography enhancement
Document image preprocessing
Underwater image enhancement
Forensic image analysis
Preprocessing for computer vision systems
Use Cases
Related Algorithms
A* Search Algorithm
Informed search algorithm combining best-first search with Dijkstra's algorithm using heuristics. Widely used in pathfinding and graph traversal, A* is optimal and complete when using admissible heuristic. Used in games, GPS navigation, and robotics. Invented by Peter Hart, Nils Nilsson, and Bertram Raphael in 1968.
Convex Hull (Graham Scan)
Find smallest convex polygon containing all points. Graham Scan invented by Ronald Graham in 1972, runs in O(n log n). Essential in computational geometry, computer graphics, and pattern recognition.
Line Segment Intersection
Determine if two line segments intersect. Fundamental geometric primitive used in graphics, CAD, GIS. Uses orientation and collinearity tests.
Caesar Cipher
The Caesar Cipher is one of the oldest and simplest encryption techniques, named after Julius Caesar who used it to protect military messages around 100 BC. It works by shifting each letter in the plaintext by a fixed number of positions down the alphabet. For example, with a shift of 3, A becomes D, B becomes E, and so on. Despite being used for over 2000 years, it's extremely weak by modern standards with only 25 possible keys, making it trivially breakable by brute force or frequency analysis.