Overview
BoVW (Bag of Visual Words) implements local feature-based hashing using ORB-like or AKAZE-like keypoint descriptors. It extracts local binary descriptors and represents them as either a normalized histogram, MinHash signature, or SimHash bit-signature. This algorithm is ideal for:- Object recognition and matching
- Finding images containing similar local features
- Partial image matching (finds similar regions)
- Handling occlusions and local transformations
BoVW can return Float64 (Histogram/MinHash) or Binary (SimHash) hash types depending on storage configuration.
How It Works
- Resize: Image is resized to the specified dimensions (default: 256×256)
- Feature Detection: Detects keypoints using ORB or AKAZE
- ORB: FAST corner detector with orientation
- AKAZE: Multi-scale Hessian detector
- Descriptor Extraction: Computes binary descriptors at each keypoint
- ORB: BRIEF-like 256-bit descriptors
- AKAZE: 256-bit oriented descriptors
- Visual Words: Maps descriptors to visual vocabulary (hash-based bucketing)
- Representation: Creates final hash based on storage type:
- Histogram: L2-normalized word frequency vector
- MinHash: Locality-sensitive signature for set similarity
- SimHash: Bit signature for approximate matching
Constructor
Available Options
WithSize(width, height uint)- Set resize dimensions (default: 256×256)WithInterpolation(interp Interpolation)- Set interpolation method (default: Bilinear)WithBoVWFeature(feature BoVWFeatureType)- Set feature detector (default: BoVWORB)WithBoVWStorage(storage BoVWStorageType)- Set storage type (default: BoVWHistogram)WithVocabularySize(size uint)- Set visual vocabulary size (default: 256)WithMaxKeypoints(count uint)- Set maximum keypoints (default: 500)WithMinHashSize(size uint)- Set MinHash signature size (default: 64)WithSimHashBits(bits uint)- Set SimHash bit length (default: 128)WithDistance(fn DistanceFunc)- Override default distance function
Feature Types
imghash.BoVWORB- ORB-like FAST + BRIEF pipeline (default)imghash.BoVWAKAZE- AKAZE-like Hessian detector with binary descriptors
Storage Types
imghash.BoVWHistogram- Normalized histogram (Float64, Cosine distance)imghash.BoVWMinHash- MinHash signature (Float64, Jaccard distance)imghash.BoVWSimHash- SimHash bit-signature (Binary, Jaccard distance)
Usage Examples
Histogram Storage (Default)
MinHash Storage
SimHash Storage
Helper Function
Default Settings
Image resize width
Image resize height
Resize interpolation method
Local feature detector (BoVWORB or BoVWAKAZE)
Storage representation (BoVWHistogram, BoVWMinHash, or BoVWSimHash)
Visual vocabulary size (must be > 0)
Maximum number of keypoints to detect (must be > 0)
MinHash signature size (must be > 0, used when storageType = BoVWMinHash)
SimHash bit length (must be > 0, used when storageType = BoVWSimHash)
Hash Type
Depends on storage type:- BoVWHistogram:
hashtype.Float64with size =vocabularySize - BoVWMinHash:
hashtype.Float64with size =minHashSize - BoVWSimHash:
hashtype.Binarywith size =simHashBitsbits
Distance Metrics
Default comparison varies by storage type:- BoVWHistogram: Cosine distance (lower = more similar)
- BoVWMinHash: Jaccard distance (estimates set similarity)
- BoVWSimHash: Jaccard distance (binary similarity)
WithDistance().
Feature Detector Comparison
BoVWORB
- FAST corner detector
- Faster computation
- Good for textured images
- Orientation-compensated BRIEF
BoVWAKAZE
- Multi-scale Hessian detector
- More robust features
- Better for blob-like structures
- Scale-space analysis
Storage Type Comparison
Histogram
- Most accurate
- Larger hash size
- Cosine similarity
- Best for quality
MinHash
- Compact Float64
- Approximate matching
- Good speed/quality
- Jaccard estimation
SimHash
- Binary hash
- Smallest size
- Fastest comparison
- Good for large scale
Performance Tuning
Vocabulary Size:- Smaller (128-256): Faster, less discriminative
- Larger (512-1024): More discriminative, slower, larger hash
- Fewer (100-500): Faster detection, may miss features
- More (1000+): Better coverage, slower
- Smaller (128×128): Faster, fewer features
- Larger (512×512): More features, better quality, slower