0.4.2 • Published 5 years ago

wasm-image-to-black-white v0.4.2

Weekly downloads
38
License
-
Repository
github
Last release
5 years ago

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

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago