imagemagick-compare
v1.1.4
Published
Compare images with NodeJS using ImageMagick's Magick++
Downloads
31
Maintainers
Readme
imagemagick-compare
ImageMagick's Compare binding for Node.
Features
- Native bindings to the C/C++ Magick++ library.
- Supports promises, async and sync.
- Supports all metrics.
- Full typescript support.
Prerequisites
You will need the following dependencies installed on your machine. Currently only linux is supported.
- node-gyp dependencies (python3, pkgconfig, make, g++)
- imagemagick
- imagemagick-dev
Installation
npm i imagemagick-compare
Usage
Version
Returns the version of the installed Magick++ library.
import { version } from 'imagemagick-compare';
console.log(version());
Compare
Compares two images using Magick++ and returns the result as a number.
originalImage
: Image buffer of the original image.compareWith
: Image buffer of the image to compare with.options
: Object with metric options. More details below.
Promise usage
import * as fs from 'fs';
import { compare } from 'imagemagick-compare';
const original = fs.readFileSync(__dirname + '/assets/Lenna_orig.png');
const compareWith = fs.readFileSync(__dirname + '/assets/Lenna_diff.png');
const options = { metric: 'SSIM', radius: 2 };
compare(originalImage, compareWith, options).then(res => console.log(res));
Async usage
import { compare } from 'imagemagick-compare';
// ...
compare(originalImage, compareWith, options, (err, res) => {
if (typeof err !== 'undefined') {
throw err;
}
console.log(res);
});
Sync usage
import { compareSync } from 'imagemagick-compare';
// ...
console.log(compareSync(originalImage, compareWith, options));
Compare options
metric
: Defaults toSSIM
. List of supported metrics below.radius
: Will only be used forSSIM
andDSSIM
metric.sigma
: Will only be used forSSIM
andDSSIM
metric.k1
: Will only be used forSSIM
andDSSIM
metric.k2
: Will only be used forSSIM
andDSSIM
metric.
Supported metrics
AE
: absolute error count, number of different pixels (-fuzz affected)DSSIM
: structural dissimilarity indexFUZZ
: mean color distanceMAE
: mean absolute error (normalized), average channel error distanceMEPP
: mean error per pixel (normalized mean error, normalized peak error)MSE
: mean error squared, average of the channel error squaredNCC
: normalized cross correlationPAE
: peak absolute (normalized peak absolute)PHASH
: perceptual hash for the sRGB and HCLp colorspacesPSNR
: peak signal to noise ratioRMSE
: root mean squared (normalized root mean squared)SSIM
: structural similarity index