Chris Pickett

PhotoHash

PhotoHash

A pure python implementation of a perceptual hashing algorithm.

Installation

pip install PhotoHash

Usage

average_hash

Returns the hash of the image using an average hash algorithm. This algorithm compares each pixel in the image to the average value of all the pixels.:

import photohash
hash = photohash.average_hash(
    '/path/to/myimage.jpg'
)
print hash  # prints 'ffffbbeff5055208'

distance

Returns the hamming distance between the average_hash of the given images.:

import photohash
distance = photohash.distance(
    '/path/to/myimage.jpg',
    '/path/to/myotherimage.jpg'
)
print distance  # prints 4

is_look_alike

Returns a boolean of whether or not the photos look similar.:

import photohash
similar = photohash.is_look_alike(
    '/path/to/myimage.jpg',
    '/path/to/myotherimage.jpg'
)
print similar  # prints True

is_look_alike also takes an optional tolerance argument that defines how strict the comparison should be, where 0 will only return true if the image is exactly the same and 16 will always return true.

import photohash
similar = photohash.is_look_alike(
    '/path/to/myimage.jpg',
    '/path/to/myotherimage.jpg',
    tolerance=3
)
print similar  # prints False

TODO

Recent Commits

Comments

comments powered by Disqus