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.
exact
: marks only binary exactly equal files as equal. This is by far the fastest, but most restricted algorithm.histogram
: checks the images' color histograms for equality. Faster than the image hashing algorithms, but tends to give a lot of false positives for images that are similar, but not equal. Use the--fuzziness
and--aspect-fuzziness
options to fine-tune its behavior.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 usingphash
, and only evaluating the other algorithms ifphash
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 filesdelete-second
: deletes the second of the two filesdelete-bigger
ord>
: deletes the file with the bigger sizedelete-smaller
ord<
: deletes the file with the smaller sizeeog
: launches theeog
image viewer to compare the two filesxv
: launches thexv
image viewer to compare the two filesprint
: prints the two filesquote
: prints the two files with quotes around eachnone
: does nothing. The default action isprint
.
Parallel execution
Use the --parallel
option to utilize all free cores on your system. There is also the
--chunk-size
option to tune how many comparisons each thread should make in one go, but that
should hardly ever be advantageous to set explicitly.
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
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
File details
Details for the file duplicate_images-0.3.6.tar.gz
.
File metadata
- Download URL: duplicate_images-0.3.6.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.0a1 CPython/3.8.5 Linux/5.4.0-58-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0ef898e7976af36c6dc770105a1479989fdedefdff759858b5422d114c446ec |
|
MD5 | e61d40b80b4891d4fe3f5594554636ed |
|
BLAKE2b-256 | 57b8ed5339ef494e4832ab716a3151478b7488871c6cbc244097bd25caa90397 |
File details
Details for the file duplicate_images-0.3.6-py3-none-any.whl
.
File metadata
- Download URL: duplicate_images-0.3.6-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.0a1 CPython/3.8.5 Linux/5.4.0-58-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c30ef35c5ce2db64b14427ffc17848b6111e9a65a857d397e0c2f9cb13f1e6e7 |
|
MD5 | 19ea42f1b5e83e52b0ac38dad3211d53 |
|
BLAKE2b-256 | 9d6fb18eace023568ea27b7b039e694dcb9211d4b381b32f264ad6120b4e4658 |