Calculate the Similarity Between Image Hashes in Go

Cloudmersive
2 min readApr 26, 2021

Calculating the similarity between perceptual image hashes enables you to compare images for copyright infringement, digital forensics, and many other tasks. These hashes are similar to fingerprints in that they provide a unique identifier for an image, and are impervious to alteration or manipulation attacks. Utilizing the following API in Go, you will be able to automatically compute the Hamming Distance between two perceptual image hashes, cutting down your calculation time to almost nothing.

To use the API, simply plug the two image hashes you wish to compare along with your API key into the following code:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/image/recognize/similarity/hash/distance"
method := "POST"
payload := strings.NewReader("ImageHash1=%3Cstring%3E&ImageHash2=%3Cstring%3E")client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

Your image similarity score will be returned immediately for review! To retrieve your API key, visit the Cloudmersive website to register for a free account and gain access to 800 calls/month.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.