Skip to main content

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


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.1.1.tar.gz (4.8 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.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gradupe-2.1.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for gradupe-2.1.1.tar.gz
Algorithm Hash digest
SHA256 a6ecfaf64148eeebf81ecd6ab77f15b7b68bd92d7a45e34bbe4cc84b8ce6e67b
MD5 66f7fbcda6a25beb090006bf3c091503
BLAKE2b-256 c4cd60757647785c7f1e7009f4bf5b4d42d61c63a2dee5cc0bf098afd045fdd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gradupe-2.1.1-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

Hashes for gradupe-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8ccbfc85821fc240924be06b240cfa948da2c795798c4efd4c13d7fb7174d8f
MD5 10b2126a3a09f0eda536b7573bf134a0
BLAKE2b-256 c305bd51c8ee1d40883039d4fa7f2bd592e4c1b8936c5a0440766b3a1ae4ae82

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