Skip to content
DeepForgeby svx
All problems
HardComputer Visioncv-037

Histogram Equalization

Problem

Equalize the histogram of a grayscale image with a 256-bin lookup table.

For each intensity v, output round(255 * cdf(v) / N), where cdf(v) is the cumulative count of pixels with value <= v and N is the total pixel count. An empty image returns [].

Hint

Build the cumulative histogram first, then map each pixel through the lookup table.

Test cases

case 1
in: [[[0,0],[255,255]]]
expected: [[128,128],[255,255]]
case 2
in: [[[0,1],[2,3]]]
expected: [[64,128],[191,255]]
case 3
in: [[[5,5]]]
expected: [[255,255]]
case 4
in: [[]]
expected: []
Starter codePython
def histogram_equalize(image):
    # Your code here
    pass

4 test cases · run your code against them in the editor