def classify_DCT(image1,image2,size=(32,32),part_size=(8,8)):
""" '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 pHash.
It's 32 * 32 when it default.
'part_size' is a size of a part of the matrix after Discrete Cosine Transform,which need to next steps.
It's 8 * 8 when it default.
The function will return the hamming code,less is correct.
"""
assert size[0]==size[1],"size error"
assert part_size[0]==part_size[1],"part_size error"
image1 = image1.resize(size).convert('L').filter(ImageFilter.BLUR)
image1 = ImageOps.equalize(image1)
matrix = get_matrix(image1)
DCT_matrix = DCT(matrix)
List = sub_matrix_to_list(DCT_matrix, part_size)
middle = get_middle(List)
code1 = get_code(List, middle)
image2 = image2.resize(size).convert('L').filter(ImageFilter.BLUR)
image2 = ImageOps.equalize(image2)
matrix = get_matrix(image2)
DCT_matrix = DCT(matrix)
List = sub_matrix_to_list(DCT_matrix, part_size)
middle = get_middle(List)
code2 = get_code(List, middle)
return comp_code(code1, code2)
pHash.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录