Histogram of Oriented Gradients
A popular feature descriptor for object detection is the Histogram of Oriented Gradients (HOG). In this section, we will discuss how HOG descriptors can be computed from an image.
Algorithm to compute HOG descriptors
The following steps describe the algorithm:
- If you wish to, you can globally normalize the image
- Compute the horizontal and vertical gradient images
- Compute the gradient histograms
- Normalize across blocks
- Flatten into a feature descriptor vector
HOG descriptors are the normalized block descriptors finally obtained by using the algorithm.
Compute HOG descriptors with scikit-image
Let's now compute the HOG descriptors using the scikit-image feature module's hog()
function and visualize them:
from skimage.feature import hog from skimage import exposure image = rgb2gray(imread('../images/cameraman.jpg')) fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualize=True) print(image.shape, len(fd)) # ((256L, 256L),...