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
Metadata
Release files for images-dedup 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| images_dedup-0.1.0.tar.gz | 10.3 kB | Without provenance | Details for images_dedup-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| images_dedup-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for images_dedup-0.1.0-py3-none-any.whl |
Total release size: 21.5 kB
Release files / images_dedup-0.1.0.tar.gz
| Download URL | images_dedup-0.1.0.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1fa34c392fa7b2a87f4aa75064733e30ec1c72ed25cc31463b69da23bab3ab0a
|
|
BLAKE2b-256 checksum How to use checksums |
6f8aa4aae4d22e04ce80ebc0cd033b063340dbe96fd731c02b4edf2d677d0fca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / images_dedup-0.1.0-py3-none-any.whl
| Download URL | images_dedup-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6b57c252ff562da7d2591e58baaa33882aa48ddc678eb1fa7ebaea34fbb9dfab
|
|
BLAKE2b-256 checksum How to use checksums |
7bc2a002211c8a40082ab6a42951ba315dab7c05a3b876a81a6cc5313a0283bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for images-dedup 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.