Advertisement
Guest User

A script to compare two batches of frames for avg pxl delta

a guest
Aug 29th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. from PIL  import Image
  2. from math import sqrt
  3.  
  4. orig = "00"
  5. diff = "02"
  6.  
  7. # could be helpful
  8. def padString(leng, char, orig):
  9.     while (len(str(orig)) < int(leng)):
  10.         orig = str(char) + str(orig)
  11.    
  12.     return str(orig)
  13.  
  14. # calculating 3D distance between two color tuples
  15. def calcDist(start, end):
  16.     r = (start[0] - end[0]) * (start[0] - end[0])
  17.     g = (start[1] - end[1]) * (start[1] - end[1])
  18.     b = (start[2] - end[2]) * (start[2] - end[2])
  19.    
  20.     sum = r + g + b
  21.    
  22.     return sqrt(sum)
  23.  
  24.  
  25. # we'll just go ahead and stash total distance here
  26. totalDistance = 0
  27.  
  28. # let's do a thing
  29. for index in range(1, 210):
  30.     # pad index out so it's not useless
  31.     indStr = padString(3, 0, index)
  32.    
  33.     # output our index
  34.     print("Now working index " + indStr)
  35.    
  36.     # open two images as, well, images
  37.     origPic = Image.open(orig + "/" + indStr + ".png")
  38.     diffPic = Image.open(diff + "/" + indStr + ".png")
  39.    
  40.     # current distCount
  41.     distCount = 0.0
  42.    
  43.     # iterate over the image body
  44.     for x in range(0, origPic.size[0]):
  45.         for y in range(0, origPic.size[1]):
  46.             # get colors
  47.             origColor = origPic.getpixel((x, y))
  48.             diffColor = diffPic.getpixel((x, y))
  49.  
  50.             # add curDist
  51.             distCount += calcDist(origColor, diffColor)
  52.            
  53.     # add a reduced distCount to totalDistance
  54.     totalDistance += (distCount/(origPic.size[0]*origPic.size[1]))
  55.    
  56.     # print totalDistance
  57.     print("Running average distance : " + str(round(totalDistance/(index), 5)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement