All problems
Sobel X and Y
Problem
Compute the Sobel gradients Gx and Gy separately in valid mode.
Use Gx = [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]] and Gy = [[1, 2, 1], [0, 0, 0], [-1, -2, -1]]. Return [gx, gy], two (H - 2) x (W - 2) integer maps.
Hint
Run the same sliding window twice, once per kernel.
Test cases
case 1
in: [[[0,0,0],[0,0,0],[0,0,10]]]
expected: [[[10]],[[-10]]]
case 2
in: [[[0,0,0],[0,0,0],[5,5,5]]]
expected: [[[0]],[[-20]]]
case 3
in: [[[0,0,0],[5,5,5],[0,0,0]]]
expected: [[[0]],[[0]]]
case 4
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: [[[8]],[[-24]]]
Starter codePython
def sobel_xy(image):
# Your code here
pass4 test cases · run your code against them in the editor