Skip to content

Instantly share code, notes, and snippets.

@agasiev
Created April 7, 2014 11:17
Show Gist options
  • Save agasiev/10018483 to your computer and use it in GitHub Desktop.
Save agasiev/10018483 to your computer and use it in GitHub Desktop.
Python PIL aHash implementation.
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