Skip to main content

Sobel Gradient Image Deduplication

Project description

GraDupe Icon
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 tool is written in pure Python. The internal library used OpenCV, NumPy, and Numba (LLVM JIT). The CLI is built with Typer and Rich.

Get the CLI with pip install gradupe, refer to gradupe --help for usage instructions. Optionally, install Intel's TBB (Threading Building Blocks) libraries on your device to enable dynamic scheduling (computational load of distance matrix is imbalanced). Run numba -s | grep TBB to check TBB presence, refer to instructions if TBB is not found.

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 found 100 duplicate pairs that iCloud Photos failed to detect.

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

gradupe-2.2.13.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

gradupe-2.2.13-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file gradupe-2.2.13.tar.gz.

File metadata

  • Download URL: gradupe-2.2.13.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gradupe-2.2.13.tar.gz
Algorithm Hash digest
SHA256 5152bc63817b1b931d5897d2322d0da5cc568b46a4c545815be408ab8bba4bc2
MD5 856b9a878a59f66d42f85e373299f51e
BLAKE2b-256 252560068f3eae0a51248740a420f5048ef6ee90f8bd20ee08686e898fa4ce8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gradupe-2.2.13.tar.gz:

Publisher: publish.yml on wavim/gradupe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gradupe-2.2.13-py3-none-any.whl.

File metadata

  • Download URL: gradupe-2.2.13-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gradupe-2.2.13-py3-none-any.whl
Algorithm Hash digest
SHA256 01eee7a19b06e77db79d050086e77711f044038ae9cd74b485cb8b2a0d984724
MD5 e2d319543e96e8fa88d9a378ab39ed0f
BLAKE2b-256 c5be3fb8beb892f523fea5a35c9d7ae81e8edb37209f857723333b1d799ffc4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gradupe-2.2.13-py3-none-any.whl:

Publisher: publish.yml on wavim/gradupe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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