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.
An average hash is an example of a perceptual hash.
For an introduction see: Average hash
Difference hashes are said to be more resillient to changes in the image then the Average hash.
For an introduction see: Difference hash
The package is go-gettable: go get -u github.com/Nr90/imgsim
.
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)
}