mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expose libvips' median filter operation (#1161)
This commit is contained in:
committed by
Lovell Fuller
parent
f880adbaac
commit
875937e3d8
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user