image-js
Version:
Image processing and manipulation in JavaScript
31 lines (30 loc) • 870 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getThreshold;
var _thresholdAlgorithms = require("../transform/mask/thresholdAlgorithms");
/**
* Returns a threshold for the creation of a binary mask with the `mask()` method.
* @memberof Image
* @instance
* @param {object} [options]
* @param {ThresholdAlgorithm} [options.algorithm='otsu']
* @return {number}
*/
function getThreshold(options = {}) {
let {
algorithm = _thresholdAlgorithms.names.otsu
} = options;
this.checkProcessable('getThreshold', {
components: 1,
bitDepth: [8, 16]
});
let method = _thresholdAlgorithms.methods[algorithm.toLowerCase()];
if (method) {
let histogram = this.getHistogram();
return method(histogram, this.size);
} else {
throw new Error(`unknown thresholding algorithm: ${algorithm}`);
}
}