All Projects → umbertogriffo → Fast Near Duplicate Image Search

umbertogriffo / Fast Near Duplicate Image Search

Licence: apache-2.0
Fast Near-Duplicate Image Search and Delete using pHash, t-SNE and KDTree.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Fast Near Duplicate Image Search

Deep Mihash
Code for papers "Hashing with Mutual Information" (TPAMI 2019) and "Hashing with Binary Matrix Pursuit" (ECCV 2018)
Stars: ✭ 13 (-75.93%)
Mutual labels:  hashing, nearest-neighbor-search
Gait Recognition
Distance Recognition of a Human Being with Deep CNN's
Stars: ✭ 51 (-5.56%)
Mutual labels:  image-processing
Dagbot
The official Repository for dagbot, the self proclaimmed n1 meme bot.
Stars: ✭ 40 (-25.93%)
Mutual labels:  image-processing
Facer
Simple (🤞) face averaging (🙂) in Python (🐍)
Stars: ✭ 49 (-9.26%)
Mutual labels:  image-processing
React Filepond
🔌 A handy FilePond adapter component for React
Stars: ✭ 1,024 (+1796.3%)
Mutual labels:  image-processing
Image Denoising Benchmark
Benchmarking Denoising Algorithms with Real Photographs
Stars: ✭ 49 (-9.26%)
Mutual labels:  image-processing
Tensorflow Lite Rest Server
Expose tensorflow-lite models via a rest API
Stars: ✭ 43 (-20.37%)
Mutual labels:  image-processing
Farmhash.sharp
Port of Google's farmhash algorithm to .NET
Stars: ✭ 52 (-3.7%)
Mutual labels:  hashing
Thmap
Concurrent trie-hash map library
Stars: ✭ 51 (-5.56%)
Mutual labels:  hashing
Seeds Revised
Implementation of the superpixel algorithm called SEEDS [1].
Stars: ✭ 48 (-11.11%)
Mutual labels:  image-processing
Op rbf
Optimized Recursive Bilateral Filter
Stars: ✭ 47 (-12.96%)
Mutual labels:  image-processing
Nimp
Nimp - Node-based image manipulation program.
Stars: ✭ 45 (-16.67%)
Mutual labels:  image-processing
Cropper
⚠️ [Deprecated] No longer maintained, please use https://github.com/fengyuanchen/jquery-cropper
Stars: ✭ 7,825 (+14390.74%)
Mutual labels:  image-processing
Wyhash Rs
wyhash fast portable non-cryptographic hashing algorithm and random number generator in Rust
Stars: ✭ 44 (-18.52%)
Mutual labels:  hashing
Opencv Face Filters
Snapchat-like Face Filters in OpenCV
Stars: ✭ 51 (-5.56%)
Mutual labels:  image-processing
React Native Heic Converter
Convert your HEIC files with React Native
Stars: ✭ 43 (-20.37%)
Mutual labels:  image-processing
Inpainting
Criminisi et al's region inpainting algorithm in C++
Stars: ✭ 46 (-14.81%)
Mutual labels:  image-processing
Esecurity
MSc Module
Stars: ✭ 49 (-9.26%)
Mutual labels:  hashing
Pixelizator
Swift/Python image pixelizer 🖼️.
Stars: ✭ 53 (-1.85%)
Mutual labels:  image-processing
Images Web Crawler
This package is a complete tool for creating a large dataset of images (specially designed -but not only- for machine learning enthusiasts). It can crawl the web, download images, rename / resize / covert the images and merge folders..
Stars: ✭ 51 (-5.56%)
Mutual labels:  image-processing

Fast Near-Duplicate Image Search and Delete

  • Author: Umberto Griffo
  • Twitter: @UmbertoGriffo

This Python script is a command line tool for visualizing, checking and deleting near-duplicate images from the target directory. In order to find similar images this script hashes the images using pHash from ImageHash library, adding the hash into a KDTree and perform a nearest neighbours search. In addition, near-duplicate images can be visualized generating a t-SNE (t-distributed Stochastic Neighbor Embedding) using a feature vector for each image derived from the pHash function.

I take no responsibility for bugs in this script or accidentally deleted pictures. Use at your own risk. Make sure you back up your pictures before using. This algorithm is intended to find nearly duplicate images. It is NOT intended to find images that are conceptually similar.

Contents

pHash definition

Features in the image are used to generate a distinct (but not unique) fingerprint, and these fingerprints are comparable. Perceptual hashes are a different concept compared to cryptographic hash functions like MD5 and SHA1.

phash

With cryptographic hashes, the hash values are random. The data used to generate the hash acts like a random seed, so the same data will generate the same result, but different data will create different results. Comparing two SHA1 hash values really only tells you two things. If the hashes are different, then the data is different. And if the hashes are the same, then the data is likely the same. (Since there is a possibility of a hash collision, having the same hash values does not guarantee the same data.) In contrast, perceptual hashes can be compared giving you a sense of similarity between the two data sets. Using pHash images can be scaled larger or smaller, have different aspect ratios, and even minor coloring differences (contrast, brightness, etc.) and they will still match similar images.

KDTree definition

A KDTree(short for k-dimensional tree) is a space-partitioning data structure for organizing points in a k-dimensional space. In particular, KDTree helps organize and partition the data points based on specific conditions. KDTree is a useful for several applications, such as searches involving a multidimensional search key (e.g. range searches and nearest neighbor searches).

Complexity (Average)

Scape Search Insert Delete
O(n) O(log n) O(log n) O(log n)

where n is the number of points.

Search

phases

Deletion

delete

Installation

Check INSTALL.md for installation instructions.

How to use the Makefile

Prerequisites

Install Python3 and virtualenv see Option 2 in INSTALL.md

  • All-in-one: make all
    • Setup, test and package.
  • Setup: make setup-env
    • Installs all dependencies.
  • Export dependencies of the environment: make export_env
    • Export a requirements.txt file containing the detailed dependencies of the environment.
  • Test: make test
    • Runs all tests.
    • Using pytest
  • Clean: make clean
    • Removes the environment.
    • Removes all cached files.
  • Check: make check
    • Use It to check that which pip3 and which python3 points to the right path.
  • Lint: make lint
    • Checks PEP8 conformance and code smells using pylint.
  • Package: make package
    • Creates a bundle of software to be installed.

Note: Run Setup as your init command (or after Clean)

Usage

Arguments

  <command>             delete or show or search.

  --images-path /path/to/images/
                        The Directory containing images.
  --output-path /path/to/output/
                        The Directory containing results.
  -q /path/to/image/, --query /path/to/image/
                        Path to the query image
  --tree-type {KDTree,cKDTree}
  --leaf-size LEAF_SIZE
                        Leaf size of the tree.
  --hash-algorithm {average_hash,dhash,phash,whash}
                        Hash algorithm to use.
  --hash-size HASH_SIZE
                        Hash size to use.
  -d {euclidean,l2,minkowski,p,manhattan,cityblock,l1,chebyshev,infinity}, --distance-metric {euclidean,l2,minkowski,p,manhattan,cityblock,l1,chebyshev,infinity}
                        Distance metric to use
  --nearest-neighbors NEAREST_NEIGHBORS
                        # of nearest neighbors.
  --threshold THRESHOLD
                        Threshold.
  --parallel [parallel]
                        Whether to parallelize the computation.
  --batch-size BATCH_SIZE
                        The batch size is used when parallel is set to true.
  --backup-keep [BACKUP_KEEP]
                        Whether to save the image to keep into a folder.
  --backup-duplicate [BACKUP_DUPLICATE]
                        Whether to save the duplicates into a folder.
  --safe-deletion [SAFE_DELETION]
                        Whether to execute the deletion without really
                        deleting nothing.
  --image-w IMAGE_W     The source image is resized down to or up to the
                        specified size.
  --image-h IMAGE_H     The source image is resized down to or up to the
                        specified size.

Delete near-duplicate images from the target directory

$ deduplication delete --images_path <target_dir> --output_path <output_dir> --tree_type KDTree

For example:

delete \
--images-path datasets/potatoes_multi_folder  \
--output-path outputs \
--tree-type KDTree \
--threshold 40 \
--parallel y \
--nearest-neighbors 5 \
--hash-algorithm phash \
--hash-size 8 \
--distance-metric manhattan \
--backup-keep y \
--backup-duplicate y \
--safe-deletion y \
Building the dataset...
	Parallel mode has been enabled...
	CPU: 16
	delegate work...
100%|██████████| 1/1 [00:00<00:00, 2231.01it/s]
	get the results...
100%|██████████| 1/1 [00:00<00:00, 773.57it/s]
Building the KDTree...
Finding duplicates and/or near duplicates...
	 Max distance: 33.0
	 Min distance: 0.0
	 number of files to remove: 28
	 number of files to keep: 4
28 duplicates or near duplicates has been founded in 0.0027272701263427734 seconds
We have found 28/32 duplicates in folder
Backuping images...
100%|██████████| 28/28 [00:00<00:00, 4087.45it/s]

Find near-duplicated images from an image you specified

$ deduplication search \
 --images_path <target_dir> \
 --output_path <output_dir> \
 --query <specify a query image file>

For example:

$ deduplication search \
--images-path datasets/potatoes \
--output-path outputs \
--tree-type KDTree \
--threshold 40 \
--parallel f \
--nearest-neighbors 5 \
--hash-algorithm phash \
--hash-size 8 \
--distance-metric manhattan \
--query datasets/potatoes/2018-12-11-15-031193.png

phases

Show near-duplicate images from the target directory With t-SNE

$ deduplication show --images_path <target_dir> --output_path <output_dir>

For example:

$ show
--images-path datasets/potatoes \
--output-path outputs \
--parallel y \
--image-w 32 \
--image-h 32

phases

Todo

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].