问题1:
这篇文章展示了比较两张图片的方法。最简单的方法可能是:from PIL import Image
from PIL import ImageChops
im1 = Image.open("file1.jpg")
im2 = Image.open("file2.jpg")
diff = ImageChops.difference(im2, im1).getbbox()
print diff
当我有两张长得很像的照片并运行在上面时,结果是:
^{pr2}$
这是图片上两张图片的差异所在的位置。所以我的问题是,有没有可能在图片上标出差异(例如,画一个圆圈)?在
问题2:import math, operator
from PIL import Image
def compare(file1, file2):
image1 = Image.open(file1)
image2 = Image.open(file2)
h1 = Image.open("image1").histogram()
h2 = Image.open("image2").histogram()
rms = math.sqrt(reduce(operator.add, map(lambda a,b: (a-b)**2, h1, h2))/len(h1))
if __name__=='__main__':
import sys
file1 = ('c:\\a.jpg') # added line
file2 = ('c:\\b.jpg') # added line
file1, file2 = sys.argv[1:]
print compare(file1, file2)
当我在上面运行时,会出现一个错误“ValueError:need more more value to unpack”,问题出在这一行:file1, file2 = sys.argv[1:]
我怎样才能纠正它?我试过了,但都没用。在print compare('c:\\a.jpg', 'c:\\b.jpg')
更新
在马特的帮助下增加了问题。在
它可以画一个矩形来标记两幅图像/图片的差异。当两幅图像/图片看起来大体相同,但有一些小斑点的差异扩散开来。它画了一个大的矩形标记大面积包括所有的斑点差异。有没有一种方法可以单独标记这些差异?在