0.2.0 • Published 7 years ago

ndarray-idw-warp v0.2.0

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

ndarray-idw-warp

build status coverage status greenkeeper

warps an image according to a set of source and target coordinates

This module allows you to warp an image according to a set of source and target coordinates. The warping algorithm is based on the inverse distance weighting algorithm by Donald Shepard. It allows you to for example warp this input image:

input

To this output image:

output

Installation

npm install ndarray-idw-warp

Example

So for example, to warp an image like in the example above:

const util = require('util');
const getPixels = util.promisify(require('get-pixels'));
const save = require('save-pixels');
const fs = require('fs');
const streamToPromise = require('stream-to-promise');
const warp = require('ndarray-idw-warp');

const displacement = [
  [200, 75, 75, 75],
  [75, 200, 200, 200]
];

getPixels('input.png')
  .then(image => {
    const warped = warp(image, displacement);
    return streamToPromise(save(warped, 'png'));
  })
  .then(warpedImage => {
    fs.writeFileSync('warped.png', warpedImage);
  });

API

warp(input, displacements, power) ⇒ ndarray

Warps an image according to a set of source and target coordinates

Kind: global function Returns: ndarray - The warped image

ParamTypeDefaultDescription
inputndarrayAn ndarray of the image to warp
displacementsarrayAn array of fromX, fromY, toX, toY arrays
powernumber1Shepard's power parameter

License

MIT

0.2.0

7 years ago

0.1.0

7 years ago