mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-14 04:10:04 +01:00
start to average module (#249)
* start to average module * completed average module * added average module, version bump
This commit is contained in:
191
dist/image-sequencer.js
vendored
191
dist/image-sequencer.js
vendored
@@ -46564,7 +46564,7 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
}
|
||||
module.exports = ImageSequencer;
|
||||
|
||||
},{"./AddStep":132,"./ExportBin":133,"./FormatInput":134,"./InsertStep":136,"./Modules":137,"./ReplaceImage":138,"./Run":139,"./ui/LoadImage":170,"./ui/UserInterface":171,"fs":7}],136:[function(require,module,exports){
|
||||
},{"./AddStep":132,"./ExportBin":133,"./FormatInput":134,"./InsertStep":136,"./Modules":137,"./ReplaceImage":138,"./Run":139,"./ui/LoadImage":172,"./ui/UserInterface":173,"fs":7}],136:[function(require,module,exports){
|
||||
// insert one or more steps at a given index in the sequencer
|
||||
function InsertStep(ref, image, index, name, o) {
|
||||
|
||||
@@ -46639,10 +46639,13 @@ module.exports = {
|
||||
],
|
||||
'saturation': [
|
||||
require('./modules/Saturation/Module'),require('./modules/Saturation/info')
|
||||
],
|
||||
'average': [
|
||||
require('./modules/Average/Module'),require('./modules/Average/info')
|
||||
]
|
||||
}
|
||||
|
||||
},{"./modules/Blur/Module":141,"./modules/Blur/info":142,"./modules/Brightness/Module":143,"./modules/Brightness/info":144,"./modules/Channel/Module":145,"./modules/Channel/info":146,"./modules/Colormap/Module":148,"./modules/Colormap/info":149,"./modules/Crop/Module":151,"./modules/Crop/info":153,"./modules/DecodeQr/Module":154,"./modules/DecodeQr/info":155,"./modules/Dynamic/Module":156,"./modules/Dynamic/info":157,"./modules/EdgeDetect/Module":159,"./modules/EdgeDetect/info":160,"./modules/FisheyeGl/Module":161,"./modules/FisheyeGl/info":162,"./modules/Invert/Module":163,"./modules/Invert/info":164,"./modules/Ndvi/Module":165,"./modules/Ndvi/info":166,"./modules/Saturation/Module":167,"./modules/Saturation/info":168}],138:[function(require,module,exports){
|
||||
},{"./modules/Average/Module":140,"./modules/Average/info":141,"./modules/Blur/Module":143,"./modules/Blur/info":144,"./modules/Brightness/Module":145,"./modules/Brightness/info":146,"./modules/Channel/Module":147,"./modules/Channel/info":148,"./modules/Colormap/Module":150,"./modules/Colormap/info":151,"./modules/Crop/Module":153,"./modules/Crop/info":155,"./modules/DecodeQr/Module":156,"./modules/DecodeQr/info":157,"./modules/Dynamic/Module":158,"./modules/Dynamic/info":159,"./modules/EdgeDetect/Module":161,"./modules/EdgeDetect/info":162,"./modules/FisheyeGl/Module":163,"./modules/FisheyeGl/info":164,"./modules/Invert/Module":165,"./modules/Invert/info":166,"./modules/Ndvi/Module":167,"./modules/Ndvi/info":168,"./modules/Saturation/Module":169,"./modules/Saturation/info":170}],138:[function(require,module,exports){
|
||||
// Uses a given image as input and replaces it with the output.
|
||||
// Works only in the browser.
|
||||
function ReplaceImage(ref,selector,steps,options) {
|
||||
@@ -46762,6 +46765,102 @@ function Run(ref, json_q, callback,progressObj) {
|
||||
module.exports = Run;
|
||||
|
||||
},{}],140:[function(require,module,exports){
|
||||
/*
|
||||
* Average all pixel colors
|
||||
*/
|
||||
module.exports = function Average(options, UI){
|
||||
options = options || {};
|
||||
options.blur = options.blur || 2
|
||||
|
||||
//Tell the UI that a step has been set up
|
||||
UI.onSetup(options.step);
|
||||
var output;
|
||||
|
||||
options.step.metadata = options.step.metadata || {};
|
||||
|
||||
function draw(input,callback,progressObj){
|
||||
|
||||
progressObj.stop(true);
|
||||
progressObj.overrideFlag = true;
|
||||
|
||||
// Tell the UI that a step is being drawn
|
||||
UI.onDraw(options.step);
|
||||
|
||||
var step = this;
|
||||
|
||||
function changePixel(r, g, b, a){
|
||||
return [r,g,b,a]
|
||||
}
|
||||
|
||||
// do the averaging
|
||||
function extraManipulation(pixels){
|
||||
var sum = [0,0,0,0];
|
||||
for (var i = 0; i < pixels.data.length; i += 4) {
|
||||
sum[0] += pixels.data[i + 0];
|
||||
sum[1] += pixels.data[i + 1];
|
||||
sum[2] += pixels.data[i + 2];
|
||||
sum[3] += pixels.data[i + 3];
|
||||
}
|
||||
|
||||
sum[0] = parseInt(sum[0] / (pixels.data.length / 4));
|
||||
sum[1] = parseInt(sum[1] / (pixels.data.length / 4));
|
||||
sum[2] = parseInt(sum[2] / (pixels.data.length / 4));
|
||||
sum[3] = parseInt(sum[3] / (pixels.data.length / 4));
|
||||
|
||||
for (var i = 0; i < pixels.data.length; i += 4) {
|
||||
pixels.data[i + 0] = sum[0];
|
||||
pixels.data[i + 1] = sum[1];
|
||||
pixels.data[i + 2] = sum[2];
|
||||
pixels.data[i + 3] = sum[3];
|
||||
}
|
||||
// report back and store average in metadata:
|
||||
options.step.metadata.averages = sum;
|
||||
console.log("average: ", sum);
|
||||
return pixels;
|
||||
}
|
||||
|
||||
function output(image, datauri, mimetype){
|
||||
|
||||
// This output is accessible by Image Sequencer
|
||||
step.output = {
|
||||
src: datauri,
|
||||
format: mimetype
|
||||
};
|
||||
|
||||
// This output is accessible by UI
|
||||
options.step.output = datauri;
|
||||
|
||||
// Tell UI that step has been drawn.
|
||||
UI.onComplete(options.step);
|
||||
}
|
||||
|
||||
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||
output: output,
|
||||
changePixel: changePixel,
|
||||
extraManipulation: extraManipulation,
|
||||
format: input.format,
|
||||
image: options.image,
|
||||
callback: callback
|
||||
});
|
||||
|
||||
}
|
||||
return {
|
||||
options: options,
|
||||
draw: draw,
|
||||
output: output,
|
||||
UI: UI
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":171}],141:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Average",
|
||||
"description": "Average all pixel color",
|
||||
"inputs": {
|
||||
}
|
||||
}
|
||||
|
||||
},{}],142:[function(require,module,exports){
|
||||
module.exports = exports = function(pixels,blur){
|
||||
let kernel = kernelGenerator(blur,1)
|
||||
kernel = flipKernel(kernel)
|
||||
@@ -46847,7 +46946,7 @@ function flipKernel(kernel){
|
||||
return result
|
||||
}
|
||||
}
|
||||
},{}],141:[function(require,module,exports){
|
||||
},{}],143:[function(require,module,exports){
|
||||
/*
|
||||
* Blur an Image
|
||||
*/
|
||||
@@ -46908,7 +47007,7 @@ module.exports = function Blur(options,UI){
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":169,"./Blur":140}],142:[function(require,module,exports){
|
||||
},{"../_nomodule/PixelManipulation.js":171,"./Blur":142}],144:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Blur",
|
||||
"description": "Gaussian blur an image by a given value, typically 0-5",
|
||||
@@ -46921,7 +47020,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],143:[function(require,module,exports){
|
||||
},{}],145:[function(require,module,exports){
|
||||
/*
|
||||
* Changes the Image Brightness
|
||||
*/
|
||||
@@ -46988,7 +47087,7 @@ module.exports = function Brightness(options,UI){
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":169}],144:[function(require,module,exports){
|
||||
},{"../_nomodule/PixelManipulation.js":171}],146:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Brightness",
|
||||
"description": "Change the brightness of the image by given percent value",
|
||||
@@ -47001,7 +47100,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],145:[function(require,module,exports){
|
||||
},{}],147:[function(require,module,exports){
|
||||
/*
|
||||
* Display only one color channel
|
||||
*/
|
||||
@@ -47061,7 +47160,7 @@ module.exports = function Channel(options,UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":169}],146:[function(require,module,exports){
|
||||
},{"../_nomodule/PixelManipulation.js":171}],148:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Channel",
|
||||
"description": "Displays only one color channel of an image -- default is green",
|
||||
@@ -47075,7 +47174,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],147:[function(require,module,exports){
|
||||
},{}],149:[function(require,module,exports){
|
||||
/*
|
||||
* Accepts a value from 0-255 and returns the new color-mapped pixel
|
||||
* from a lookup table, which can be specified as an array of [begin, end]
|
||||
@@ -47164,7 +47263,7 @@ var colormaps = {
|
||||
])
|
||||
}
|
||||
|
||||
},{}],148:[function(require,module,exports){
|
||||
},{}],150:[function(require,module,exports){
|
||||
module.exports = function Colormap(options,UI) {
|
||||
|
||||
options = options || {};
|
||||
@@ -47220,7 +47319,7 @@ module.exports = function Colormap(options,UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":169,"./Colormap":147}],149:[function(require,module,exports){
|
||||
},{"../_nomodule/PixelManipulation.js":171,"./Colormap":149}],151:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Colormap",
|
||||
"description": "Maps brightness values (average of red, green & blue) to a given color lookup table, made up of a set of one more color gradients.\n\nFor example, 'cooler' colors like blue could represent low values, while 'hot' colors like red could represent high values.",
|
||||
@@ -47234,7 +47333,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],150:[function(require,module,exports){
|
||||
},{}],152:[function(require,module,exports){
|
||||
(function (Buffer){
|
||||
module.exports = function Crop(input,options,callback) {
|
||||
|
||||
@@ -47280,7 +47379,7 @@ module.exports = function Crop(input,options,callback) {
|
||||
};
|
||||
|
||||
}).call(this,require("buffer").Buffer)
|
||||
},{"buffer":8,"get-pixels":38,"save-pixels":120}],151:[function(require,module,exports){
|
||||
},{"buffer":8,"get-pixels":38,"save-pixels":120}],153:[function(require,module,exports){
|
||||
/*
|
||||
* Image Cropping module
|
||||
* Usage:
|
||||
@@ -47359,7 +47458,7 @@ module.exports = function CropModule(options, UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"./Crop":150,"./Ui.js":152}],152:[function(require,module,exports){
|
||||
},{"./Crop":152,"./Ui.js":154}],154:[function(require,module,exports){
|
||||
// hide on save
|
||||
module.exports = function CropModuleUi(step, ui) {
|
||||
|
||||
@@ -47458,7 +47557,7 @@ module.exports = function CropModuleUi(step, ui) {
|
||||
}
|
||||
}
|
||||
|
||||
},{}],153:[function(require,module,exports){
|
||||
},{}],155:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Crop",
|
||||
"description": "Crop image to given x, y, w, h in pixels, measured from top left",
|
||||
@@ -47487,7 +47586,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],154:[function(require,module,exports){
|
||||
},{}],156:[function(require,module,exports){
|
||||
/*
|
||||
* Decodes QR from a given image.
|
||||
*/
|
||||
@@ -47542,7 +47641,7 @@ module.exports = function DoNothing(options,UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"get-pixels":38,"jsqr":56}],155:[function(require,module,exports){
|
||||
},{"get-pixels":38,"jsqr":56}],157:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Decode QR",
|
||||
"description": "Search for and decode a QR code in the image",
|
||||
@@ -47555,7 +47654,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],156:[function(require,module,exports){
|
||||
},{}],158:[function(require,module,exports){
|
||||
module.exports = function Dynamic(options,UI) {
|
||||
|
||||
options = options || {};
|
||||
@@ -47652,7 +47751,7 @@ module.exports = function Dynamic(options,UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":169}],157:[function(require,module,exports){
|
||||
},{"../_nomodule/PixelManipulation.js":171}],159:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Dynamic",
|
||||
"description": "A module which accepts JavaScript math expressions to produce each color channel based on the original image's color. See <a href='https://publiclab.org/wiki/infragram-sandbox'>Infragrammar</a>.",
|
||||
@@ -47680,7 +47779,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],158:[function(require,module,exports){
|
||||
},{}],160:[function(require,module,exports){
|
||||
const _ = require('lodash')
|
||||
|
||||
//define kernels for the sobel filter
|
||||
@@ -47861,7 +47960,7 @@ function hysteresis(pixels){
|
||||
|
||||
|
||||
|
||||
},{"lodash":57}],159:[function(require,module,exports){
|
||||
},{"lodash":57}],161:[function(require,module,exports){
|
||||
/*
|
||||
* Detect Edges in an Image
|
||||
*/
|
||||
@@ -47930,7 +48029,7 @@ module.exports = function edgeDetect(options,UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":169,"./EdgeUtils":158,"ndarray-gaussian-filter":62}],160:[function(require,module,exports){
|
||||
},{"../_nomodule/PixelManipulation.js":171,"./EdgeUtils":160,"ndarray-gaussian-filter":62}],162:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Detect Edges",
|
||||
"description": "this module detects edges using the Canny method, which first Gaussian blurs the image to reduce noise (amount of blur configurable in settings as `options.blur`), then applies a number of steps to highlight edges, resulting in a greyscale image where the brighter the pixel, the stronger the detected edge. Read more at: https://en.wikipedia.org/wiki/Canny_edge_detector",
|
||||
@@ -47953,7 +48052,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],161:[function(require,module,exports){
|
||||
},{}],163:[function(require,module,exports){
|
||||
/*
|
||||
* Resolves Fisheye Effect
|
||||
*/
|
||||
@@ -48035,7 +48134,7 @@ module.exports = function DoNothing(options,UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"fisheyegl":30}],162:[function(require,module,exports){
|
||||
},{"fisheyegl":30}],164:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Fisheye GL",
|
||||
"description": "Correct fisheye, or barrel distortion, in images (with WebGL -- adapted from fisheye-correction-webgl by @bluemir).",
|
||||
@@ -48103,7 +48202,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],163:[function(require,module,exports){
|
||||
},{}],165:[function(require,module,exports){
|
||||
/*
|
||||
* Invert the image
|
||||
*/
|
||||
@@ -48160,7 +48259,7 @@ module.exports = function Invert(options,UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":169}],164:[function(require,module,exports){
|
||||
},{"../_nomodule/PixelManipulation.js":171}],166:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Invert",
|
||||
"description": "Inverts the image.",
|
||||
@@ -48168,7 +48267,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],165:[function(require,module,exports){
|
||||
},{}],167:[function(require,module,exports){
|
||||
/*
|
||||
* NDVI with red filter (blue channel is infrared)
|
||||
*/
|
||||
@@ -48229,7 +48328,7 @@ module.exports = function Ndvi(options,UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":169}],166:[function(require,module,exports){
|
||||
},{"../_nomodule/PixelManipulation.js":171}],168:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "NDVI",
|
||||
"description": "Normalized Difference Vegetation Index, or NDVI, is an image analysis technique used with aerial photography. It's a way to visualize the amounts of infrared and other wavelengths of light reflected from vegetation by comparing ratios of blue and red light absorbed versus green and IR light reflected. NDVI is used to evaluate the health of vegetation in satellite imagery, where it correlates with how much photosynthesis is happening. This is helpful in assessing vegetative health or stress. <a href='https://publiclab.org/ndvi'>Read more</a>.<br /><br/>This is designed for use with red-filtered single camera <a href='http://publiclab.org/infragram'>DIY Infragram cameras</a>; change to 'blue' for blue filters",
|
||||
@@ -48243,7 +48342,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],167:[function(require,module,exports){
|
||||
},{}],169:[function(require,module,exports){
|
||||
/*
|
||||
* Saturate an image with a value from 0 to 1
|
||||
*/
|
||||
@@ -48312,7 +48411,7 @@ module.exports = function Saturation(options,UI) {
|
||||
}
|
||||
}
|
||||
|
||||
},{"../_nomodule/PixelManipulation.js":169}],168:[function(require,module,exports){
|
||||
},{"../_nomodule/PixelManipulation.js":171}],170:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "Saturation",
|
||||
"description": "Change the saturation of the image by given value, from 0-1, with 1 being 100% saturated.",
|
||||
@@ -48325,7 +48424,7 @@ module.exports={
|
||||
}
|
||||
}
|
||||
|
||||
},{}],169:[function(require,module,exports){
|
||||
},{}],171:[function(require,module,exports){
|
||||
(function (Buffer){
|
||||
/*
|
||||
* General purpose per-pixel manipulation
|
||||
@@ -48337,7 +48436,9 @@ module.exports = function PixelManipulation(image, options) {
|
||||
options.changePixel = options.changePixel || function changePixel(r, g, b, a) {
|
||||
return [r, g, b, a];
|
||||
};
|
||||
options.extraManipulation = options.extraManipulation||function extraManipulation(pixels){
|
||||
|
||||
//
|
||||
options.extraManipulation = options.extraManipulation || function extraManipulation(pixels){
|
||||
return pixels;
|
||||
}
|
||||
|
||||
@@ -48352,26 +48453,25 @@ module.exports = function PixelManipulation(image, options) {
|
||||
}
|
||||
|
||||
if(options.getNeighbourPixel){
|
||||
options.getNeighbourPixel.fun = function (distX,distY) {
|
||||
options.getNeighbourPixel.fun = function getNeighborPixel(distX,distY) {
|
||||
return options.getNeighbourPixel(pixels,x,y,distX,distY);
|
||||
};
|
||||
}
|
||||
|
||||
// iterate through pixels;
|
||||
// this could possibly be more efficient; see
|
||||
// TODO: this could possibly be more efficient; see
|
||||
// https://github.com/p-v-o-s/infragram-js/blob/master/public/infragram.js#L173-L181
|
||||
|
||||
if(!options.inBrowser){
|
||||
try{
|
||||
if (!options.inBrowser) {
|
||||
try {
|
||||
var pace = require('pace')((pixels.shape[0] * pixels.shape[1]));
|
||||
}
|
||||
catch(e){
|
||||
} catch(e){
|
||||
options.inBrowser = true;
|
||||
}
|
||||
}
|
||||
|
||||
for(var x = 0; x < pixels.shape[0]; x++) {
|
||||
for(var y = 0; y < pixels.shape[1]; y++) {
|
||||
for (var x = 0; x < pixels.shape[0]; x++) {
|
||||
for (var y = 0; y < pixels.shape[1]; y++) {
|
||||
|
||||
var pixel = options.changePixel(
|
||||
pixels.get(x, y, 0),
|
||||
@@ -48389,9 +48489,10 @@ module.exports = function PixelManipulation(image, options) {
|
||||
pace.op()
|
||||
}
|
||||
}
|
||||
|
||||
if(options.extraManipulation)
|
||||
pixels = options.extraManipulation(pixels)
|
||||
|
||||
// perform any extra operations on the entire array:
|
||||
if (options.extraManipulation)
|
||||
pixels = options.extraManipulation(pixels);
|
||||
|
||||
// there may be a more efficient means to encode an image object,
|
||||
// but node modules and their documentation are essentially arcane on this point
|
||||
@@ -48414,7 +48515,7 @@ module.exports = function PixelManipulation(image, options) {
|
||||
};
|
||||
|
||||
}).call(this,require("buffer").Buffer)
|
||||
},{"buffer":8,"get-pixels":38,"pace":69,"save-pixels":120}],170:[function(require,module,exports){
|
||||
},{"buffer":8,"get-pixels":38,"pace":69,"save-pixels":120}],172:[function(require,module,exports){
|
||||
// special module to load an image into the start of the sequence; used in the HTML UI
|
||||
function LoadImage(ref, name, src, main_callback) {
|
||||
function makeImage(datauri) {
|
||||
@@ -48521,7 +48622,7 @@ function LoadImage(ref, name, src, main_callback) {
|
||||
|
||||
module.exports = LoadImage;
|
||||
|
||||
},{"urify":127}],171:[function(require,module,exports){
|
||||
},{"urify":127}],173:[function(require,module,exports){
|
||||
/*
|
||||
* User Interface Handling Module
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user