Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-059

Gradient Direction Angle

Problem

Compute the Sobel gradient direction angle at every valid pixel.

For each 3x3 window compute sx and sy with the Sobel kernels, then angle = degrees(atan2(sy, sx)) mod 180, rounded to 2 decimal places. Return the (H - 2) x (W - 2) map.

Hint

Use atan2(sy, sx) so the quadrant is handled automatically, then reduce mod 180.

Test cases

case 1
in: [[[7,7,7],[7,7,7],[7,7,7]]]
expected: [[0]]
case 2
in: [[[0,0,0],[0,0,0],[0,0,10]]]
expected: [[135]]
case 3
in: [[[0,0,0],[0,0,0],[5,5,5]]]
expected: [[90]]
case 4
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: [[108.43]]
Starter codePython
def gradient_direction(image):
    # Your code here
    pass

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