Skip to main content

A lightweight Python library for perceptual image hashing, currently providing pHash with an extensible design.

Project description

RetinaHash

Lightweight, pure-NumPy perceptual hashing for images

RetinaHash computes compact, rotation-invariant fingerprints of images using only NumPy...no OpenCV, no PIL, no Scipy.
Perfect for duplicate detection, near-duplicate search, and lightweight image clustering.

Features

  • Pure NumPy – runs anywhere Python runs
  • Rotation invariant – same hash for 0°, 90°, 180°, 270° rotations
  • Auto-crop – strips solid scanner borders automatically
  • Extensible – plug-in architecture for new hash algorithms
  • Fast – ~1 ms per 512×512 image on a laptop CPU (TRUST ME BRO Benchmark, lol.)

Install

pip install retinahash

Or better, because you are sane and use uv to manage your projects:

uv add retinahash

(or drop the retinahash/ folder into your project—zero dependencies beyond NumPy).

Quick Start

import imageio.v3 as iio          # any loader will do but numpy array is expected
from retinahash import RetinaHash

img = iio.imread("photo.jpg")
h   = RetinaHash.phash(img, rotation_invariant=True)
print(h)        # 16-char hex string, e.g. 'a5f3c1e8d2b4906e'

Compare two images (via Hamming distance):

h1 = RetinaHash.phash(img1)
h2 = RetinaHash.phash(img2)
distance = RetinaHash.distance(h1, h2)

API

RetinaHash.hash(image, method='phash', hash_size=8, rotation_invariant=False, auto_crop=False)
RetinaHash.phash(image, **kwargs) – convenience wrapper
RetinaHash.distance(hex1, hex2) – Hamming distance between two hex hashes

Algorithms

Key Description
phash DCT-based perceptual hash (default)

More algorithms (ahash, dhash, whash, …) can be added by dropping a new module into retinahash/strategies/ and registering it in STRATEGIES.

Customisation

# 16-bit hash, auto-crop on, rotation invariant
h = RetinaHash.hash(img, method='phash', hash_size=16,
                    auto_crop=True, rotation_invariant=True)

License

MIT – do what you want, just keep the copyright notice.


That’s it—clone, hash, dedupe.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

retinahash-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

retinahash-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file retinahash-0.1.0.tar.gz.

File metadata

  • Download URL: retinahash-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for retinahash-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eb290a96257d25672fc9901919c6dfb0c82a2862041c7045d08846dbaf6f78c8
MD5 12428e2f2f76b94ebe2616cacaffc530
BLAKE2b-256 89cf3019b955e4a788f0fc0030662d37d193438d92bfd134148f078d741ace65

See more details on using hashes here.

File details

Details for the file retinahash-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: retinahash-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for retinahash-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1737039d667d774c2e34d2020fcf189b647c3795e8647a8f85691c6c99e8c1e
MD5 e4de45c9e63eda9f6946daee1c2c784c
BLAKE2b-256 5ee08e5c07b524891ca07b019879301c4f6798734466e2dc897ecc0405c6e285

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page