Overview
HOGHash is a perceptual hash algorithm based on Histogram of Oriented Gradients (HOG), a feature descriptor widely used in computer vision for object detection and recognition. It captures the distribution of gradient orientations in an image, making it effective for shape-based similarity.How It Works
The HOGHash algorithm processes images through the following steps:- Preprocessing: The image is resized and converted to grayscale
- Gradient computation: For each pixel, compute:
- Gradient magnitude: √(gx² + gy²)
- Gradient orientation: atan2(gy, gx) mapped to 0-180° (unsigned)
- Cell division: The image is divided into square cells of specified size
- Histogram computation: For each cell:
- Build an orientation histogram with specified number of bins (0-180°)
- Weight each gradient by its magnitude
- Normalization: Each cell histogram is normalized (0-255 range)
- Concatenation: All cell histograms are concatenated into a single descriptor
HOGHash returns a UInt8 hash type with size = (width/cellSize) × (height/cellSize) × numBins bytes.
When to Use HOGHash
HOGHash is particularly effective for:- Object detection and recognition
- Shape-based image similarity
- Pedestrian detection
- Logo and icon matching
- Structure and contour matching
- Images where edge orientation is discriminative
- Color-based matching (uses grayscale only)
- Texture without directional structure
- Images with very uniform regions
Constructor
Options
Sets the resize dimensions before hash computation. The image is resized to this size before processing.Default: 256×256 pixels
Sets the interpolation method used when resizing the image.Default:
BilinearAvailable options: NearestNeighbor, Bilinear, Bicubic, LanczosSets the cell size in pixels (square cells) for HOG computation.Default: 8 pixelsSmaller cells capture finer details but produce longer hashes.
Sets the number of orientation histogram bins (0-180°).Default: 9 bins (20° per bin)More bins provide finer orientation resolution but increase hash size.
Overrides the default distance function used by the
Compare method.Default: similarity.CosineAvailable functions: Hamming, L1, L2, Cosine, ChiSquare, PCC, JaccardUsage Example
Default Settings
| Parameter | Default Value |
|---|---|
| Width | 256 pixels |
| Height | 256 pixels |
| Interpolation | Bilinear |
| Cell Size | 8 pixels |
| Number of Bins | 9 bins |
| Distance Function | Cosine |
| Hash Length | 2,304 bytes (32×32 cells × 9 bins) |
Technical Details
- Hash Type:
hashtype.UInt8 - Hash Length: (width/cellSize) × (height/cellSize) × numBins bytes
- Default Comparison: Cosine distance
- Color Processing: Converted to grayscale
- Gradient Method: Central differences
- Orientation Range: 0-180° (unsigned gradients)
- Magnitude Weighting: Histograms weighted by gradient magnitude
- Normalization: Per-cell normalization to 0-255 range
Configuration Examples
| Image Size | Cell Size | Bins | Hash Length | Use Case |
|---|---|---|---|---|
| 256×256 | 8 | 9 | 2,304 bytes | Default, general purpose |
| 256×256 | 16 | 9 | 576 bytes | Faster, coarser features |
| 256×256 | 4 | 9 | 9,216 bytes | Detailed, fine features |
| 256×256 | 8 | 18 | 4,608 bytes | Finer orientation resolution |
References
- Dalal, N., & Triggs, B. (2005). “Histograms of Oriented Gradients for Human Detection.” IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR).
- IEEE Xplore