0.2.2 • Published 6 years ago

@ismay/morpheus v0.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

morpheus

build status coverage status greenkeeper

warp and average images

This tool allows you to warp and average images. It does so by averaging the colors of each pixel. It accepts optional coordinates which it will use to morph all images to a common shape, for a more accurate result. It expects the images to be pngs of the same dimensions and the coordinates to be generated and exported with coordinator. You can use this library from the command line with morpheus-cli.

Installation

npm install -g @ismay/morpheus

Example

So for example, to medoid average a collection of images without coordinates:

const fs = require('fs');
const globby = require('globby');
const savePixels = require('save-pixels');
const util = require('util');
const getPixels = util.promisify(require('get-pixels'));
const streamToPromise = require('stream-to-promise');
const morpheus = require('@ismay/morpheus');

const imagePaths = globby.sync(['images/*.png']);
const imagePromises = imagePaths.map(imagePath => getPixels(imagePath));

Promise.all(imagePromises)
  .then(images => {
    const average = morpheus(images);
    return streamToPromise(savePixels(average, 'png'));
  })
  .then(imageBuffer => {
    fs.writeFileSync('average.png', imageBuffer);
  });

Usage

morpheus(images, options) ⇒ ndarray

Kind: global function Returns: ndarray - The average image

ParamTypeDescription
imagesArrayAn array of ndarrays for the images
optionsObjectConfiguration options
options.meanBooleanGenerate a mean average instead of a medoid average
options.coordinatesArrayAn array of coordinate arrays

License

MIT

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago