By Aman Kharwal

Extracting HOG Features

Data Science Project on Extracting HOG Features from an Image using Machine Learning.

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:

  1. Optionally prenormalize images. This leads to features that resist dependence on variations in illumination.
  2. Convolve the image with two filters that are sensitive to horizontal and vertical brightness gradients. These capture edge, contour, and texture information.
  3. Subdivide the image into cells of a predetermined size, and compute a histogram of the orientations within each cell.
  4. Normalize the histogram in each cell by comparing to the block of neighboring cells. This further suppresses the effect of illumination across the image.
  5. 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),
ax[0].imshow(image, cmap='gray')
ax[0].set_title('input image')
ax[1].set_title("extarcting features from image")

3 replies on “Extracting HOG Features”

Leave a Reply