An implementation of perceptual hash in Nim language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Crystal Melting Dot 3824b62939
make HASH_SIZE an intdefine
12 months ago
demo Update readme and documentation 12 months ago
src make HASH_SIZE an intdefine 12 months ago
tests More precise test description in RGBAHash tests 12 months ago
.gitignore Update readme and documentation 12 months ago
LICENSE initial commit 2 years ago Update readme 12 months ago
alike.nimble bump version 12 months ago
config.nims ??? 12 months ago
gendoc Update readme and documentation 12 months ago


A nim implementation of preceptual image hash. Useful when searching for duplicate or similar pictures.

How it works

Simple algorithm:

  1. Get a small grayscale square image from original by scaling it
  2. Compute average image brightness
  3. Compare each pixel against average image brightness
  4. Write the result into bit array where 1 is 'brighter' and 0 is 'darker'
  5. Voila! We got the hash.

RGBA is basically simple algoritm x 4 for each channel.

Computing the difference is basically counting different bits in two hashes.


  1. Get source code by cloning this repository or downloading as zip
  2. Open directory where the source code is in terminal and run nimble build (yeah, you'll need to have nimble installed first)
  3. After successful build the binaries will be in ./bin folder, you can run them




   [options] COMMAND


  compare2         Compare 2 image files
  hash             Compute hash for image file

  -h, --help
  -a, --algorithm=ALGORITHM  Algorithm to use for hash computation Possible values: [simple, rgba] (default: rgba)


Alike can be used as a library. See full API reference.

Example usage:

import pixie
import alike

  img1 = readImage("img1.png")
  img2 = readImage("img2.png")

echo img1.getRGBAImgHash.diff(img2.getRGBAImgHash)