Skip to main content

Finds equal or similar images in a directory containing (many) image files

Project description

Finding Duplicate Images

Finds equal or similar images in a directory containing (many) image files.

Usage

$ pip install duplicate_images
$ find-dups -h

to print the help screen. Or just

$ find-dups $IMAGE_ROOT 

for a test run.

Image comparison algorithms

Use the --algorithm option to select how equal images are found.

ahash, colorhash, dhash, phash, whash: five different image hashing algorithms. See https://pypi.org/project/ImageHash for an introduction on image hashing and https://tech.okcupid.com/evaluating-perceptual-image-hashes-okcupid for some gory details which image hashing algorithm performs best in which situation. For a start I recommend using phash, and only evaluating the other algorithms if phash does not perform satisfactorily in your use case.

Actions for matching image pairs

Use the --on-equal option to select what to do to pairs of equal images.

  • delete-first: deletes the first of the two files
  • delete-second: deletes the second of the two files
  • delete-bigger or d>: deletes the file with the bigger size
  • delete-smaller or d<: deletes the file with the smaller size
  • eog: launches the eog image viewer to compare the two files
  • xv: launches the xv image viewer to compare the two files
  • print: prints the two files
  • quote: prints the two files with quotes around each
  • none: does nothing. The default action is print.

Parallel execution

Use the --parallel option to utilize all free cores on your system.

Progress and verbosity control

  • --progress prints a progress bar each for the process of reading the images and the process of finding duplicates among the scanned image
  • --debug prints debugging output

Development notes

Needs Python3 and Pillow imaging library to run, additionally Wand for the test suite.

Uses Poetry for dependency management.

Installation

From source:

$ git clone https://gitlab.com/lilacashes/DuplicateImages.git
$ cd DuplicateImages
$ pip3 install poetry
$ poetry install

Running

$ poetry run find-dups $PICTURE_DIR

or

$ poetry run find-dups -h

for a list of all possible options.

Test suite

Running it all:

$ poetry run pytest
$ poetry run mypy duplicate_images tests
$ poetry run flake8
$ poetry run pylint duplicate_images tests

or simply

$ .git_hooks/pre-push

Setting the test suite to be run before every push:

$ cd .git/hooks
$ ln -s ../../.git_hooks/pre-push .

Publishing

$ poetry config repositories.testpypi https://test.pypi.org/legacy/
$ poetry build
$ poetry publish --username $PYPI_USER --password $PYPI_PASSWORD --repository testpypi && \
  poetry publish --username $PYPI_USER --password $PYPI_PASSWORD

(obviously assuming that username and password are the same on PyPI and TestPyPI)

Profiling

CPU time

To show the top functions by time spent, including called functions:

$ poetry run python -m cProfile -s tottime ./duplicate_images/duplicate.py \ 
    --algorithm $ALGORITHM --action-equal none $IMAGE_DIR 2>&1 | head -n 15

or, to show the top functions by time spent in the function alone:

$ poetry run python -m cProfile -s cumtime ./duplicate_images/duplicate.py \ 
    --algorithm $ALGORITHM --action-equal none $IMAGE_DIR 2>&1 | head -n 15

Memory usage

$ poetry run fil-profile run ./duplicate_images/duplicate.py \
    --algorithm $ALGORITHM --action-equal none $IMAGE_DIR 2>&1

This will open a browser window showing the functions using the most memory (see https://pypi.org/project/filprofiler for more details).

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

duplicate_images-0.5.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

duplicate_images-0.5.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file duplicate_images-0.5.0.tar.gz.

File metadata

  • Download URL: duplicate_images-0.5.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/4.19.78-coreos

File hashes

Hashes for duplicate_images-0.5.0.tar.gz
Algorithm Hash digest
SHA256 517b9a79008761ad33f090eba4d1e9db7a7d9e75d752b1be93ef9686d3461603
MD5 2e775de43597b08a16f6631b50f075d6
BLAKE2b-256 82459072e4c11e5cf2f1ace24fae272552eb5a746011b431b9d006d163fca6dd

See more details on using hashes here.

File details

Details for the file duplicate_images-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: duplicate_images-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/4.19.78-coreos

File hashes

Hashes for duplicate_images-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86367c4a17a8a84af08af682b8c8d2f77ed0179f9bd5f77562e559ed8c8ea512
MD5 dcd214b8bca70183d11aa1f2c1b451fb
BLAKE2b-256 00264c74d7185625baee2c6ac646724fc49505fab4377a3e8823a86601a30271

See more details on using hashes here.

Supported by

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