What is @jimp/plugin-threshold?
@jimp/plugin-threshold is a plugin for the Jimp image processing library that allows you to apply threshold effects to images. This effect converts an image to black and white based on a threshold value, which can be useful for various image processing tasks such as edge detection, binarization, and more.
What are @jimp/plugin-threshold's main functionalities?
Apply Threshold Effect
This feature allows you to apply a threshold effect to an image. The `max` parameter specifies the threshold value. Pixels with a value above this threshold will be set to white, and those below will be set to black.
const Jimp = require('jimp');
Jimp.read('path/to/image.jpg')
.then(image => {
image.threshold({ max: 128 })
.write('path/to/output.jpg');
})
.catch(err => {
console.error(err);
});
Other packages similar to @jimp/plugin-threshold
sharp
Sharp is a high-performance image processing library that supports a wide range of image transformations, including thresholding. It is known for its speed and efficiency, especially with large images.
gm
GraphicsMagick (gm) is a powerful image processing library that provides a wide range of image manipulation features, including thresholding. It is a wrapper around the GraphicsMagick command-line tool and is known for its robustness and versatility.
opencv4nodejs
opencv4nodejs is a Node.js binding for OpenCV, a popular computer vision library. It provides extensive image processing capabilities, including thresholding, and is suitable for more advanced image analysis tasks.
@jimp/plugin-threshold
Lightens an image.
This is useful as a simplified method for processing scanned drawings, signatures, etc
Usage
- @param {number} options object
- max: A number auto limited between 0 - 255
- replace: (optional) A number auto limited between 0 - 255 (default 255)
- autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)
- @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from 'jimp';
async function main() {
const image = await jimp.read('test/image.png');
image.threshold({ max: 150 });
image.threshold({ max: 200, replace: 200, autoGreyscale: false });
}
main();