Skip to content

Commit

Permalink
fix issue #28: dhash should compute horizontally. Version bump to 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesBuchner committed Sep 1, 2016
1 parent fce6768 commit 9777d09
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ Source hosted at github: https://github.com/JohannesBuchner/imagehash
.. _wHash: https://fullstackml.com/2016/07/02/wavelet-image-hash-in-python/
.. _pypi: https://pypi.python.org/pypi/ImageHash

Changelog
----------

* 3.0: dhash had a bug: It computed pixel differences vertically, not horizontally.
I modified it to follow `dHash`_. The old function is available as dhash_vertical.

* 2.0: added whash

* 1.0: initial ahash, dhash, phash implementations.



18 changes: 18 additions & 0 deletions imagehash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ def dhash(image, hash_size=8):
Difference Hash computation.
following http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
computes differences horizontally
@image must be a PIL instance.
"""
image = image.convert("L").resize((hash_size, hash_size + 1), Image.ANTIALIAS)
pixels = numpy.array(image.getdata(), dtype=numpy.float).reshape((hash_size + 1, hash_size))
# compute differences
diff = pixels[:, 1:] > pixels[:, :-1]
return ImageHash(diff)

def dhash_vertical(image, hash_size=8):
"""
Difference Hash computation.
following http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
computes differences vertically
@image must be a PIL instance.
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='ImageHash',
version='2.2',
version='3.0',
author='Johannes Buchner',
author_email='[email protected]',
packages=['imagehash'],
Expand Down

0 comments on commit 9777d09

Please sign in to comment.