image-signature
v0.4.0
Published
Library that hashes images in order to compare their similarity
Downloads
38
Readme
image-signature
Function that generates a hash for a canvas image that can be used to identify similar images
Written in Scala, transpiled to JavaScript with ScalaJS
(JVM compilation target coming soon!)
const signature = require('image-signature')
// getting image data from canvas
let canvas = document.createElement('canvas');
let context = canvas.getContext('2d');
let img = document.getElementById('foo');
context.drawImage(img, 0, 0 );
let imageData = context.getImageData(0, 0, img.width, img.height);
// calculating the signature
let sig = signature.generate(imageData)
// finding the "distance" (similarity) between two images
let distance = signature.distance(sig1, sig2)
The signature is an array of 81 arrays, one for each grid point in a 10x10 grid. Each array contains comparisons of grid pieces of image with each other (much darker, darker, same, lighter, much lighter). The algorithm used to generate the signature is based on the method described in Goldberg, et al.
The calculated "distance" is a measure of the similarity between the images. It is computed as the normalized L2 norm of the signature, as described in the Goldberg paper.
This package is the core algorithm used for comparing images and video frames in the Chrome extension Saucer.