简体   繁体   中英

Image comparison library for node.js

I'm looking for a basic image comparison library with node.js support or linux standard library. Support for comparing multi-resolutions images and slight color variation will be great. Any advice?

If you're looking for a simple "distance" between two images, the dhash-image module implements the dHash algorithm.

It converts to greyscale (ignoring color) and handles images of different dimensions, so meets those needs quite nicely.

I've been using dHash for automated regression testing of an image processing library. It's very fast if you need this sort of relative accuracy, but I would expect the SIFT/SURF features of OpenCV to provide a greater absolute accuracy.

Hey RembrandtJS might be exactly what you're looking for. It's a lightweight library we just released, that does a pixel-wise image comparison using drop-in Node.JS replacement node-canvas. It accepts both blobs and urls as image sources so you could simply do this:

import Rembrandt from 'rembrandt'

const rembrandt = new Rembrandt({
  // `imageA` and `imageB` can be either Strings (file path on node.js,
  // public url on Browsers) or Buffers
  imageA: '/path/to/imageA',
  imageB: fs.readFileSync('/path/to/imageB'),

  // Needs to be one of Rembrandt.THRESHOLD_PERCENT or Rembrandt.THRESHOLD_PIXELS
  thresholdType: Rembrandt.THRESHOLD_PERCENT,

  // The maximum threshold (0...1 for THRESHOLD_PERCENT, pixel count for THRESHOLD_PIXELS
  maxThreshold: 0.01,

  // Maximum color delta (0...255):
  maxDelta: 20,

  // Maximum surrounding pixel offset
  maxOffset: 0,

  renderComposition: true, // Should Rembrandt render a composition image?
  compositionMaskColor: Rembrandt.Color.RED // Color of unmatched pixels
})

// Run the comparison
rembrandt.compare()
  .then(function (result) {
    console.log('Passed:', result.passed)
    console.log('Difference:', (result.threshold * 100).toFixed(2), '%')
    console.log('Composition image buffer:', result.compositionImage)

    // Note that `compositionImage` is an Image when Rembrandt.js is run in the browser environment
  })
  .catch((e) => {
    console.error(e)
  })

As you can see Rembrandt also allows you to introduce threshold values that might offer some support for handling color variations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM