Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

This is the second image that we will be using

And the following image is the third:

How to do it…

  1. Import the phash library as follows:

    import Data.PHash
    import Data.Maybe (fromJust, isJust)
  2. Hash an image as follows:

    main = do
      phash1 <- imageHash "image1.jpg"
      putStrLn $ "image1: " ++ show phash1
  3. Hash a similar image as follows:

      phash2 <- imageHash "image2.jpg"
        putStrLn $ "image2: " ++ show phash2
  4. Hash a slightly different image as follows...