Python画像の比較
880 ワード
'''
ImageCompare.py by
'''
from PIL import Image
from PIL import ImageChops
def compare_images(path_one, path_two, diff_save_location):
diff = ImageChops.difference(Image.open(path_one), Image.open(path_two))
if diff.getbbox():
diff.save(diff_save_location)
print(path_one,path_two)
else:
print(path_one,path_two,' We are the same!')
if __name__ == '__main__':
import os
compare_files = os.listdir('./image')
for file in compare_files:
print(file)
image_file = input('input image file name:')
for compare_file in compare_files:
compare_images('./image/'+image_file,
'./image/'+compare_file,
'./image/'+compare_file+'diff.png')