imagesim

package module
v0.0.0-...-38bdb0e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2022 License: Unlicense Imports: 1 Imported by: 1

README

Go Report Card GitHub

image SIMililarity

This is a fast and simple algorithm for comparing the similarity of 2 images. Pure Go and zero dependencies.

Example

The hashing algorithm

  1. Resize the images to be 8 by 8 pixels. This is done by a very simple resizing algorithm.
  2. Make the images grayscale.
  3. Get the bitmask image value threshold. This is done by getting the average gray value in the image.
  4. Calculate the bitmask of the image, skip all values that are smaller than the threshold.

The hash comparing algorithm

  1. Calculate the Hamming distance between two hashes.
  2. Divide it by the amount of bits in the hash (this library uses uint64 for hashes, so 64).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(img image.Image, hash uint64) float64

Compare compares an image with an image hash.

func CompareHashes

func CompareHashes(hash1, hash2 uint64) float64

CompareHashes compares two hashes and returns their similarity (lower = more similar).

func CompareImages

func CompareImages(img1, img2 image.Image) float64

CompareImages compares two images and returns the similarity (lower = more similar) between them. You shouldn't use this because it will calculate the hash for both images at the same time, instead you should only calculate the hash once by calling Hash(img), and then passing the image you want to compare with the hash of the other image to Compare.

func Hash

func Hash(img image.Image) uint64

Hash returns the comparable hash of the image.

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL