def classify_ahash(cls, image1, image2, size=(8, 8), exact=25):
""" 'image1' and 'image2' is a Image Object.
You can build it by 'Image.open(path)'.
'Size' is parameter what the image will resize to it and then image will be compared by the algorithm.
It's 8 * 8 when it default.
'exact' is parameter for limiting the Hamming code between 'image1' and 'image2',it's 25 when it default.
The result become strict when the exact become less.
This function return the true when the 'image1' and 'image2' are similar.
"""
image1 = image1.resize(size).convert('L').filter(ImageFilter.BLUR)
image1 = ImageOps.equalize(image1)
code1 = cls.get_code(image1, size)
image2 = image2.resize(size).convert('L').filter(ImageFilter.BLUR)
image2 = ImageOps.equalize(image2)
code2 = cls.get_code(image2, size)
assert len(code1) == len(code2), "error"
return cls.compare_code(code1, code2)
评论列表
文章目录