UNPKG

image-js

Version:

Image processing and manipulation in JavaScript

28 lines (27 loc) 624 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getMoment; /** * Returns the moment of an image (https://en.wikipedia.org/wiki/Image_moment) * @memberof Image * @instance * @param {number} [xPower=0] * @param {number} [yPower=0] * @return {number} */ function getMoment(xPower = 0, yPower = 0) { this.checkProcessable('getMoment', { bitDepth: [1] }); let m = 0; for (let x = 0; x < this.width; x++) { for (let y = 0; y < this.height; y++) { if (this.getBitXY(x, y) === 1) { m += x ** xPower * y ** yPower; } } } return m; }