Advertisement
Kappei

histogram.py

Jan 13th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. from PIL import Image
  2. import os
  3. import math, operator
  4.  
  5. for root_n, dirs_n, filenames_n in os.walk('noisy'):
  6. for f_n in filenames_n:
  7. if f_n <> ".DS_Store":
  8. path_n = os.path.join(root_n, f_n)
  9. noisy = Image.open(path_n,'r')
  10. noisy_hist = noisy.histogram()
  11. for root, dirs, filenames in os.walk('covers'):
  12. for f in filenames:
  13. if f <> ".DS_Store":
  14. path = os.path.join(root, f)
  15. cover = Image.open(path,'r')
  16. cover_hist = cover.histogram()
  17. rms = math.sqrt(reduce(operator.add,map(lambda a,b: (a-b)**2, noisy_hist, cover_hist))/len(noisy_hist))
  18. if rms == 0.0:
  19. print("%s %s" % (f_n,f))
  20. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement