Created
September 13, 2019 14:04
-
-
Save alexandru-dinu/90e05a7cc86d57ebb441c89a6b773fcc to your computer and use it in GitHub Desktop.
quick-and-dirty hog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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