ImageHashes package

ImageHashes.jl is a Julia package for image hashing. It covers various techniques to simplify the task of finding exact and near duplicates in an image collection, among other applications.

Benchmark

The package provides basic benchmarks in benchmarks/benchmark.jl. One can run

julia --project=. benchmarks/benchmark.jl 

to get

BENCHMARK RESULTS
time taken to compute a hash using difference_hash : 1.28e-6 seconds
Hashes per second: 781645
time taken to compute 100000000 hash distances: 0.531 seconds

There is an equivalent benchmark in Python using

https://github.com/JohannesBuchner/imagehash

which produces

BENCHMARK RESULTS
time taken to compute a hash using dhash: 0.004 seconds
Hashes per second: 250
time taken to compute 100000000 hash distances: 242.927 seconds

This Package is inspired by:

https://github.com/JohannesBuchner/imagehash

Good related material can be found in

  • https://github.com/JohannesBuchner/imagehash
  • https://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
  • https://erdogant.github.io/undouble/pages/html/hash_functions.html
  • https://content-blockchain.org/research/testing-different-image-hash-functions/
ImageHashes._difference_hash_matrixMethod
_difference_hash_matrix(image, n_size_side::Int; orientation=:vertical)

Compute the boolean bit matrix for difference hash.

  • orientation = :vertical: compares columns (resize to (n_size_side, n_size_side+1)), result (n_size_side, n_size_side).
  • orientation = :horizontal: compares rows (resize to (n_size_side+1, n_size_side)), result (n_size_side, n_size_side).
source
ImageHashes._preprocess_imageMethod
_preprocess_image(image, size::Union{Int,Tuple{Int,Int}}; func=nothing)

Resize an image to the target size and convert it to grayscale.

Arguments

  • image: the input image.
  • size: either an Int (resized to (size, size)) or a tuple (height, width).
  • func: optional function applied on the grayscale image. If provided, the function output is returned together with the grayscale image.

Returns

  • If func is nothing: the resized grayscale image.
  • Otherwise: a tuple (img_resized_gray, func(img_resized_gray)).
source
ImageHashes.difference_mathashFunction
difference_mathash(image, n_size_side::Int=8; orientation=:horizontal)

Return the difference hash as a BitMatrix.

  • By default, uses orientation=:horizontal to match test expectations.
source
ImageHashes.init_hash_containerMethod
init_hash_container(n_bits::Int)

Choose the proper variable type for the variable storing the resulting hash based on n_bits of the input..

source