Skip to content

Commit

Permalink
fixed mixed indents in demo file
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesBuchner committed Feb 1, 2017
1 parent b1237cf commit 32d3d9b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions find_similar_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
def find_similar_images(userpath, hashfunc = imagehash.average_hash):
import os
def is_image(filename):
f = filename.lower()
return f.endswith(".png") or f.endswith(".jpg") or \
f.endswith(".jpeg") or f.endswith(".bmp") or f.endswith(".gif")
f = filename.lower()
return f.endswith(".png") or f.endswith(".jpg") or \
f.endswith(".jpeg") or f.endswith(".bmp") or f.endswith(".gif")

image_filenames = [os.path.join(userpath, path) for path in os.listdir(userpath) if is_image(path)]
images = {}
for img in sorted(image_filenames):
hash = hashfunc(Image.open(img))
images[hash] = images.get(hash, []) + [img]
hash = hashfunc(Image.open(img))
images[hash] = images.get(hash, []) + [img]

for k, img_list in six.iteritems(images):
if len(img_list) > 1:
print(" ".join(img_list))
if len(img_list) > 1:
print(" ".join(img_list))


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.
Expand All @@ -42,21 +42,21 @@ def usage():
(C) Johannes Buchner, 2013
""" % sys.argv[0])
sys.exit(1)
sys.exit(1)

hashmethod = sys.argv[1] if len(sys.argv) > 1 else usage()
if hashmethod == 'ahash':
hashfunc = imagehash.average_hash
hashfunc = imagehash.average_hash
elif hashmethod == 'phash':
hashfunc = imagehash.phash
hashfunc = imagehash.phash
elif hashmethod == 'dhash':
hashfunc = imagehash.dhash
hashfunc = imagehash.dhash
elif hashmethod == 'whash-haar':
hashfunc = imagehash.whash
hashfunc = imagehash.whash
elif hashmethod == 'whash-db4':
hashfunc = lambda img: imagehash.whash(img, mode='db4')
hashfunc = lambda img: imagehash.whash(img, mode='db4')
else:
usage()
usage()
userpath = sys.argv[2] if len(sys.argv) > 2 else "."
find_similar_images(userpath=userpath, hashfunc=hashfunc)

Expand Down

0 comments on commit 32d3d9b

Please sign in to comment.