MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / dctHashDistance

Method dctHashDistance

testutil/image_hash.go:242–255  ·  view source on GitHub ↗

dctHashDistance calculates the distance between two DCT hashes

(other *ImageHash)

Source from the content-addressed store, hash-verified

240
241// dctHashDistance calculates the distance between two DCT hashes
242func (h *ImageHash) dctHashDistance(other *ImageHash) float32 {
243 if len(h.dctHash) != len(other.dctHash) {
244 return math.MaxFloat32
245 }
246
247 var sumSquaredDiff float32
248 for i := range h.dctHash {
249 diff := h.dctHash[i] - other.dctHash[i]
250 sumSquaredDiff += diff * diff
251 }
252 mse := sumSquaredDiff / float32(len(h.dctHash))
253
254 return mse
255}
256
257// calcSha256Hash calculates the SHA-256 hash for the given image data buffer
258func (h *ImageHash) calcSha256Hash(buf []byte) error {

Callers 1

DistanceMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected