0.2.0 • Published 7 years ago
ndarray-idw-warp v0.2.0
ndarray-idw-warp
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:
To this output image:
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
Param | Type | Default | Description |
---|---|---|---|
input | ndarray | An ndarray of the image to warp | |
displacements | array | An array of fromX, fromY, toX, toY arrays | |
power | number | 1 | Shepard's power parameter |