What is a dHash ?
dHash, short for difference hash, is a fast and efficient way to detect whether two images look alike even if they’re not exactly the same. Instead of comparing images pixel by pixel, dHash creates a unique digital fingerprint by analysing how the brightness of pixels changes across an image. This makes it ideal for spotting near-duplicates, such as resized, compressed, or slightly edited versions of the same photo.
How it Works
Simplifies the Image
The image is resized to a small, fixed size (typically 9×8 pixels) and converted to black and white. This strips out unnecessary detail and focuses on structure.
Compares Adjacent Pixels
It then checks if each pixel is brighter or darker than its neighbour. These results are stored as a sequence of 1s and 0s — creating a 64-bit fingerprint of the image.
Checks for Similarity
Two images are compared by measuring the difference between their hashes. The fewer the differences, the more visually similar they are.
Many major platforms use dHash or similar perceptual hashing to detect duplicate or altered images. Companies like Google, Meta (Facebook, Instagram), Microsoft, Pinterest, and Reddit rely on it for content moderation, reverse image search, and repost detection. Ecommerce platforms like Amazon and eBay use it to flag duplicate product images and fight fraud. It’s also widely used in photo management apps, digital forensics, and open-source tools like ImageHash and dupeGuru for fast, reliable image comparison.
dHashBreaker – Anti Perceptual Hash Image Modifier
script_dhash is an open-source Python script and windows exe created by cfernpra that helps you quickly compare images based on how they look, not just their file data.
It uses the difference hash (dHash) algorithm — a lightweight, perceptual hashing method that transforms images into 64-bit hashes based on brightness changes between adjacent pixels. This makes it excellent for detecting near-duplicate images that may have been resized, compressed, or slightly edited.
How It Works
- The script converts images to grayscale and resizes them to a small, fixed size.
- It compares each pixel with its neighbour and stores the brightness relationship as binary values.
- It outputs a 64-bit hash for each image.
- It then calculates the Hamming distance between hashes to measure similarity — the lower the distance, the more visually similar the images.
Download dhash
Get the latest version of the script_dhash image comparison script directly from Here.
