
- Scikit Image – Introduction
- Scikit Image - Image Processing
- Scikit Image - Numpy Images
- Scikit Image - Image datatypes
- Scikit Image - Using Plugins
- Scikit Image - Image Handlings
- Scikit Image - Reading Images
- Scikit Image - Writing Images
- Scikit Image - Displaying Images
- Scikit Image - Image Collections
- Scikit Image - Image Stack
- Scikit Image - Multi Image
- Scikit Image - Data Visualization
- Scikit Image - Using Matplotlib
- Scikit Image - Using Ploty
- Scikit Image - Using Mayavi
- Scikit Image - Using Napari
- Scikit Image - Color Manipulation
- Scikit Image - Alpha Channel
- Scikit Image - Conversion b/w Color & Gray Values
- Scikit Image - Conversion b/w RGB & HSV
- Scikit Image - Conversion to CIE-LAB Color Space
- Scikit Image - Conversion from CIE-LAB Color Space
- Scikit Image - Conversion to luv Color Space
- Scikit Image - Conversion from luv Color Space
- Scikit Image - Image Inversion
- Scikit Image - Painting Images with Labels
- Scikit Image - Contrast & Exposure
- Scikit Image - Contrast
- Scikit Image - Contrast enhancement
- Scikit Image - Exposure
- Scikit Image - Histogram Matching
- Scikit Image - Histogram Equalization
- Scikit Image - Local Histogram Equalization
- Scikit Image - Tinting gray-scale images
- Scikit Image - Image Transformation
- Scikit Image - Scaling an image
- Scikit Image - Rotating an Image
- Scikit Image - Warping an Image
- Scikit Image - Affine Transform
- Scikit Image - Piecewise Affine Transform
- Scikit Image - ProjectiveTransform
- Scikit Image - EuclideanTransform
- Scikit Image - Radon Transform
- Scikit Image - Line Hough Transform
- Scikit Image - Probabilistic Hough Transform
- Scikit Image - Circular Hough Transforms
- Scikit Image - Elliptical Hough Transforms
- Scikit Image - Polynomial Transform
- Scikit Image - Image Pyramids
- Scikit Image - Pyramid Gaussian Transform
- Scikit Image - Pyramid Laplacian Transform
- Scikit Image - Swirl Transform
- Scikit Image - Morphological Operations
- Scikit Image - Erosion
- Scikit Image - Dilation
- Scikit Image - Black & White Tophat Morphologies
- Scikit Image - Convex Hull
- Scikit Image - Generating footprints
- Scikit Image - Isotopic Dilation & Erosion
- Scikit Image - Isotopic Closing & Opening of an Image
- Scikit Image - Skelitonizing an Image
- Scikit Image - Morphological Thinning
- Scikit Image - Masking an image
- Scikit Image - Area Closing & Opening of an Image
- Scikit Image - Diameter Closing & Opening of an Image
- Scikit Image - Morphological reconstruction of an Image
- Scikit Image - Finding local Maxima
- Scikit Image - Finding local Minima
- Scikit Image - Removing Small Holes from an Image
- Scikit Image - Removing Small Objects from an Image
- Scikit Image - Filters
- Scikit Image - Image Filters
- Scikit Image - Median Filter
- Scikit Image - Mean Filters
- Scikit Image - Morphological gray-level Filters
- Scikit Image - Gabor Filter
- Scikit Image - Gaussian Filter
- Scikit Image - Butterworth Filter
- Scikit Image - Frangi Filter
- Scikit Image - Hessian Filter
- Scikit Image - Meijering Neuriteness Filter
- Scikit Image - Sato Filter
- Scikit Image - Sobel Filter
- Scikit Image - Farid Filter
- Scikit Image - Scharr Filter
- Scikit Image - Unsharp Mask Filter
- Scikit Image - Roberts Cross Operator
- Scikit Image - Lapalace Operator
- Scikit Image - Window Functions With Images
- Scikit Image - Thresholding
- Scikit Image - Applying Threshold
- Scikit Image - Otsu Thresholding
- Scikit Image - Local thresholding
- Scikit Image - Hysteresis Thresholding
- Scikit Image - Li thresholding
- Scikit Image - Multi-Otsu Thresholding
- Scikit Image - Niblack and Sauvola Thresholding
- Scikit Image - Restoring Images
- Scikit Image - Rolling-ball Algorithm
- Scikit Image - Denoising an Image
- Scikit Image - Wavelet Denoising
- Scikit Image - Non-local means denoising for preserving textures
- Scikit Image - Calibrating Denoisers Using J-Invariance
- Scikit Image - Total Variation Denoising
- Scikit Image - Shift-invariant wavelet denoising
- Scikit Image - Image Deconvolution
- Scikit Image - Richardson-Lucy Deconvolution
- Scikit Image - Recover the original from a wrapped phase image
- Scikit Image - Image Inpainting
- Scikit Image - Registering Images
- Scikit Image - Image Registration
- Scikit Image - Masked Normalized Cross-Correlation
- Scikit Image - Registration using optical flow
- Scikit Image - Assemble images with simple image stitching
- Scikit Image - Registration using Polar and Log-Polar
- Scikit Image - Feature Detection
- Scikit Image - Dense DAISY Feature Description
- Scikit Image - Histogram of Oriented Gradients
- Scikit Image - Template Matching
- Scikit Image - CENSURE Feature Detector
- Scikit Image - BRIEF Binary Descriptor
- Scikit Image - SIFT Feature Detector and Descriptor Extractor
- Scikit Image - GLCM Texture Features
- Scikit Image - Shape Index
- Scikit Image - Sliding Window Histogram
- Scikit Image - Finding Contour
- Scikit Image - Texture Classification Using Local Binary Pattern
- Scikit Image - Texture Classification Using Multi-Block Local Binary Pattern
- Scikit Image - Active Contour Model
- Scikit Image - Canny Edge Detection
- Scikit Image - Marching Cubes
- Scikit Image - Foerstner Corner Detection
- Scikit Image - Harris Corner Detection
- Scikit Image - Extracting FAST Corners
- Scikit Image - Shi-Tomasi Corner Detection
- Scikit Image - Haar Like Feature Detection
- Scikit Image - Haar Feature detection of coordinates
- Scikit Image - Hessian matrix
- Scikit Image - ORB feature Detection
- Scikit Image - Additional Concepts
- Scikit Image - Render text onto an image
- Scikit Image - Face detection using a cascade classifier
- Scikit Image - Face classification using Haar-like feature descriptor
- Scikit Image - Visual image comparison
- Scikit Image - Exploring Region Properties With Pandas
Scikit Image - Histogram of Oriented Gradients
Histogram of Oriented Gradients, commonly known as HOG, is a widely used image feature descriptor in the field of image processing and computer vision tasks, particularly in the context of object detection. It involves counting occurrences of gradient orientation within localized segments of an image.
The process of computing a Histogram of Oriented Gradients (HOG) descriptors involves several stages −
Global Image Normalization (Optional): As an initial step, there's an optional global image normalization process aimed at reducing the influence of illumination effects. This often involves gamma (power law) compression, such as computing the square root or logarithm of each color channel. This step helps reduce the influence of local shadowing and illumination variations.
Computing the gradient image in x and y: The second stage involves computing first-order image gradients. These gradients capture information related to contours, silhouettes, and some texture details, while also enhancing resistance to variations in illumination.
Computing gradient histograms: The third stage aims to create an encoding sensitive to local image content while remaining robust to minor changes in pose or appearance. This is achieved by pooling gradient orientation information locally in the same way as the SIFT feature. The image is divided into smaller spatial regions known as "cells." For each cell, a local 1-D histogram of gradient or edge orientations is computed using all the pixels within the cell. These individual cell-level histograms collectively form the fundamental "orientation histogram" representation. Each orientation histogram divides the range of gradient angles into a fixed number of predefined bins. The gradient magnitudes of pixels within the cell are used to contribute to the orientation histogram.
Normalising across blocks: In the fourth stage, normalization is applied to enhance invariance to illumination, shadowing, and edge contrast. It's performed by measuring local histogram "energy" over groups of cells known as "blocks" and then normalizing each cell within the block. Each individual cell might be shared across multiple blocks, but its normalizations vary from block to block. As a result, the same cell appears multiple times in the final output vector with different normalizations. This may seem redundant but it improves the performance, and these normalized block descriptors are referred to as Histogram of Oriented Gradient (HOG) descriptors.
Flattening into a feature vector: Finally, HOG descriptors from all blocks in a dense, overlapping grid covering the detection window are combined into a feature vector, which is then used in window classification.
Using the skimage.feature.hog() function
The Scikit-Image provides a flexible implementation of the Histogram of Oriented Gradient (HOG) algorithm with the skimage.feature.hog() function, allowing users to compute HOG features for images with customization options.
Syntax
skimage.feature.hog(image, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(3, 3), block_norm='L2-Hys', visualize=False, transform_sqrt=False, feature_vector=True, *, channel_axis=None)
Parameters
image ((M, N[, C]) ndarray): Input image for which HOG features are computed.
orientations (int, optional): The number of orientation bins.
pixels_per_cell (2-tuple (int, int), optional): The size of a cell in pixels.
cells_per_block (2-tuple (int, int), optional): The number of cells in each block.
-
block_norm (str {'L1', 'L1-sqrt', 'L2', 'L2-Hys'}, optional): Specifies the block normalization method. Options include −
'L1': Normalization using L1-norm.
'L1-sqrt': Normalization using L1-norm, followed by square root.
'L2': Normalization using L2-norm.
'L2-Hys' (default): Normalization using L2-norm, followed by limiting the maximum values to 0.2 (Hys stands for hysteresis) and renormalization using L2-norm.
visualize (bool, optional): If set to True, it returns an image of the HOG features. This image shows line segments for each cell and orientation bin, with intensities proportional to the corresponding histogram values.
transform_sqrt (bool, optional): If set to True, it applies power-law compression to normalize the image before processing. If the image contains negative values then it is recommended to DO NOT use this parameter.
feature_vector (optional): If set to True, it returns the data as a feature vector by calling .ravel() on the result just before returning.
channel_axis (optional): Indicates which axis of the array corresponds to channels in the case of multi-channel images. If None, the image is assumed to be a grayscale (single channel) image.
The function returns two outputs −
Out (n_blocks_row, n_blocks_col, n_cells_row, n_cells_col, n_orient) ndarray: An ndarray representing the HOG descriptor for the image. The shape depends on the parameters and can be multi-dimensional if not flattened. If feature_vector is set to True, a 1D (flattened) array is returned.
hog_image ((M, N) ndarray, optional): An ndarray representing a visualization of the HOG image. This is provided only if visualize is set to True.
Example
Here's an example of how to use the skimage.feature.hog function to compute the Histogram of Oriented Gradients (HOG) features for a color image.
import numpy as np from skimage import io, feature import matplotlib.pyplot as plt # Load the input image image = io.imread('Images/hand writting.jpg') # Compute HOG features hog_features, hog_image = feature.hog(image, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(3, 3), visualize=True, channel_axis=-1) # Display the original and resultant images fig, axes = plt.subplots(1, 2, figsize=(10, 8)) ax = axes.ravel() ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Original Image') ax[0].axis('off') # Display the HOG visualization ax[1].imshow(hog_image, cmap=plt.cm.gray) ax[1].set_title('HOG Visualization') ax[1].axis('off') plt.show() # display the shaope of computed HOG features print("Shape of HOG features:", hog_features.shape)
Output

Example
Let's take a different input image and use the feature.hog() function to calculate the Histogram of Oriented Gradients (HOG) features.
import matplotlib.pyplot as plt from skimage.feature import hog from skimage import io, exposure # Load an input image image = io.imread('Images/logo.jpg') # Compute HOG features with specified parameters fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualize=True, channel_axis=-1) # Create a figure with two subplots fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 8), sharex=True, sharey=True) # Display the input image 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)) # Display the HOG image ax2.axis('off') ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray) ax2.set_title('Histogram of Oriented Gradients') plt.show()
Output
