PIXELBANKv9.1.0
Menu

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:

  1. Compute the Cumulative Histogram (CDF): Calculate the cumulative proportion of pixels ckc_k for each intensity level kk by normalizing the cumulative sum of the histogram hh by the total number of pixels NN:

ck=∑l=1khlNc_k = \frac{\sum_{l=1}^{k} h_l}{N}

  1. Apply Transformation: Map the original intensity value pijp_{ij} to the new intensity value xijx_{ij} using the calculated cumulative proportion and the maximum intensity value KK:

xij=Kâ‹…cpijx_{ij} = K \cdot c_{p_{ij}}

Your task is to take a flat 1D array representing grayscale pixel intensities (where the maximum possible intensity KK is 10) and return the transformed array after applying histogram equalization.

Example:

Input:
intensities = [2, 3, 3, 5, 5, 5, 7, 7, 7, 7]
max_k = 10
# Total pixels N = 10
Output:
[1, 3, 3, 6, 6, 6, 10, 10, 10, 10]
Reasoning:
  1. Calculate histogram counts for each intensity level
  2. Compute CDF: ck=cumulative countNc_k = \frac{\text{cumulative count}}{N}
    • c2=0.1c_2 = 0.1, c3=0.3c_3 = 0.3, c5=0.6c_5 = 0.6, c7=1.0c_7 = 1.0
  3. Apply transformation: xij=Kâ‹…cpijx_{ij} = K \cdot c_{p_{ij}}
    • Intensity 2 → 10×0.1=110 \times 0.1 = 1
    • Intensity 3 → 10×0.3=310 \times 0.3 = 3
    • Intensity 5 → 10×0.6=610 \times 0.6 = 6
    • Intensity 7 → 10×1.0=1010 \times 1.0 = 10

Constraints:

  • The input array contains positive integer intensity values
  • The maximum possible intensity KK is 10
  • The output array elements must be rounded down to the nearest integer (floor)
solution.py

Test Results

0/0
Run code to see test results.