Measure pixel differences between pam image pixel arrays. Pam is an image type similar to ppm, pbm, and pgm. It has a small header that is followed by an uncompressed array of pixel data.
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
examples testing bounds response for gray all and mask, sync and async Jan 11, 2019
lib removed todo Feb 11, 2018
src unused var Jan 17, 2019
tests update tests Jan 16, 2019
.env clang-tidy again Jan 15, 2019
.gitignore clang-tidy again Jan 15, 2019
.jshintrc
.npmignore clang-tidy again Jan 15, 2019
.travis.yml test travis Jan 18, 2019
CMakeLists.txt update cmakelists.txt for code hinting Jan 18, 2019
LICENSE updated license Oct 13, 2017
README.md reformat code samples Jan 5, 2019
appveyor.yml add node version 8 and 9 for testing Jan 4, 2019
binding.gyp update binding.gyp Jan 18, 2019
index.js testing bounds response for gray all and mask, sync and async Jan 11, 2019
package-lock.json
package.json

README.md

pam-diff

dependencies Status Build Status Build status GitHub issues GitHub license npm

Measure differences between pixel arrays extracted from pam images. Works well with node module pipe2pam to extract pam images from an ffmpeg pipe. Supported tupltypes are rgb, rgb_alpha, and grayscale. It is currently being used for a video motion detection project.

Installation:

npm install pam-diff@latest --save

Important Note: The js-only version will no longer receive any updates. All future work will be dedicated to the n-api version because it is much more efficient.

New Feature: Starting with version 0.13.0, the option to use worker threads can be enabled by passing {async: true} to the pam-diff constructor.

Usage Options:

When comparing 2 equally sized buffers of grayscale, rgb, or rgba pixels, there are several options:
  1. all (default)
    • All pixels will be targeted when checking for differences.
    • To use this option, set the configuration object without creating any regions.
const pamDiff = new PamDiff({difference: 5, percent: 5});
  1. regions
    • Specific regions of pixels will be targeted when checking for differences and the rest will be ignored.
    • To use this option, create a regions array and pass it to the constructor.
const region1 = {name: 'region1', difference: 12, percent: 22, polygon: [{x: 0, y: 0}, {x: 0, y: 225}, {x: 100, y: 225}, {x: 100, y: 0}]};
const region2 = {name: 'region2', difference: 14, percent: 10, polygon: [{x: 100, y: 0}, {x: 100, y: 225}, {x: 200, y: 225}, {x: 200, y: 0}]};
const regions = [region1, region2];
const pamDiff = new PamDiff({regions : regions});
  1. mask
    • Specific regions of pixels will be ignored when checking for differences.
    • To use this option, create a regions array and set the mask option to true.
const region1 = {name: 'region1', polygon: [{x: 0, y: 0}, {x: 0, y: 225}, {x: 100, y: 225}, {x: 100, y: 0}]};
const region2 = {name: 'region2', polygon: [{x: 100, y: 0}, {x: 100, y: 225}, {x: 200, y: 225}, {x: 200, y: 0}]};
const regions = [region1, region2];
const pamDiff = new PamDiff({difference: 12, percent: 10, mask: true, regions : regions});
Getting results back from the pixel difference detection:
  1. event
    • A diff event will be emitted with a data object passed as the only argument.
pamDiff.on('diff', data => {
    console.log(data);
}); 
  1. callback
    • A callback function will be called with a data object passed as the only argument.
    • The callback can be passed as the 2nd argument to the constructor or it can be added later.
/* callback function */      
function myCallback(data) {
    console.log(data);
}

/* via the constructor */
const pamDiff = new pamDiff({difference: 10, percent: 20}, myCallback);

/* via the setter */
pamDiff.callback = myCallback;

/* via the chain-able setter */
pamDiff.setCallback(myCallback).setDifference(10).setPercent(20);

/* remove the callback */
pamDiff.callback = null;
Expected results:
  1. When targeting all pixels:
{
    trigger: [
        {name: 'all', percent: 13}
    ],
    pam: <Buffer>
}
  1. When targeting regions of pixels:
{
    trigger: [
        {name: 'region1', percent: 13},
        {name: 'region2', percent: 22}
    ],
    pam: <Buffer>
}
  1. When targeting all pixels ignored by mask:
{
    trigger: [
        {name: 'mask', percent: 13}
    ],
    pam: <Buffer>
}

Other Resources:

View the docs, tests, or examples for more implementations.

Future Plans:

  • Add node-pre-gyp as an option for installing pre-built binaries for those who are unable to use node-gyp. (Not a priority at this point)
  • Include option to return coordinates for bounding box of changed pixels.
  • Introduce blob filtering to group changed pixels with their neighbors.