Skip to content

Library containing perceptual hash algorithms using the ImageSharp library

License

Notifications You must be signed in to change notification settings

TechSmith/ImageHash

This branch is 1 commit behind coenm/ImageHash:develop.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

698ec0e · Apr 8, 2024
Feb 11, 2022
Feb 11, 2022
Jul 5, 2022
Jul 5, 2022
Jun 19, 2019
Oct 3, 2018
Apr 8, 2024
Jul 5, 2022
Nov 13, 2021
Nov 13, 2021
Feb 11, 2022
Aug 28, 2020
Feb 11, 2022
Nov 16, 2017
Apr 8, 2024
Sep 17, 2020
Jul 5, 2022

Repository files navigation

ImageHash
ImageHash

Build Status Coverage NuGet

.NET Standard library containing multiple algorithms to calculate perceptual hashes of images and to calculate similarity using those hashes.

Contents

Perceptual hash

Definition by phash.org

A perceptual hash is a fingerprint of a multimedia file derived from various features from its content. Unlike cryptographic hash functions which rely on the avalanche effect of small changes in input leading to drastic changes in the output, perceptual hashes are "close" to one another if the features are similar.

Hash Algorithms

This project implements the following algorithms:

  • AverageHash by Dr. Neal Krawetz. Check his blog/article here;
  • PerceptualHash also by Dr. Neal Krawetz.
  • DifferenceHash by David Oftedal with minor improvements of Dr. Neal Krawetz. More information can be found here or here.

Credits

API

Calculate image hash

var hashAlgorithm = new AverageHash();
// or one of the other available algorithms:
// var hashAlgorithm = new DifferenceHash();
// var hashAlgorithm = new PerceptualHash();

string filename = "your filename";
using var stream = File.OpenRead(filename);

ulong imageHash = hashAlgorithm.Hash(stream);

snippet source | anchor

Calculate image similarity

Note that to calculate the image similarity, both image hashes should have been calculated using the same hash algorihm.

// calculate the two image hashes
ulong hash1 = hashAlgorithm.Hash(imageStream1);
ulong hash2 = hashAlgorithm.Hash(imageStream2);

double percentageImageSimilarity = CompareHash.Similarity(hash1, hash2);

snippet source | anchor

You can also take a look at DotNet APIs.

Some screenshots of the demo application

Screenshot 1

Screenshot 2

Screenshot 3

About

Library containing perceptual hash algorithms using the ImageSharp library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%