aHash.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:Learn-to-identify-similar-images 作者: MashiMaroLjc 项目源码 文件源码
def classfiy_aHash(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 = getCode(image1, size)
    image2 = image2.resize(size).convert('L').filter(ImageFilter.BLUR)
    image2 = ImageOps.equalize(image2)
    code2 = getCode(image2, size)

    assert len(code1) == len(code2),"error"

    return compCode(code1, code2)<=exact
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号