Histogram of Oriented Gradients (original) (raw)

Last Updated : 23 Jul, 2025

**HOG is a feature descriptor used in computer vision and image processing for object detection. It captures the structure or the shape of an object by analyzing the distribution (histograms) of gradient orientations in localized portions of an image. HOG is especially popular for human and vehicle detection.

Walkthrough-of-HOG-Step-by-Step

Walkthrough of HOG Step by Step

1. **Preprocessing

Image-Preprocessing

Image Preprocessing

2. **Compute Gradients

Calculating-Gradient-and-Orientation

Calculating Gradient and Orientation

3

Value of Magnitude and direction

**Note: Standard practice is to resize images to 64x128 pixels and use larger cell sizes (8x8 or 16x16), but smaller sizes are used here due to the small input images.

3. **Divide Image into Cells

4. **Create Orientation Histograms

Build-Histogram

Build Histogram

5. **Normalize Across Blocks

Normalisation

Normalisation

6. **Concatenate Features

Below is a simple implementation using OpenCV and scikit-image

import matplotlib.pyplot as plt

from skimage.feature import hog from skimage import data, exposure

image = data.astronaut()

fd, hog_image = hog( image, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualize=True, channel_axis=-1, )

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True)

ax1.axis('off') ax1.imshow(image, cmap=plt.cm.gray) ax1.set_title('Input image')

Rescale histogram for better display

hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 10))

ax2.axis('off') ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray) ax2.set_title('Histogram of Oriented Gradients') plt.show()

`

**Output

Output-Image

Output Image

Above is the output features extracted from the given input image.

Why is HOG Effective?

Applications of HOG

  1. **Human Detection : Widely used in pedestrian detection (e.g., in self-driving cars, surveillance).
  2. **Vehicle Detection : Detecting cars, trucks, and other vehicles in traffic analysis.
  3. **Face Detection : Used as a pre-processing step in face recognition systems.
  4. **Object Recognition : General object detection tasks in robotics and automation.
  5. **Medical Imaging : Identifying structures in X-rays, MRIs, etc.
  6. **Gesture Recognition : Recognizing hand or body gestures in interactive systems.