Histogram of oriented gradients

Also known as: HOG

On this page 7

A histogram of oriented gradients (HOG) is a feature descriptor in computer vision that describes the shape of an object by counting how strongly and in which directions image intensity changes within small regions of an image. It divides an image window into cells, builds a histogram of gradient orientations in each cell, normalizes groups of cells and concatenates the results into one fixed-length vector.

HOG became widely known through pedestrian detection in the mid-2000s, where it was paired with a linear support vector machine (SVM). Although deep convolutional networks and vision transformers now dominate most recognition tasks, HOG remains a fast, interpretable and training-free descriptor used on embedded hardware, in classical face detectors and as a teaching baseline for feature extraction in artificial intelligence.

How the HOG descriptor is computed

The HOG pipeline converts raw pixels into a robust summary of local edge structure in five steps. Each step is simple, which is why the descriptor is cheap to compute and easy to reason about.

  1. Gradient computation: horizontal and vertical derivatives are calculated, usually with the simple centered filter [-1, 0, 1], giving a magnitude and an orientation for every pixel.
  2. Cell histograms: the window is split into cells, typically 8 x 8 pixels, and each pixel votes into an orientation bin weighted by its gradient magnitude.
  3. Vote interpolation: votes are shared between neighboring bins and cells to reduce aliasing at bin boundaries.
  4. Block normalization: overlapping blocks of 2 x 2 cells are normalized so that the descriptor tolerates changes in illumination and contrast.
  5. Concatenation: all normalized block vectors are joined into the final feature vector for the window.

The key idea is that object shape is captured by the distribution of edge directions, not by exact edge positions. Small shifts or deformations move pixels between neighboring cells only slightly, so the histogram changes gradually instead of abruptly.

Parameters that shape a HOG descriptor

HOG performance depends on a handful of design parameters that trade detail against robustness. The classic configuration for detecting upright people uses a 64 x 128 pixel window, which produces a vector of 3,780 values.

The table below lists the main parameters, their standard settings and what changing them does.

ParameterCommon settingEffect of changing it
Cell size8 x 8 pixelsSmaller cells keep detail but add noise and length
Orientation bins9 bins over 0 to 180 degreesMore bins add angular precision with diminishing gains
Gradient signUnsigned orientationsSigned gradients help when contrast polarity is stable
Block size2 x 2 cellsLarger blocks give stronger but coarser normalization
Block strideOne cell, giving 50 percent overlapOverlap improves accuracy and increases vector size
NormalizationL2-Hys or L2Controls robustness to lighting and strong edges
Standard HOG parameters and their effects

Unsigned orientations treat a dark-to-light edge and a light-to-dark edge as equal. This choice suits pedestrians and vehicles, whose clothing and paint vary in color against changing backgrounds, so the direction of the boundary matters more than its polarity.

HOG compared with other feature descriptors

HOG belongs to the family of hand-crafted gradient descriptors, and its closest relative is SIFT. The difference lies mainly in where and how the descriptor is applied: SIFT describes sparse keypoints for matching, while HOG densely describes a whole detection window for classification.

This comparison places HOG among related descriptors used in computer vision.

DescriptorMain useKey difference from HOG
HOGDense window description for detectionReference method
SIFTKeypoint matching and registrationSparse, scale and rotation invariant
Haar-like featuresFast cascade face detectionRectangle intensity sums, not gradients
Local binary patternsTexture and face analysisEncodes pixel comparisons, not orientations
CNN featuresGeneral recognition and detectionLearned from data rather than designed
HOG and related image descriptors

A notable observation is that the first layers of trained convolutional networks often learn oriented edge filters similar to the gradients HOG measures. Deep models go further by learning many layers of combinations, which explains their large accuracy advantage on cluttered, varied scenes.

Using HOG in a detection pipeline

In object detection, HOG is normally combined with a sliding window, an image pyramid and a classifier. The detector scans windows at many positions and scales, computes a HOG vector for each window, scores it with a linear SVM and finally applies non-maximum suppression to merge overlapping detections into single bounding boxes.

The decision table below shows when HOG is still a reasonable choice and when a learned model is preferable.

SituationRecommended choiceReason
Microcontroller or low-power cameraHOG with linear SVMRuns without a GPU and with little memory
Rigid object, fixed viewpointHOG-based detectorShape is consistent and data needs are small
Small labeled datasetHOG features plus a simple classifierNo large training set is required
Crowded scenes with occlusionDeep detector such as YOLOLearned features handle variation far better
Many object classesModern neural detectorHOG needs one model per class and pose
When to choose HOG

Extensions improve the basic method. The deformable part model combines a coarse HOG root filter with finer part filters that can shift, which handles articulated poses much better than a single rigid template.

Limitations and common mistakes

HOG is not rotation invariant and handles large scale changes only through an external image pyramid. It also describes shape rather than color or texture, so objects that differ mainly in appearance are hard to separate. Common practical mistakes include the following:

  • Mismatched window aspect ratio, such as using a tall pedestrian window to detect wide vehicles
  • Skipping block normalization, which makes the descriptor sensitive to shadows and exposure
  • Excessive image smoothing before gradient computation, which blurs the edges HOG depends on
  • Too few hard negatives during SVM training, which produces many false detections on background clutter

A frequent misconception is that HOG is obsolete. It is no longer state of the art in accuracy, yet it remains useful wherever speed, transparency and small data outweigh peak performance.

In simple terms

Imagine tracing an object’s outline with short pencil strokes and then noting, for each small patch of the picture, which way most strokes point. A person standing upright leaves many vertical strokes along the legs and body and a rounded set near the head. HOG makes exactly this kind of summary of edge directions, patch by patch.

Because it records directions rather than colors or exact positions, the summary looks similar for people in different clothes or slightly different poses. A computer can then compare summaries and decide whether a patch of the image contains the object it is searching for, quickly and without heavy hardware.

A practical example

An engineer building a battery-powered people counter for a library entrance uses a camera mounted above the door at a fixed angle. Because the device has no GPU, the engineer chooses a HOG descriptor with a linear SVM, trained on about 2,000 cropped images of visitors and 10,000 background patches, including hard negatives such as coat racks and door frames.

The detector runs on downscaled frames of 320 x 240 pixels using a small image pyramid and non-maximum suppression, processing several frames per second on a low-power processor. Over a week of testing, its counts stay within a few percent of manual tallies during normal traffic, while accuracy drops when groups enter shoulder to shoulder. The outcome is a low-cost counter that meets the library’s reporting needs, with a documented limitation for crowded periods.