Measuring image similarity with perceptual hashes

A perceptual hash produces a small digest from an image file where slight changes in the images only produce a slight change in the hash. This can be useful to quickly compare thousands of images.

Getting ready

Install the pHash library from www.phash.org. On a Debian-based system, we can install it by using apt-get as follows:

$ sudo apt-get install libphash0-dev

Install the phash library from Cabal as follows:

$ cabal install phash

Find three nearly identical images. We will use the following image:

Getting ready

This is the second image that we will be using

And the following image is the third:

How to do it…

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.