Skip to content

AvraamMavridis/wasm-image-to-black-white

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

Implementation of various algorithms that transform colourful images to black and white.

Install

npm i wasm-image-to-black-white --save

Algorithms

Original Image

Averaging Color Channels

Gray = (Red + Green + Blue) / 3

const wasm = import("wasm-image-to-black-white");
wasm.then(bnw => {
  img.src = bnw.grayscale_with_luminocity(img);
});

Luminocity

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);
});

Desaturation

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);
});        

BT601

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);
});            

Example

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);
})

About

Convert and image to b&w using various algorithms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages