Go implementation of multiple perceptual hash algorithms for images.
Detailed documentation has moved to the Wiki:
go get -u github.com/ajdnik/imghash/v2import "github.com/ajdnik/imghash/v2"Most consumers only need the top-level imghash package. Core types (Hash, Binary, UInt8, Float64, Distance) are re-exported there.
If you're unsure which hash to pick, start with PDQ.
package main
import (
"fmt"
"github.com/ajdnik/imghash/v2"
)
func main() {
pdq, err := imghash.NewPDQ()
if err != nil {
panic(err)
}
h1, err := imghash.HashFile(pdq, "image1.png")
if err != nil {
panic(err)
}
h2, err := imghash.HashFile(pdq, "image2.png")
if err != nil {
panic(err)
}
dist, err := pdq.Compare(h1, h2)
if err != nil {
panic(err)
}
fmt.Printf("Distance: %v\n", dist)
}| Algorithm | Hash type | Default metric |
|---|---|---|
| Average | Binary |
Hamming |
| Difference | Binary |
Hamming |
| Median | Binary |
Hamming |
| PHash | Binary |
Weighted Hamming |
| WHash | Binary |
Hamming |
| MarrHildreth | Binary |
Hamming |
| BlockMean | Binary |
Hamming |
| PDQ | Binary |
Hamming |
| RASH | Binary |
Hamming |
| ColorMoment | Float64 |
L2 (Euclidean) |
| Zernike | Float64 |
L2 (Euclidean) |
| GIST | Float64 |
Cosine |
| BoVW (Histogram) | Float64 |
Cosine |
| BoVW (MinHash) | Float64 |
Jaccard |
| BoVW (SimHash) | Binary |
Jaccard |
| CLD | UInt8 |
L2 (Euclidean) |
| EHD | UInt8 |
L1 (Manhattan) |
| LBP | UInt8 |
Chi-Square |
| HOGHash | UInt8 |
Cosine |
| RadialVariance | UInt8 |
L1 (Manhattan) |
See Algorithms for options, defaults, references, and examples.
Imghash is released under the MIT license. See LICENSE.
