Skip to main content

difPy Duplicate Image Finder - automated search for duplicate or similar images.

Project description

Duplicate Image Finder (difPy)

Tired of going through all images in a folder and comparing them manually to check if they are duplicates?

The Duplicate Image Finder (difPy) Python package automates this task for you!

Read more on how the algorithm of difPy works in my Medium article Finding Duplicate Images with Python.

For a detailed usage guide, please view the official difPy Usage Documentation.


Description

difPy searches for images in one or more different folders, compares the images it found and checks whether these are duplicates. It then outputs the image files classified as duplicates as well as the images having the lowest resolutions, so you know which of the duplicate images are safe to be deleted. You can then either delete them manually, or let difPy delete them for you.

difPy does not compare images based on their hashes. It compares them based on their tensors i. e. the image content - this allows difPy to not only search for duplicate images, but also for similar images.

difPy leverages Python's multiprocessing capabilities and is therefore able to perform at high performance even on large datasets.

Table of Contents

  1. Basic Usage
  2. Output
  3. Additional Parameters
  4. CLI Usage

Basic Usage

To make difPy search for duplicates within one folder:

import difPy
dif = difPy.build("C:/Path/to/Folder/")
search = difPy.search(dif)

To search for duplicates within multiple folders:

import difPy
dif = difPy.build(["C:/Path/to/FolderA/", "C:/Path/to/FolderB/", "C:/Path/to/FolderC/",...])
search = difPy.search(dif)

Folder paths can be specified as standalone Python strings, or within a list. With difPy.build(), difPy first scans the images in the provided folders and builds a collection of images by generating image tensors. difPy.search() then starts the search for duplicate images.

Output

difPy returns various types of output that you may use depending on your use case:

I. Search Result Dictionary

A JSON formatted collection of duplicates/similar images (i. e. match groups) that were found, where the keys are a randomly generated unique id for each image file:

search.result

> Output:
{20220819171549 : {"location" : "C:/Path/to/Image/image1.jpg",
                   "matches" : {30270813251529 : "location": "C:/Path/to/Image/matched_image1.jpg",
                                                 "mse": 0.0},
                               {72214282557852 : "location": "C:/Path/to/Image/matched_image2.jpg",
                                                 "mse": 0.0},
                   ... }
 ...
}

II. Lower Quality Files

A JSON formatted collection of duplicates/similar images that have the lowest quality among match groups:

search.lower_quality

> Output:
{"lower_quality" : ["C:/Path/to/Image/duplicate_image1.jpg", 
                    "C:/Path/to/Image/duplicate_image2.jpg", ...]}

Lower quality images then can be moved to a different location:

search.move_to(search, destination_path="C:/Path/to/Destination/")

Or deleted:

search.delete(search, silent_del=False)

III. Process Statistics

A JSON formatted collection with statistics on the completed difPy processes:

search.stats

> Output:
{"directory" : ("C:/Path/to/Folder_A/", "C:/Path/to/Folder_B/", ... ),
 "process" : {"build" : {"duration" : {"start" : "2023-08-28T21:22:48.691008",
                                       "end" : "2023-08-28T21:23:59.104351",
                                       "seconds_elapsed" : "70.4133"},
                         "parameters" : {"recursive" : True,
                                         "in_folder" : False,
                                         "limit_extensions" : True,
                                         "px_size" : 50}},
              "search" : {"duration" : {"start" : "2023-08-28T21:23:59.106351",
                                        "end" : "2023-08-28T21:25:17.538015",
                                        "seconds_elapsed" : "78.4317"},
                          "parameters" : {"similarity_mse" : 0}
                          "files_searched" : 5225,
                          "matches_found" : {"duplicates" : 5,
                                             "similar" : 0}}}
 "invalid_files" : {"count" : 230,
                    "logs" : {...}}}

Additional Parameters

difPy supports the following parameters:

difPy.build(*directory, recursive=True, in_folder=False, limit_extensions=True, 
            px_size=50, show_progress=False, logs=True)
difPy.search(difpy_obj, similarity='duplicates', show_progress=False, logs=True)

CLI Usage

difPy can also be invoked through the CLI by using the following commands:

python dif.py #working directory

python dif.py -D "C:/Path/to/Folder/"

python dif.py -D "C:/Path/to/Folder_A/" "C:/Path/to/Folder_B/" "C:/Path/to/Folder_C/"

difPy CLI supports the following arguments:

dif.py [-h] [-D DIRECTORY [DIRECTORY ...]] [-Z OUTPUT_DIRECTORY] 
       [-r {True,False}] [-i {True,False}] [-le {True,False}] 
       [-px PX_SIZE] [-p {True,False}] [-s SIMILARITY] 
       [-mv MOVE_TO] [-d {True,False}] [-sd {True,False}] 
       [-l {True,False}]

If no directory parameter is given in the CLI, difPy will run on the current working directory.

When running from the CLI, the output of difPy is written to files and saved in the working directory by default. To change the default output directory, specify the -Z / -output_directory parameter. The "xxx" in the output filenames is the current timestamp:

difPy_xxx_results.json
difPy_xxx_lower_quality.json
difPy_xxx_stats.json

For a detailed usage guide, please view the official difPy Usage Documentation.

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

difPy-4.0.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

difPy-4.0.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file difPy-4.0.0.tar.gz.

File metadata

  • Download URL: difPy-4.0.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for difPy-4.0.0.tar.gz
Algorithm Hash digest
SHA256 04978684da7c5abac3840ff5e1327cccd3323b4ac1f48e50a5ba966a01c2e6dd
MD5 b2a12bc9d317223b1c2c61f0c5bd287d
BLAKE2b-256 d14dbc389bb23e586d12a55294c7c2a125961e2055ad4026fc27bb8806b103b8

See more details on using hashes here.

File details

Details for the file difPy-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: difPy-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for difPy-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a78d1af221990197d912c5d5881d0f9ed03b956c1bf992c9cc760c0c5e93be9
MD5 d09989818f0dfce50832587dfb27364a
BLAKE2b-256 771bcb2ce98c95e25d17eb365e660b0d65d2257024a9159db2aac18d6737db59

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