Image Histogram Equalization
Histogram equalization is a technique used in image preprocessing to modify the intensity values such that the distribution of pixel intensities is approximately uniform. This process is useful for increasing contrast by making sure all moments of the intensity values take predefined values.
The process involves two main steps:
- Compute the Cumulative Histogram (CDF): Calculate the cumulative proportion of pixels for each intensity level by normalizing the cumulative sum of the histogram by the total number of pixels :
- Apply Transformation: Map the original intensity value to the new intensity value using the calculated cumulative proportion and the maximum intensity value :
Your task is to take a flat 1D array representing grayscale pixel intensities (where the maximum possible intensity is 10) and return the transformed array after applying histogram equalization.
Example
intensities = [2, 3, 3, 5, 5, 5, 7, 7, 7, 7] max_k = 10 # Total pixels N = 10
[1, 3, 3, 6, 6, 6, 10, 10, 10, 10]
- Calculate histogram counts for each intensity level
- Compute CDF:
- , , ,
- Apply transformation:
- Intensity 2 →
- Intensity 3 →
- Intensity 5 →
- Intensity 7 →
Constraints
- The input array contains positive integer intensity values
- The maximum possible intensity is 10
- The output array elements must be rounded down to the nearest integer (floor)