Expose libvips' median filter operation (#1161)

This commit is contained in:
Andrea Bianco
2018-03-17 11:52:44 +01:00
committed by Lovell Fuller
parent f880adbaac
commit 875937e3d8
12 changed files with 105 additions and 1 deletions

View File

@@ -156,6 +156,26 @@ function sharpen (sigma, flat, jagged) {
return this;
}
/**
* Apply median filter using vips_rank( in, out, m, m, m * m / 2 );
* when used witout parameters the defaul window is 3x3
* @param {Number} [size] square mask size: size x size
* @returns {Sharp}
* @throws {Error} Invalid parameters
*/
function median (size) {
if (!is.defined(size)) {
// No arguments: default to 3x3
this.options.medianSize = 3;
} else if (is.integer(size) && is.inRange(size, 1, 1000)) {
// Numeric argument: specific sigma
this.options.medianSize = size;
} else {
throw new Error('Invalid median size ' + size);
}
return this;
}
/**
* Blur the image.
* When used without parameters, performs a fast, mild blur of the output image.
@@ -444,6 +464,7 @@ module.exports = function (Sharp) {
flip,
flop,
sharpen,
median,
blur,
extend,
flatten,