Created
April 7, 2014 11:17
-
-
Save agasiev/10018483 to your computer and use it in GitHub Desktop.
Python PIL aHash implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Image | |
img = Image.open("lenna.png") | |
img = img.resize((8, 8)) | |
img = img.convert('L') | |
pixels = img.load() | |
avg = 0 | |
result = 0 | |
for y in range(8): | |
for x in range(8): | |
avg += pixels[x, y] | |
avg = avg / 64 | |
for y in range(8): | |
for x in range(8): | |
result = (result << 1) | 1 if pixels[x, y] <= avg else result << 1 | |
print("Hash: %x" % result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment