Implementation of various algorithms that transform colourful images to black and white.
npm i wasm-image-to-black-white --save
Original Image
Gray = (Red + Green + Blue) / 3
const wasm = import("wasm-image-to-black-white");
wasm.then(bnw => {
img.src = bnw.grayscale_with_luminocity(img);
});
Gray = (Red * 0.21 + Green * 0.72 + Blue * 0.07)
const wasm = import("wasm-image-to-black-white");
wasm.then(bnw => {
img.src = bnw.grayscale_with_average(img);
});
Gray = ( Max(Red, Green, Blue) + Min(Red, Green, Blue) ) / 2)
const wasm = import("wasm-image-to-black-white");
wasm.then(bnw => {
img.src = bnw.grayscale_with_desaturation(img);
});
Gray = (Red * 0.299 + Green * 0.587 + Blue * 0.114)
const wasm = import("wasm-image-to-black-white");
wasm.then(bnw => {
img.src = bnw.grayscale_with_BT601(img);
});
const wasm = import("wasm-image-to-black-white");
const fileUploader = document.querySelector("#uploadfile");
fileUploader.addEventListener('change', (event) => {
const file = event.target.files[0];
var img = new Image;
img.onload = function() {
wasm.then(bnw => {
bnw.grayscale_with_luminocity(img);
bnw.grayscale_with_average(img);
});
}
img.src = URL.createObjectURL(file);
})