image-js
Version:
Image processing and manipulation in JavaScript
32 lines (31 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = background;
var _mlRegression = require("ml-regression");
var _Image = _interopRequireDefault(require("../Image"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* @memberof Image
* @instance
* @param {Array<Array<number>>} coordinates
* @param {Array<Array<number>>} values;
* @param {object} [options]
* @return {Image}
*/
function background(coordinates, values, options) {
const model = new _mlRegression.KernelRidgeRegression(coordinates, values, options);
const allCoordinates = new Array(this.size);
for (let i = 0; i < this.width; i++) {
for (let j = 0; j < this.height; j++) {
allCoordinates[j * this.width + i] = [i, j];
}
}
const result = model.predict(allCoordinates);
const background = _Image.default.createFrom(this);
for (let i = 0; i < this.size; i++) {
background.data[i] = Math.min(this.maxValue, Math.max(0, result[i][0]));
}
return background;
}