""" 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)