Giter Site home page Giter Site logo

experhash's Introduction

ExPerHash

Perceptual hashing for images. Implemented as a C++ program connected to Elixir via a port.

##Installation

Requires Magick++, the ImageMagick C++ API. Check your package manager or the ImageMagick downloads page.

For use in a mix project, add ExPerHash to the mix.exs dependencies:

def deps do
  [{:experhash, github: "kemonomachi/experhash"}]
end

Download by using:

$ mix deps.get

Run mix compile to build both the Elixir and the C++ code.

##Usage

iex> {:ok, srv} = ExPerHash.start_link
{:ok, #PID<0.91.0>}

iex> {:ok, hash1} = ExPerHash.dd_hash srv, "some/image.png"
{:ok, <<140, 173, 167, 143, 157, 141, 14, 39, 77, 9, 3, 135, 23, 49, 25, 89>>}

iex> {:ok, hash2} = ExPerHash.dd_hash srv, "some/other/image.png"
{:ok, <<140, 173, 167, 143, 157, 141, 14, 39, 77, 9, 0, 135, 23, 49, 25, 89>>}

iex> ExPerHash.hamming_distance srv, hash1, hash2
{:ok, 2}

Three hash functions are available: aHash, dHash and ddHash.

aHash by dr. Neal Krawitz creates a hash based on the average of the low frequencies of an image.

dHash by dr. Neal Krawitz and David Oftedal tracks gradients instead. In this variant, images are resized to 8x8 pixels and each row wraps around to the next, with the last row wrapping around to the first. Hash bits are set in order from left to right (most significant to least significant).

ddHash is a double dHash, one row-wise and one column-wise.

All hash functions return {:ok, hash} on success, where hash is a binary. For aHash and dHash, the hash is 64 bits (8 bytes), for ddHash it is 128 bits (16 bytes).

On error, all functions return {:error, {error_type, reason}.

The hamming_distance/3 function compares two hashes and return the number of bits that differ. Low distance means similar images.

##License

Copyright © 2015 Ookami Kenrou <[email protected]>

This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the LICENSE file or the WTFPL homepage for more details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.