HOG.py
1.29 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Extract HOG feature of images.But we decide to use C instead of Python considering the 10-times efficiency gap.
@author: chunk
chunkplus@gmail.com
2014 Dec
"""
__author__ = 'hadoop'
from . import *
from ..common import *
import numpy as np
from PIL import Image
from skimage.feature import hog
from skimage import io, color, transform, exposure
class FeatHOG(FeatureBase):
def __init__(self, size=(64, 64)):
FeatureBase.__init__(self)
self.size = size
def _feat_sk(self, image, size=(64, 64)):
"""
N.B. image[x][y][z] where x for line and y for column,z(0,1,2) for (R,G,B)
"""
if size is None:
size = (64, 64)
img = io.imread(image, as_grey=True) # 0.02s
img = transform.resize(img, size)
# img = color.rgb2gray(img)
fd = hog(img, orientations=9, pixels_per_cell=(8, 8),
cells_per_block=(2, 2), visualise=False, normalise=False) # 0.18s
# hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 0.02))
#
# cv2.imshow('processed', ski2cv(hog_image_rescaled))
# cv2.waitKey(0)
return fd
def set_size(self, size):
self.size = size
def feat(self, image):
return self._feat_sk(image, self.size)