8 つのビンと事前にカウントされた Sobel X および Y フィルター処理された画像を使用して HOG 画像を計算する次のコードがあります。
for y in xrange(0, 480):
for x in xrange(0, 640):
base_angle = np.arctan2(sobel_Y[y,x], sobel_X[y,x]) * 180/np.pi
if base_angle < 0: base_angle += 360
angle = int(round(base_angle / 45))
if angle == 8: angle = 0
hog[y,x,angle] += np.sqrt(sobel_X[y,x]**2 + sobel_Y[y,x]**2)
ループを避けるためにそれを変更しようとしていました:
base_angle = np.arctan2(sobel_Y, sobel_X) * 180/np.pi
base_angle[base_angle < 0] += 360
angle =(base_angle / 45).round().astype(np.uint8)
angle[angle == bins] = 0
hog[:,:,angle] += np.sqrt(sobel_X**2 + sobel_Y**2)
ただし、最後の式は正しくカウントされません。基本的に必要なのは、ホッグ配列のすべての(y、x)ポイントで、角度配列のインデックスに従って、マグニチュード(np.sqrt ...式)をホッグ配列に追加することです。解決策はありますか?