Grayphash is unstable simple gem for some functions from pHash library.
- CImg library
- Imagemagick for more stability
How to get
sudo apt-get install cimg-dev sudo gem install grayphash
Compiling can take some minutes (0.5 - 2 minutes): slow CImg is slow.
You can use MinGW (it's just in ruby kit for windows). You also need Imagemagick if you want to use this gem.
And you need big library file CImg.h (just find it and copy to
How to use
Calculcate perceptive hash for image:
require 'grayphash' phash = Grayphash.phash('./pics/1.jpg') # => 16162904659988308473 phash = phash('./pics/1.jpg') # => 16162904659988308473
a = './pics/3.jpg' b = './pics/4.jpg' similarity = 1 - Grayphash.hamming(phash(a), phash(b)).to_f / 64 # => 0.90625
How it works
Grayphash is small ruby module which contains some methods from pHash library.
about()# returns info string about version.
phash(image_path)# calculate 64-bits perceptive hash for image.
hamming(hash1, hash2)# returns hamming distance between two numbers.