PIL ImageChop给出了错误的结果:

时间:2018-04-12 17:57:59

标签: python image python-imaging-library

img1_path = r'/Users/siddharth/image1.png'
img2_path = r'/Users/siddharth/image2.png'

from PIL import Image, ImageDraw, ImageChops

im1 = Image.open(img1_path) # original
im2 = Image.open(img2_path) # scapred

height,width = im1.size


for h in range(0,height,height/25):
    for w in range(0,width,width/20):
        c_img1 = im1.crop((h,w,height/25,height/25))
        c_img2 = im2.crop((h,w,height/25,height/25))

        if ImageChops.difference(c_img1, c_img2).getbbox() is None:
            draw = ImageDraw.Draw(im2)
            draw.rectangle((h,w,height/25,height/25),outline='red')

im2.save('Diff.png')
print 'Done'

这里的想法是两个比较两个图像并在它们不同的区域中标记矩形。 问题是尽管多次尝试我的结果(Diff.img)都有矩形,而不是仅仅存在差异?

我错过了什么?

0 个答案:

没有答案