PIXELBANKv8.2.1
Menu

Image Histogram Equalization

Implement histogram equalization to enhance image contrast using NumPy.

Histogram equalization redistributes pixel intensities to achieve a more uniform histogram, improving contrast in images with concentrated intensity ranges.

Algorithm:

  1. Compute histogram h[i]h[i] = count of pixels with intensity ii
  2. Compute cumulative distribution function: CDF[i]=j=0ih[j]CDF[i] = \sum_{j=0}^{i} h[j]
  3. Normalize CDF to range [0, 255]: CDFnorm[i]=CDF[i]CDFmin(M×N)CDFmin×255CDF_{norm}[i] = \frac{CDF[i] - CDF_{min}}{(M \times N) - CDF_{min}} \times 255
  4. Map each pixel: output[x,y]=CDFnorm[input[x,y]]output[x,y] = CDF_{norm}[input[x,y]]

Where M×NM \times N is the total number of pixels and CDFminCDF_{min} is the minimum non-zero CDF value.

Example:

Input:
image = [[50, 50], [50, 50]]
Output:
[[255, 255], [255, 255]]
Reasoning:

Step 1: Histogram Only intensity 50 appears, count = 4

Step 2: CDF CDF[50] = 4, all others = 0 or 4

Step 3: Normalize CDF_min = 4, total pixels = 4 CDF_norm[50] = (4-4)/(4-4) × 255 = undefined → use 255 when all same

Step 4: Map All pixels map to 255 (maximum) since they all have the same value.

When all pixels are identical, equalization maps them to maximum intensity.

Constraints:

  • image: 2D numpy array with values in [0, 255]
  • Return: Equalized image with same shape, values in [0, 255]
  • Output values should be integers
Editor

Test Results

0/0
Run code to see test results.