Skip to content

Instantly share code, notes, and snippets.

@clofresh
Created December 3, 2008 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clofresh/31417 to your computer and use it in GitHub Desktop.
Save clofresh/31417 to your computer and use it in GitHub Desktop.
import Image
from numpy import average, linalg, dot
import sys
images = sys.argv[1:3]
vectors = []
norms = []
for image in images:
vector = []
for pixel_tuple in Image.open(image).getdata():
vector.append(average(pixel_tuple))
vectors.append(vector)
norms.append(linalg.norm(vector, 2))
a, b = vectors
a_norm, b_norm = norms
print dot(a / a_norm, b / b_norm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment