31-----近似重复图像检测

本文展示了如何利用感知图像哈希和textdistance库检测重复或接近重复的图像。通过缩放、裁剪图像,生成哈希值,并计算Levenshtein距离找到最接近的图像。此外,还介绍了如何结合txtai和Sentence-Transformers创建嵌入式索引来进一步搜索相似图像。
摘要由CSDN通过智能技术生成

本文将概述如何使用感知图像哈希来检测重复和接近重复的图像。

安装依赖
安装txtai和所有依赖项。
pip install txtai[pipeline] textdistance

!wget -N https://github.com/neuml/txtai/releases/download/v3.5.0/tests.tar.gz
tar -xvzf tests.tar.gz
生成哈希
下面的示例为图像列表生成感知图像哈希。
import glob

from PIL import Image

from txtai.pipeline import ImageHash

def show(image):
width, height = image.size
return image.resize((int(width / 2.25), int((width / 2.25) * height / width)))

Get and scale images

images = [Image.open(image) for image in glob.glob(‘txtai/*jpg’)]

Create image pipeline

ihash = ImageHash()

Generate hashes

hashes = ihash(images)
hashes
[‘000000c0feffff00’,
‘0859dd04ffbfbf00’,
‘78f8f8d8f8f8f8f0’,
‘0000446c6f2f2724’,
‘ffffdf0700010100’,
‘00000

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Q shen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值