WebGL based image processing library
EMAGE is a webgl based image processing library, it is based on the webgl library qtek.
The example
Import the library
<script type="https://github.com/pissang/emage/blob/master/dist/emage.min.js"></script>
Or in the AMD environment
var emage = require("emage")
Process the image
// Create a image processor
var processor = new emage.Processor(canvas, image);
// Create a layer
var blurLayer = new emage.Layer();
// Use gaussian blur
blurLayer.use("buildin.gaussian");
// Create an other layer for color adjustment
var colorLayer = new emage.Layer("buildin.coloradjust");
// Add layers to processor and update the image
processor.add(blurLayer);
processor.add(colorLayer);
processor.update();
// Replace the gaussian blur with lens blur and update again
blurLayer.use("buildin.lensblur");
processor.update();
// Set parameters of filter
blurLayer.set("brightness", 6.0);
blurLayer.set("blurSize", 4.0);
// Or you can also write like this
blurLayer.set({
brightness : 6.0,
blurSize : 4.0
})
// Export the final image
var canvas = emage.canvas;
var img = new Image;
img.src = canvas.toDataURL();
Most of the filters is from GPUImage
buildin.gaussian
buildin.boxblur
buildin.lensblur
buildin.coloradjust
buildin.colormatrix
buildin.sepia
buildin.lut
buildin.sobel
buildin.toon
buildin.sketch
Histogram compute is done in shaders and can be quite efficient
// Pass in the image you want to compute histogram
var histogram = new emage.Histogram(image);
// Set down sample rate
histogram.downSample = 1/4;
// Compute the histogram and get the result
histogram.update();
// It will return a UnitArray(256) which store the histogram of red channel
var redChannel = histogram.channels.red;
// And other channels
var blueChannel = histogram.channels.blue;
var luminanceChannel = histogram.channels.luminance;