python 图像去重(imagededup)

开源地址:

https://github.com/idealo/imagededup

安装库

pip install imagededup

示例代码

from imagededup.methods import PHash

phasher = PHash()

# 生成图像目录中所有图像的二值hash编码
encodings = phasher.encode_images(image_dir='/tmp/close_eyes_jt/jingtiao_eyes_img')  # 图像路径

# 对已编码图像寻找重复图像
d_1 = phasher.find_duplicates(encoding_map=encodings)

# 给定一幅图像,显示与其重复的图像
from imagededup.utils import plot_duplicates
plot_duplicates(image_dir='path/to/image/directory',
                duplicate_map=d_1,
                filename='ukbench00120.jpg')



repeat_img = []  # 重复图片列表
is_img = []  # 不重复图片列表

for k, v in d_1.items():
    if not v:
        is_img.append(k)
    elif k not in repeat_img:
        is_img.append(k)
        repeat_img.extend(v)
    else:
        repeat_img.extend(v)

print(len(is_img))

原文地址:https://www.cnblogs.com/zhaoyingjie/p/15506751.html