@ismay/morpheus

warp and average images

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@ismay/morpheus
Minified + gzip package size for @ismay/morpheus in KB

Readme

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

Param Type Description
images Array An array of ndarrays for the images
[options] Object Configuration options
[options.mean] Boolean Generate a mean average instead of a medoid average
[options.coordinates] Array An array of coordinate arrays

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.