Check Following Code: PIL
#[Optional] Images Variables from command arguments
#from sys import argv #base_image = argv[1] #test_image = argv[2] #result_image= argv[3]
#[Main] from PIL import Image,ImageChops,ImageOps from functools import reduce import math,operator # Images Variables base_image = "1.jpg" test_image = "2.jpg" result_image= "result.jpg" print("-------------------------------- ") # Base Image baseImage = Image.open(base_image).convert('RGB') print("Base Image = ",base_image , " : ") print("Width = ",baseImage.width, "Height = ",baseImage.height) # Test Image testImage = Image.open(test_image).convert('RGB') print("Test Image = ",test_image , " : ") print("Width = ",testImage.width, "Height = ",testImage.height) print("================================ ") #ITechOasis Image Comparision diff_Image=ImageChops.difference(baseImage, testImage).convert('RGB')
To Change Difference section color :
#Difference in Color diffInColor = Image.new('RGB', diff_Image.size, 'red') newDiff = ImageChops.multiply(diffInColor, diff_Image)
To Check % Image Difference:
#Image_Difference h = newDiff.histogram() Image_Difference = math.sqrt(reduce(operator.add,map(lambda h, i: h*(i**2), h, range(256))) / (float(baseImage.size[0]) * baseImage.size[1])) if newDiff.getbbox() is None: newDiff.save(result_image) print ("[Pass] Both Images are Same. Image_Difference = ", Image_Difference) else: newDiff.save(result_image) print ("[FAIL] Images are Different ! Image_Difference = ", Image_Difference) print("================================ ")
Read :
Leave a Reply
You must be logged in to post a comment.