Skip to content

JS function that generates a hash for a canvas image that can be used to identify duplicates

License

Notifications You must be signed in to change notification settings

wmsmacdonald/image-signature-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image-signature-js

Pure JS function that generates a hash for a canvas image that can be used to identify similar images

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.

About

JS function that generates a hash for a canvas image that can be used to identify duplicates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published