mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-11 10:49:59 +01:00
Finishing demo
This commit is contained in:
9
index.js
9
index.js
@@ -1,4 +1,9 @@
|
|||||||
require('./dist/image-sequencer-node');
|
sharp = require('sharp');
|
||||||
|
function log2(i){
|
||||||
|
console.log('\x1b[31m%s\x1b[0m:',"This is the output of the module");
|
||||||
|
console.log(sequencer.steps[i].get());
|
||||||
|
}
|
||||||
|
require('./src/ImageSequencerNode');
|
||||||
sequencer = ImageSequencer();
|
sequencer = ImageSequencer();
|
||||||
sequencer.loadImage('examples/grid.png');
|
sequencer.loadImage('examples/grid.png');
|
||||||
sequencer.addStep('ndvi-red');
|
sequencer.addStep('do-nothing');
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
"url": "https://github.com/publiclab/image-sequencer/issues"
|
"url": "https://github.com/publiclab/image-sequencer/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"font-awesome": "~4.5.0",
|
|
||||||
"bootstrap": "~3.2.0",
|
"bootstrap": "~3.2.0",
|
||||||
|
"font-awesome": "~4.5.0",
|
||||||
"jquery": "~2",
|
"jquery": "~2",
|
||||||
"sharp": "~0.17.2"
|
"sharp": "~0.17.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
var sharp = require('sharp');
|
|
||||||
|
|
||||||
ImageSequencer = function ImageSequencer(options) {
|
ImageSequencer = function ImageSequencer(options) {
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.inBrowser = options.inBrowser || typeof window !== 'undefined';
|
options.inBrowser = options.inBrowser || typeof window !== 'undefined';
|
||||||
if (options.inBrowser) options.ui = options.ui || require('./UserInterface');
|
// if (options.inBrowser) options.ui = options.ui || require('./UserInterface');
|
||||||
options.sequencerCounter = 0;
|
options.sequencerCounter = 0;
|
||||||
|
|
||||||
var image,
|
var image,
|
||||||
@@ -17,8 +15,7 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
|
|
||||||
// soon, detect local or URL?
|
// soon, detect local or URL?
|
||||||
function addStep(name, o) {
|
function addStep(name, o) {
|
||||||
console.log('adding step "' + name + '"');
|
console.log('\x1b[36m%s\x1b[0m','adding step "' + name + '"');
|
||||||
|
|
||||||
if (typeof(global) != "undefined")
|
if (typeof(global) != "undefined")
|
||||||
for(var variable in global)
|
for(var variable in global)
|
||||||
if(global[variable] == this)
|
if(global[variable] == this)
|
||||||
@@ -34,14 +31,14 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
|
|
||||||
steps.push(module);
|
steps.push(module);
|
||||||
|
|
||||||
// function defaultSetupModule() {
|
function defaultSetupModule() {
|
||||||
// if (options.ui) module.options.ui = options.ui({
|
if (options.ui) module.options.ui = options.ui({
|
||||||
// selector: o.selector,
|
selector: o.selector,
|
||||||
// title: module.options.title,
|
title: module.options.title,
|
||||||
// id: o.id,
|
id: o.id,
|
||||||
// instanceName: options.instanceName
|
instanceName: options.instanceName
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (name === "image-select") {
|
if (name === "image-select") {
|
||||||
|
|
||||||
@@ -55,20 +52,20 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
defaultSetupModule.apply(module); // run default setup() in scope of module (is this right?)
|
defaultSetupModule.apply(module); // run default setup() in scope of module (is this right?)
|
||||||
}
|
}
|
||||||
|
|
||||||
var previousStep = steps[steps.length - 2];
|
// var previousStep = steps[steps.length - 2];
|
||||||
|
//
|
||||||
if (previousStep) {
|
// if (previousStep) {
|
||||||
// connect output of last step to input of this step
|
// // connect output of last step to input of this step
|
||||||
previousStep.options.output = function output(image) {
|
// previousStep.options.output = function output(image) {
|
||||||
if (sequencer.steps[0].options.initialImage) {
|
// if (sequencer.steps[0].options.initialImage) {
|
||||||
options.initialImage = sequencer.steps[0].options.initialImage;
|
// options.initialImage = sequencer.steps[0].options.initialImage;
|
||||||
}
|
// }
|
||||||
log('running module "' + name + '"');
|
// log('running module "' + name + '"');
|
||||||
// display the image in any available ui
|
// // display the image in any available ui
|
||||||
if (previousStep.options.ui && previousStep.options.ui.display) previousStep.options.ui.display(image);
|
// if (previousStep.options.ui && previousStep.options.ui.display) previousStep.options.ui.display(image);
|
||||||
module.draw(image);
|
// module.draw(image);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,28 +75,29 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
// if (module.options.ui && module.options.ui.display) module.options.ui.display(image);
|
// if (module.options.ui && module.options.ui.display) module.options.ui.display(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 'Addded.';
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeStep (id) {
|
function removeStep (id) {
|
||||||
for (i=0;i<steps.length;i++) {
|
for (i=0;i<steps.length;i++) {
|
||||||
if (steps[i].options.id == id && steps[i].options.name != 'image-select'){
|
if (steps[i].options.id == id && steps[i].options.name != 'image-select'){
|
||||||
console.log('removing step "'+steps[i].options.name+'"');
|
console.log('\x1b[36m%s\x1b[0m','removing step "'+steps[i].options.name+'"');
|
||||||
// if (options.inBrowser) steps[i].options.ui.remove();
|
// if (options.inBrowser) steps[i].options.ui.remove();
|
||||||
steps.splice(i,1);
|
steps.splice(i,1);
|
||||||
run(options.initialImage);
|
if (steps.length != 0)
|
||||||
|
run(options.initialImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return "Removed.";
|
||||||
}
|
}
|
||||||
|
|
||||||
// passed image is optional but you can pass a
|
// passed image is optional but you can pass a
|
||||||
// non-stored image through the whole steps chain
|
// non-stored image through the whole steps chain
|
||||||
function run(image) {
|
function run(image) {
|
||||||
if (image) steps[1].draw(image);
|
steps[0].draw(image);
|
||||||
else steps[0].draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(msg) {
|
function log(msg) {
|
||||||
$('.log').append(msg + ' at ' + new Date());
|
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,13 +109,6 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
for(var variable in global)
|
for(var variable in global)
|
||||||
if(global[variable] == this)
|
if(global[variable] == this)
|
||||||
options.instanceName = variable;
|
options.instanceName = variable;
|
||||||
// image = new Image();
|
|
||||||
// image.onload = function() {
|
|
||||||
// run(image);
|
|
||||||
// if (callback) callback(image);
|
|
||||||
// options.initialImage = image;
|
|
||||||
// }
|
|
||||||
// image.src = src;
|
|
||||||
image = {};
|
image = {};
|
||||||
image.src = src;
|
image.src = src;
|
||||||
image.width = 0;
|
image.width = 0;
|
||||||
@@ -128,9 +119,9 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
image.height = metadata.height;
|
image.height = metadata.height;
|
||||||
image.naturalWidth = metadata.width;
|
image.naturalWidth = metadata.width;
|
||||||
image.naturalHeight = metadata.height;
|
image.naturalHeight = metadata.height;
|
||||||
|
options.initialImage = image;
|
||||||
run(image);
|
run(image);
|
||||||
if(callback) callback(image);
|
if(callback) callback(image);
|
||||||
options.initialImage = image;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
* Core modules
|
* Core modules
|
||||||
*/
|
*/
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'image-threshold': require('./modules/ImageThresholdNode')
|
'do-nothing': require('./modules/DoNothingNode')
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/modules/DoNothingNode.js
Normal file
23
src/modules/DoNothingNode.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Demo Module. Does nothing.
|
||||||
|
*/
|
||||||
|
module.exports = function DoNothing(options) {
|
||||||
|
options = options || {};
|
||||||
|
options.title = "Do Nothing";
|
||||||
|
|
||||||
|
var image;
|
||||||
|
|
||||||
|
function draw(inputImage) {
|
||||||
|
image = inputImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
options: options,
|
||||||
|
draw: draw,
|
||||||
|
get: get
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* Image thresholding with 'image-filter-threshold'
|
|
||||||
*/
|
|
||||||
module.exports = function ImageThreshold(options) {
|
|
||||||
options = options || {};
|
|
||||||
options.title = "Threshold image";
|
|
||||||
options.threshold = options.threshold || 30;
|
|
||||||
|
|
||||||
var image;
|
|
||||||
|
|
||||||
function draw(inputImage) {
|
|
||||||
$(inputImage).load(function(){
|
|
||||||
var canvas = document.createElement('canvas');
|
|
||||||
canvas.width = inputImage.naturalWidth;
|
|
||||||
canvas.height = inputImage.naturalHeight;
|
|
||||||
var context = canvas.getContext('2d');
|
|
||||||
context.drawImage(inputImage, 0, 0);
|
|
||||||
|
|
||||||
var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
||||||
|
|
||||||
var imageThreshold = require('image-filter-threshold');
|
|
||||||
var imageFilterCore = require('image-filter-core');
|
|
||||||
|
|
||||||
var result = imageThreshold({
|
|
||||||
data: imageData,
|
|
||||||
threshold: options.threshold
|
|
||||||
}).then(function (imageData) {
|
|
||||||
image = {};
|
|
||||||
image.src = src;
|
|
||||||
image.width = 0;
|
|
||||||
image.height = 0;
|
|
||||||
img = sharp(image.src);
|
|
||||||
img.metadata().then(function(metadata){
|
|
||||||
image.width = metadata.width;
|
|
||||||
image.height = metadata.height;
|
|
||||||
image.naturalWidth = metadata.width;
|
|
||||||
image.naturalHeight = metadata.height;
|
|
||||||
if (options.output) options.output(image);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function get() {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
options: options,
|
|
||||||
draw: draw,
|
|
||||||
get: get
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user