All problems
Standardization of Image Pixels
Problem
Standardize an image to zero mean and unit variance.
Compute the population mean and standard deviation over all pixels, then return (v - mean) / std rounded to 4 decimal places. If the standard deviation is 0, return a same-shaped grid of zeros.
Test cases
case 1
in: [[[1,2],[3,4]]]
expected: [[-1.3416,-0.4472],[0.4472,1.3416]]
case 2
in: [[[5,5],[5,5]]]
expected: [[0,0],[0,0]]
case 3
in: [[[10]]]
expected: [[0]]
case 4
in: [[[2,4,4,4],[5,5,7,9]]]
expected: [[-1.5,-0.5,-0.5,-0.5],[0,0,1,2]]
Starter codePython
def standardize(image):
# Your code here
pass4 test cases · run your code against them in the editor