SkillAgentSearch skills...

Imgsim

Golang library for computing perceptual hashes of images

Install / Use

/learn @Nr90/Imgsim

README

Imgsim GoDoc Go Report Card unstable

Imgsim is a library allows you to compute a fast perceptual hashes of an image. These hashes can then be used to compare images for similarity. Similar looking images will get similar perceptual hashes. Unlike cryptographic hashes that would be very different for images with slight differences. This makes them suitable to compare how similar images are.

Average hash

An average hash is an example of a perceptual hash.

For an introduction see: Average hash

Difference hash

Difference hashes are said to be more resillient to changes in the image then the Average hash.

For an introduction see: Difference hash

Installation

The package is go-gettable: go get -u github.com/Nr90/imgsim.

Example

package main

import (
	"fmt"
	"image/png"
	"os"

	"github.com/Nr90/imgsim"
)

func main() {
	imgfile, err := os.Open("assets/gopher.png")
	defer imgfile.Close()
	if err != nil {
		panic(err)
	}
	img, err := png.Decode(imgfile)
	if err != nil {
		panic(err)
	}
	ahash := imgsim.AverageHash(img)
	fmt.Println(ahash)
	dhash := imgsim.DifferenceHash(img)
	fmt.Println(dhash)
}

Related Skills

View on GitHub
GitHub Stars75
CategoryDevelopment
Updated1y ago
Forks5

Languages

Go

Security Score

85/100

Audited on Jan 4, 2025

No findings