dctHashDistance calculates the distance between two DCT hashes
(other *ImageHash)
| 240 | |
| 241 | // dctHashDistance calculates the distance between two DCT hashes |
| 242 | func (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 |
| 258 | func (h *ImageHash) calcSha256Hash(buf []byte) error { |