All problems
Unsharp Masking
Problem
Sharpen a grayscale image with unsharp masking.
Blur the image with a normalized 3x3 Gaussian kernel (sigma 1) using valid-mode cross-correlation, then set each center pixel to clamp(round(v + amount * (v - blur)), 0, 255), where v is the corresponding input pixel. The output shape is (H - 2) x (W - 2).
Hint
Add back a scaled version of the high-frequency detail (original minus blur).
Test cases
case 1
in: [[[4,4,4],[4,4,4],[4,4,4]],1]
expected: [[4]]
case 2
in: [[[0,0,0],[0,10,0],[0,0,0]],1]
expected: [[18]]
case 3
in: [[[1,2,3],[4,5,6],[7,8,9]],0.5]
expected: [[5]]
case 4
in: [[[1,2,3],[4,5,6],[7,8,9]],0]
expected: [[5]]
Starter codePython
def unsharp_mask(image, amount):
# Your code here
pass4 test cases · run your code against them in the editor