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.
- 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.
- 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.
- Vote interpolation: votes are shared between neighboring bins and cells to reduce aliasing at bin boundaries.
- Block normalization: overlapping blocks of 2 x 2 cells are normalized so that the descriptor tolerates changes in illumination and contrast.
- 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.
| Parameter | Common setting | Effect of changing it |
|---|---|---|
| Cell size | 8 x 8 pixels | Smaller cells keep detail but add noise and length |
| Orientation bins | 9 bins over 0 to 180 degrees | More bins add angular precision with diminishing gains |
| Gradient sign | Unsigned orientations | Signed gradients help when contrast polarity is stable |
| Block size | 2 x 2 cells | Larger blocks give stronger but coarser normalization |
| Block stride | One cell, giving 50 percent overlap | Overlap improves accuracy and increases vector size |
| Normalization | L2-Hys or L2 | Controls robustness to lighting and strong edges |
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.
| Descriptor | Main use | Key difference from HOG |
|---|---|---|
| HOG | Dense window description for detection | Reference method |
| SIFT | Keypoint matching and registration | Sparse, scale and rotation invariant |
| Haar-like features | Fast cascade face detection | Rectangle intensity sums, not gradients |
| Local binary patterns | Texture and face analysis | Encodes pixel comparisons, not orientations |
| CNN features | General recognition and detection | Learned from data rather than designed |
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.
| Situation | Recommended choice | Reason |
|---|---|---|
| Microcontroller or low-power camera | HOG with linear SVM | Runs without a GPU and with little memory |
| Rigid object, fixed viewpoint | HOG-based detector | Shape is consistent and data needs are small |
| Small labeled dataset | HOG features plus a simple classifier | No large training set is required |
| Crowded scenes with occlusion | Deep detector such as YOLO | Learned features handle variation far better |
| Many object classes | Modern neural detector | HOG needs one model per class and pose |
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.