Sobel Gradient Image Deduplication
Project description
GraDupe
Sobel Gradient Image Deduplication
Motivation
Classical algorithms based on image hashes can be inaccurate. Innovative ones based on RNNs can be inefficient. As the demand for image storage increases rapidly over the decade, we need a prompt solution that combines the benefits of both.
Solution
At one point, Sobel gradients occurred to me as a decent fingerprint for an image. Similar to finite differences and derivatives, two distinct images bear the same gradient only if they differ by a constant. By reading an image in grayscale, we obtain a 2D matrix suitable for Sobel operators.
Images of different dimensions are downscaled into a square grid. Although convolutions are blazingly fast on modern hardware, this is done to unify dimensions and speed up diffing. After downscaling, there remains a sufficient amount of informative bits for diffing in the next step.
Sobel operators are traditionally used for edge detection, but their nature lies in differentiating an image. Computing the Sobel gradient of an image in both the x and y directions yields two matrices, which we flatten and concatenate into a contiguous array.
The gradients are thresholded into bitmasks since Hamming distance can be optimized using SIMD XOR instructions, making it magnitudes faster than Euclidean norm. By mapping sub-indices of pairs into combinatorial indices, a densely packed array can be used as a distance matrix, saving memory and enabling parallel computation.
The single flat distance array can be thresholded into a boolean mask with SIMD instructions. All that remains is to compress the image combinations with the mask (combinatorial indexing ensures correct correspondence), resulting in a list of duplicate images with the specified threshold.
Implementation
The library is written in Python using OpenCV, NumPy, and Numba (LLVM JIT). The CLI is written with Rich and Typer.
Install the CLI tool with pip install gradupe. Refer to gradupe --help for
usage instructions.
In practice, the tool proves extremely efficient and accurate. It finishes comparing 2000+ images in under 0.1 seconds on my Intel(R) Core(TM) i5-11320H laptop and caught 100+ duplicate pairs that iCloud Photos failed to detect.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gradupe-2.1.0.tar.gz.
File metadata
- Download URL: gradupe-2.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
768f0ff98fa0b9decfd20c0581334a58cd6777917674ecdba194837590283fd1
|
|
| MD5 |
ad0facd5d773bbb4d23b3eaa12f1abda
|
|
| BLAKE2b-256 |
8fcaaf64359bf3e46899aee55479df494903e905609845063652e87ddeeddd11
|
File details
Details for the file gradupe-2.1.0-py3-none-any.whl.
File metadata
- Download URL: gradupe-2.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df02f34b57bd8439a77ae760f7220cff516a8d777320d0f9d65079e9a64d9114
|
|
| MD5 |
1d2512c80cd7385e61d179d2005ade6d
|
|
| BLAKE2b-256 |
220c2d5b82af39d3917d140329c45e6bceef3f3d8da5fa02b20398f192371966
|