Skip to content

Instantly share code, notes, and snippets.

@dmpetrov
Created March 6, 2017 04:39
Show Gist options
  • Save dmpetrov/f96ea73a95be1ff93f2f5af7850ba614 to your computer and use it in GitHub Desktop.
Save dmpetrov/f96ea73a95be1ff93f2f5af7850ba614 to your computer and use it in GitHub Desktop.
Wavelet imagehash for Lenna image
# Code for the blogpost https://fullstackml.com/2016/07/02/wavelet-image-hash-in-python/
import PIL
from PIL import Image
import imagehash
w = imagehash.whash(PIL.Image.open(‘lenna.png’))
w1 = imagehash.whash(PIL.Image.open(‘lenna1.jpg’))
w2 = imagehash.whash(PIL.Image.open(‘lenna2.jpg’))
(w — w1)/len(w.hash)**2
# > 0.03125
(w — w2)/len(w.hash)**2
# > 0.28125
@CyberShadow
Copy link

CyberShadow commented Jan 5, 2019

FYI, the code seems to have been smartypants'd OSLT (Unicode quotes, dashes and whitespace instead of ASCII characters).

Fixed:

# Code for the blogpost https://fullstackml.com/2016/07/02/wavelet-image-hash-in-python/
import PIL
from PIL import Image
import imagehash

w = imagehash.whash(PIL.Image.open('lenna.png'))
w1 = imagehash.whash(PIL.Image.open('lenna1.jpg'))
w2 = imagehash.whash(PIL.Image.open('lenna2.jpg'))

(w - w1)/len(w.hash)**2
# > 0.03125

(w - w2)/len(w.hash)**2
# > 0.28125

Thanks for the article.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment