Skip to main content

基于感知哈希(imagehash)的图像去重工具,支持本地路径/URL/base64 输入

Project description

images-dedup

基于感知哈希(imagehash)的图像去重工具。支持三种输入方式:本地路径、URL、base64,使用归一化相似度阈值,直觉友好。

安装

pip install images-dedup

快速开始

from images_dedup import dedup_images

images = [
    "photo1.jpg",
    "https://example.com/photo2.png",
    "data:image/png;base64,iVBORw0KGgo...",
]

result = dedup_images(images, threshold=0.97)

print(f"{result.original_count} 张 → 去重后 {result.unique_count} 张 "
      f"(移除 {result.removed_count}, {result.reduction_rate:.1%})")

for item in result.unique_images:
    print(item.index, item.source[:60], item.hash_hex)

# 重复关系: {保留索引: [被移除的索引列表]}
print(result.duplicates)

阈值说明

threshold 取值范围 0~1,表示两张图像相似度超过此值即视为重复。

threshold 含义(phash, hash_size=8)
1.00 只去完全相同的图像
0.97 相似度 ≥ 98.4% 视为重复
0.95 相似度 ≥ 95.3% 视为重复(默认)
0.90 相似度 ≥ 90.6% 视为重复
0.80 相似度 ≥ 81.2% 视为重复

API

dedup_images(
    images,                  # List[str] — 路径 / URL / base64
    threshold=0.95,          # float — 归一化相似度阈值
    hash_method="phash",     # phash | ahash | dhash | whash | colorhash
    hash_size=8,             # int — 哈希尺寸
    max_workers=8,           # int — 并发数
    retries=1,               # int — URL 下载失败重试次数
    verbose=False,           # bool — 是否打印进度
) -> DedupResult

DedupResult

属性 说明
images 全部条目(含失败),用于诊断
unique_images 去重后保留的图像列表
duplicates {保留索引: [重复索引...]}
input_count 输入总数
original_count 成功加载的数量(参与去重)
unique_count 去重后数量
removed_count 被移除的重复图像数
error_count 加载失败的数量
reduction_rate 去重率 = removed / original

加载失败的图像不参与去重,不计入 original_count 和去重率。

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

images_dedup-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

images_dedup-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file images_dedup-0.1.0.tar.gz.

File metadata

  • Download URL: images_dedup-0.1.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for images_dedup-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1fa34c392fa7b2a87f4aa75064733e30ec1c72ed25cc31463b69da23bab3ab0a
MD5 0dca48b962121b0699cb6f81b4452bc4
BLAKE2b-256 6f8aa4aae4d22e04ce80ebc0cd033b063340dbe96fd731c02b4edf2d677d0fca

See more details on using hashes here.

File details

Details for the file images_dedup-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: images_dedup-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for images_dedup-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b57c252ff562da7d2591e58baaa33882aa48ddc678eb1fa7ebaea34fbb9dfab
MD5 dc2186b65e98ff52341ffef60063eb21
BLAKE2b-256 7bc2a002211c8a40082ab6a42951ba315dab7c05a3b876a81a6cc5313a0283bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page