tensorflowjs-binarization

1.1.0 • Public • Published

tensorflowjs-binarization

Description

Implementation of binarization algorithms e.g. Otsu threshold

Installation

$ npm i tensorflowjs-binarization

Usage

const tf = require('@tensorflow/tfjs-node-gpu');
const fs = require("fs");
const threshold = require('tensorflowjs-binarization');

const thresh = new threshold(tf);

async function test(){

	let img1 = fs.readFileSync("./test_images/wow.png");

	const imageToPixel = await tf.node.decodePng(img1, 1);

	let bin = await thresh.binary(imageToPixel, 0.6, false);

	let otsuz = await thresh.otsu(imageToPixel);

	let newImg = await tf.node.encodePng(bin,1);

	let newImg_otsuz = await tf.node.encodePng(otsuz,1);



fs.writeFileSync("./test_images/result/bin.png", newImg)
fs.writeFileSync("./test_images/result/otsuz.png", newImg_otsuz)


}


 test();

binary

1st argument is tf.tensor3d 2nd argument is threshold coeff (float) 3rd argument is optional (boolean argument, defines if script should invert the colour)

otsu

Otsu binarization algorithms with calculating optimal threshold coeff.

License

MIT

Package Sidebar

Install

npm i tensorflowjs-binarization

Weekly Downloads

4

Version

1.1.0

License

MIT

Unpacked Size

330 kB

Total Files

9

Last publish

Collaborators

  • badmachine