All problems
HOG Cell (9-Bin)
Problem
Build a simplified 9-bin HOG histogram over a whole gradient map.
For each pixel with gradients (gx, gy), let mag = sqrt(gx^2 + gy^2) and bin = int((degrees(atan2(gy, gx)) mod 180) // 20) mod 9, then accumulate mag into that bin. Return the 9 bin sums rounded to 4 decimal places.
Hint
Orientations live in [0, 180): 20 degrees per bin, folded with modulo.
Test cases
case 1
in: [[[1,0],[0,1]],[[0,1],[1,0]]]
expected: [2,0,0,0,2,0,0,0,0]
case 2
in: [[[0,0,0],[0,0,0],[0,0,0]],[[1,1,1],[1,1,1],[1,1,1]]]
expected: [0,0,0,0,9,0,0,0,0]
case 3
in: [[[3,0]],[[4,0]]]
expected: [0,0,5,0,0,0,0,0,0]
case 4
in: [[[1,1]],[[1,-1]]]
expected: [0,0,1.4142,0,0,0,1.4142,0,0]
Starter codePython
def hog_cell(gx, gy):
# Your code here
pass4 test cases · run your code against them in the editor