Skip to content

Commit

Permalink
version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesBuchner committed Jun 27, 2016
1 parent e4ecab7 commit f6ddd13
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
*.pyc
env
*.jpg
build
dist
ImageHash.egg-info/
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A image hashing library written in Python. ImageHash supports:
* average hashing (`aHash`_)
* perception hashing (`pHash`_)
* difference hashing (`dHash`_)
* wavelet hashing (`wHash`_)

Requirements
-------------
Expand Down Expand Up @@ -36,6 +37,7 @@ Source hosted at github: https://github.com/JohannesBuchner/imagehash
.. _aHash: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
.. _pHash: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
.. _dHash: http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
.. _wHash: https://www.kaggle.com/c/avito-duplicate-ads-detection/
.. _pypi: https://pypi.python.org/pypi/ImageHash


14 changes: 10 additions & 4 deletions find_similar_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ def is_image(filename):
if __name__ == '__main__':
import sys, os
def usage():
sys.stderr.write("""SYNOPSIS: %s [ahash|phash|dhash] [<directory>]
sys.stderr.write("""SYNOPSIS: %s [ahash|phash|dhash|...] [<directory>]
Identifies similar images in the directory.
Method:
ahash: Average hash
phash: Perceptual hash
dhash: Difference hash
ahash: Average hash
phash: Perceptual hash
dhash: Difference hash
whash-haar: Haar wavelet hash
whash-db4: Daubechies wavelet hash
(C) Johannes Buchner, 2013
""" % sys.argv[0])
Expand All @@ -46,6 +48,10 @@ def usage():
hashfunc = imagehash.phash
elif hashmethod == 'dhash':
hashfunc = imagehash.dhash
elif hashmethod == 'whash-haar':
hashfunc = imagehash.whash
elif hashmethod == 'whash-db4':
hashfunc = lambda img: imagehash.whash(img, mode='db4')
else:
usage()
userpath = sys.argv[2] if len(sys.argv) > 2 else "."
Expand Down
5 changes: 4 additions & 1 deletion imagehash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def dhash(image, hash_size=8):
def whash(image, hash_size = 8, image_scale = None, mode = 'haar', remove_max_haar_ll = True):
"""
Wavelet Hash computation.
based on https://www.kaggle.com/c/avito-duplicate-ads-detection/
@image must be a PIL instance.
@hash_size must be a power of 2 and less than @image_scale.
Expand All @@ -176,7 +178,7 @@ def whash(image, hash_size = 8, image_scale = None, mode = 'haar', remove_max_ha
@remove_max_haar_ll - remove the lowest low level (LL) frequency using Haar wavelet.
"""

if image_scale != None:
if image_scale is not None:
assert image_scale == int(2**image_scale), "image_scale is not power of 2"
else:
image_scale = 2**int(numpy.log2(min(image.size)))
Expand Down Expand Up @@ -206,3 +208,4 @@ def whash(image, hash_size = 8, image_scale = None, mode = 'haar', remove_max_ha
med = numpy.median(dwt_low)
diff = dwt_low > med
return ImageHash(diff)

7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='ImageHash',
version='1.0',
version='2.0',
author='Johannes Buchner',
author_email='[email protected]',
packages=['imagehash'],
Expand All @@ -19,9 +19,10 @@
description='Image Hashing library',
long_description=long_description,
install_requires=[
"scipy",
"numpy",
"pillow", # or PIL
"scipy", # for phash
"pillow", # or PIL
"PyWavelets", # for whash
],
)

0 comments on commit f6ddd13

Please sign in to comment.