-
Notifications
You must be signed in to change notification settings - Fork 9
/
pyhog.py
37 lines (33 loc) · 1.01 KB
/
pyhog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import numpy as np
import features_pedro_py
try:
from scipy.misc import imrotate
imrotate_available = True
except ImportError:
imrotate_available = False
def features_pedro(img, sbin):
imgf = img.copy('F')
hogf = features_pedro_py.process(imgf, sbin)
return hogf
def hog_picture(w, bs=20):
""" Visualize positive HOG weights.
ported to numpy from https://github.com/CSAILVision/ihog/blob/master/showHOG.m
"""
if not imrotate_available:
raise RuntimeError('This function requires scipy')
bim1 = np.zeros((bs, bs))
bim1[:,round(bs/2)-1:round(bs/2)] = 1
bim = np.zeros((9,)+bim1.shape)
for i in xrange(9):
bim[i] = imrotate(bim1, -i*20)/255.0
s = w.shape
w = w.copy()
w[w < 0] = 0
im = np.zeros((bs*s[0], bs*s[1]))
for i in xrange(s[0]):
iis = slice( i*bs, (i+1)*bs )
for j in xrange(s[1]):
jjs = slice( j*bs, (j+1)*bs )
for k in xrange(9):
im[iis,jjs] += bim[k] * w[i,j,k+18]
return im/np.max(w)