Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-028

Histogram Binning

Problem

Compute a histogram of a grayscale image with a fixed number of bins.

Pixel values are integers in [0, 255]. The bin index for value v is v * bins // 256. Return the list of bin counts, which has length bins.

Hint

Scale the intensity into the bin range with integer division.

Test cases

case 1
in: [[[0,255],[128,64]],4]
expected: [1,1,1,1]
case 2
in: [[[0,0],[100,200]],2]
expected: [3,1]
case 3
in: [[[0,32,64,96,128,160,192,224,255]],8]
expected: [1,1,1,1,1,1,1,2]
Starter codePython
def histogram(image, bins):
    # Your code here
    pass

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