Skip to content
DeepForgeby svx
All problems
EasyComputer Visioncv-014

Min-Max Normalization

Problem

Min-max normalize an image to the range [0, 1].

For each pixel compute (v - min) / (max - min), rounded to 4 decimal places, where min and max are taken over the whole image. If all pixels are equal, return a same-shaped grid of zeros.

Hint

Handle the constant-image case before dividing to avoid a zero denominator.

Test cases

case 1
in: [[[0,2],[4,8]]]
expected: [[0,0.25],[0.5,1]]
case 2
in: [[[5,5],[5,5]]]
expected: [[0,0],[0,0]]
case 3
in: [[[10,20],[30,40]]]
expected: [[0,0.3333],[0.6667,1]]
case 4
in: [[[-1,1]]]
expected: [[0,1]]
Starter codePython
def min_max_normalize(image):
    # Your code here
    pass

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