In Data Science the HOG (Histogram of Gradients) is a straightforward feature extraction process that was developed with the idea of identifying pedestrians within images.
HOG involves the following steps:
- Optionally prenormalize images. This leads to features that resist dependence on variations in illumination.
- Convolve the image with two filters that are sensitive to horizontal and vertical brightness gradients. These capture edge, contour, and texture information.
- Subdivide the image into cells of a predetermined size, and compute a histogram of the orientations within each cell.
- Normalize the histogram in each cell by comparing to the block of neighboring cells. This further suppresses the effect of illumination across the image.
- Construct a one-dimensional feature vector from the information in each cell.
A fast HOG extractor is built into the Scikit-Image project, and we can try it out relatively quickly and visualize the oriented gradients within each cell:
from skimage import data, color, feature image = color.rgb2gray(data.chelsea()) hogVec, hogVis = feature.hog(image, visualize=True) import matplotlib.pyplot as plt fig, ax = plt.subplots(1, 2, figsize=(12, 6), subplot_kw=dict(xticks=, yticks=)) ax.imshow(image, cmap='gray') ax.set_title('input image') ax.imshow(hogVis) ax.set_title("extarcting features from image") plt.show()