Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- from math import sqrt
- orig = "00"
- diff = "02"
- # could be helpful
- def padString(leng, char, orig):
- while (len(str(orig)) < int(leng)):
- orig = str(char) + str(orig)
- return str(orig)
- # calculating 3D distance between two color tuples
- def calcDist(start, end):
- r = (start[0] - end[0]) * (start[0] - end[0])
- g = (start[1] - end[1]) * (start[1] - end[1])
- b = (start[2] - end[2]) * (start[2] - end[2])
- sum = r + g + b
- return sqrt(sum)
- # we'll just go ahead and stash total distance here
- totalDistance = 0
- # let's do a thing
- for index in range(1, 210):
- # pad index out so it's not useless
- indStr = padString(3, 0, index)
- # output our index
- print("Now working index " + indStr)
- # open two images as, well, images
- origPic = Image.open(orig + "/" + indStr + ".png")
- diffPic = Image.open(diff + "/" + indStr + ".png")
- # current distCount
- distCount = 0.0
- # iterate over the image body
- for x in range(0, origPic.size[0]):
- for y in range(0, origPic.size[1]):
- # get colors
- origColor = origPic.getpixel((x, y))
- diffColor = diffPic.getpixel((x, y))
- # add curDist
- distCount += calcDist(origColor, diffColor)
- # add a reduced distCount to totalDistance
- totalDistance += (distCount/(origPic.size[0]*origPic.size[1]))
- # print totalDistance
- print("Running average distance : " + str(round(totalDistance/(index), 5)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement