All problems
Contrast Adjustment
Problem
Adjust the contrast of a grayscale image around the midpoint 128.
Each pixel becomes clamp(round(128 + alpha * (v - 128)), 0, 255), returned as an integer. alpha = 1 leaves the image unchanged and alpha < 1 reduces contrast.
Test cases
case 1
in: [[[0,100],[200,255]],1.5]
expected: [[0,86],[236,255]]
case 2
in: [[[0,128,254]],0.5]
expected: [[64,128,191]]
case 3
in: [[[10,20],[30,40]],1]
expected: [[10,20],[30,40]]
case 4
in: [[[0,64,192,255]],2]
expected: [[0,0,255,255]]
Starter codePython
def adjust_contrast(image, alpha):
# Your code here
pass4 test cases · run your code against them in the editor