This is a small, very fast library to execute image filters using Web.GL on any runtime supported by Tensorflow.js.
npm install --save tf-gaussian-blur
This is a symetric (NxNx3x1) tensor that is convolved across an image tensor to generate a blur effect.
size
determines the dimension of the kernel. The larger size
the more surrounding pixels are included in the filter. size
must be odd. Computation time increases exponentially as size
increases.
sigma
is optional and sets the standard deviation of the gaussian distribution. A higher sigma
gives further pixels higher weight in the output.
const gaussianBlur = require("tf-gaussian-blur");
// get a 5x5 symetric gaussian filter
const size = 5
const sigma = 2
const kernel = blur.getGaussianKernel(size, sigma)
var image = tf.browser.fromPixels(document.getElementById("img"))
var blurredImage = blur.blur(image, kernel)
tf.browser.toPixels(image, document.getElementById("canvas"))