Skip to content

Instantly share code, notes, and snippets.

@alexandru-dinu
Created September 13, 2019 14:04
Show Gist options
  • Save alexandru-dinu/90e05a7cc86d57ebb441c89a6b773fcc to your computer and use it in GitHub Desktop.
Save alexandru-dinu/90e05a7cc86d57ebb441c89a6b773fcc to your computer and use it in GitHub Desktop.
quick-and-dirty hog
def hog(mag, angle, bin_dist=20):
h, w = mag.shape
bins = defaultdict(lambda: 0)
locs1 = (np.floor(angle / bin_dist) * bin_dist).astype(int)
locs2 = locs1 + bin_dist
ihs = (angle - locs1) / bin_dist
ils = 1 - ihs
il_m = ils * mag
ih_m = ihs * mag
for i in range(h):
for j in range(w):
bins[locs1[i,j] % 180] += il_m[i,j]
bins[locs2[i,j] % 180] += ih_m[i,j]
return sorted(bins.items(), key=lambda k: k[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment