UNPKG

tensorflowjs-binarization

Version:

Realization of binarization algorithms with Tensorflowjs

53 lines (31 loc) 1.17 kB
# tensorflowjs-binarization ## Description Implementation of binarization algorithms e.g. Otsu threshold ## Installation $ npm i tensorflowjs-binarization ## Usage ``` javascript 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](LICENSE)