mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-12 11:20:02 +01:00
Modified Modules Folder Structure
This commit is contained in:
16
index.js
16
index.js
@@ -1,11 +1,11 @@
|
|||||||
console.log('\x1b[31m%s\x1b[0m',"This is the output of the module");
|
console.log('\x1b[31m%s\x1b[0m',"This is the output of the module");
|
||||||
require('./src/ImageSequencer');
|
require('./src/ImageSequencer');
|
||||||
sequencer = ImageSequencer();
|
sequencer = ImageSequencer();
|
||||||
sequencer.loadImages({images:{red:'examples/red.jpg'},callback:function(){
|
// sequencer.loadImages({images:{red:'examples/red.jpg'},callback:function(){
|
||||||
sequencer.addSteps(['do-nothing-pix','ndvi-red','invert']);
|
// sequencer.addSteps(['do-nothing-pix','ndvi-red','invert']);
|
||||||
sequencer.removeSteps(1);
|
// sequencer.removeSteps(1);
|
||||||
sequencer.insertSteps({
|
// sequencer.insertSteps({
|
||||||
red: [{index: -1, name: 'do-nothing-pix', o:{}}]
|
// red: [{index: -1, name: 'do-nothing-pix', o:{}}]
|
||||||
});
|
// });
|
||||||
sequencer.run();
|
// sequencer.run();
|
||||||
}});
|
// }});
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
* Core modules
|
* Core modules
|
||||||
*/
|
*/
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'do-nothing': require('./modules/DoNothing'),
|
'do-nothing': require('./modules/DoNothing/Module'),
|
||||||
'green-channel': require('./modules/GreenChannel'),
|
'green-channel': require('./modules/GreenChannel/Module'),
|
||||||
'ndvi-red': require('./modules/NdviRed'),
|
'ndvi-red': require('./modules/NdviRed/Module'),
|
||||||
'do-nothing-pix': require('./modules/DoNothingPix'),
|
'do-nothing-pix': require('./modules/DoNothingPix/Module.js'),
|
||||||
'invert': require('./modules/Invert'),
|
'invert': require('./modules/Invert/Module'),
|
||||||
'crop': require('./modules/Crop'),
|
'crop': require('./modules/Crop/Module'),
|
||||||
'segmented-colormap': require('./modules/SegmentedColormap')
|
'segmented-colormap': require('./modules/SegmentedColormap/Module')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Image Cropping module
|
|
||||||
* Usage:
|
|
||||||
* Expected Inputs:
|
|
||||||
* options.x : x-coordinate of image where the modules starts cropping | default : 0
|
|
||||||
* options.y : y-coordinate of image where the modules starts cropping | default : 0
|
|
||||||
* options.w : width of the resulting cropped image | default : 50% of input image width
|
|
||||||
* options.h : height of the resulting cropped image | default : 50% of input image height
|
|
||||||
* Output:
|
|
||||||
* The cropped image, which is essentially a rectangle bounded by the lines:
|
|
||||||
* x = options.x
|
|
||||||
* x = options.x + options.w
|
|
||||||
* y = options.y
|
|
||||||
* y = options.y + options.h
|
|
||||||
*/
|
|
||||||
module.exports = function Crop(options) {
|
|
||||||
options = options || {};
|
|
||||||
options.title = "Do Nothing";
|
|
||||||
this_ = this;
|
|
||||||
var output
|
|
||||||
var getPixels = require("get-pixels"),
|
|
||||||
savePixels = require("save-pixels"),
|
|
||||||
base64 = require('base64-stream');
|
|
||||||
|
|
||||||
function draw(input,callback) {
|
|
||||||
|
|
||||||
const this_ = this;
|
|
||||||
|
|
||||||
getPixels(input.src,function(err,pixels){
|
|
||||||
var newdata = [];
|
|
||||||
var ox = options.x || 0;
|
|
||||||
var oy = options.y || 0;
|
|
||||||
var w = options.w || Math.floor(0.5*pixels.shape[0]);
|
|
||||||
var h = options.h || Math.floor(0.5*pixels.shape[1]);
|
|
||||||
var iw = pixels.shape[0]; //Width of Original Image
|
|
||||||
newarray = new Uint8Array(4*w*h);
|
|
||||||
for (var n = oy; n < oy + h; n++) {
|
|
||||||
newarray.set(pixels.data.slice(n*4*iw + ox, n*4*iw + ox + 4*w),4*w*(n-oy));
|
|
||||||
}
|
|
||||||
pixels.data = newarray;
|
|
||||||
pixels.shape = [w,h,4];
|
|
||||||
pixels.stride[1] = 4*w;
|
|
||||||
|
|
||||||
options.format = "jpeg";
|
|
||||||
|
|
||||||
w = base64.encode();
|
|
||||||
var r = savePixels(pixels, options.format);
|
|
||||||
r.pipe(w).on('finish',function(){
|
|
||||||
data = w.read().toString();
|
|
||||||
datauri = 'data:image/' + options.format + ';base64,' + data;
|
|
||||||
this_.output = {src:datauri,format:options.format};
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
options: options,
|
|
||||||
draw: draw,
|
|
||||||
output: output
|
|
||||||
}
|
|
||||||
}
|
|
||||||
33
src/modules/Crop/Crop.js
Normal file
33
src/modules/Crop/Crop.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
module.exports = function Crop(input,options,callback) {
|
||||||
|
|
||||||
|
var getPixels = require("get-pixels"),
|
||||||
|
savePixels = require("save-pixels"),
|
||||||
|
base64 = require('base64-stream');
|
||||||
|
|
||||||
|
getPixels(input.src,function(err,pixels){
|
||||||
|
var newdata = [];
|
||||||
|
var ox = options.x || 0;
|
||||||
|
var oy = options.y || 0;
|
||||||
|
var w = options.w || Math.floor(0.5*pixels.shape[0]);
|
||||||
|
var h = options.h || Math.floor(0.5*pixels.shape[1]);
|
||||||
|
var iw = pixels.shape[0]; //Width of Original Image
|
||||||
|
newarray = new Uint8Array(4*w*h);
|
||||||
|
for (var n = oy; n < oy + h; n++) {
|
||||||
|
newarray.set(pixels.data.slice(n*4*iw + ox, n*4*iw + ox + 4*w),4*w*(n-oy));
|
||||||
|
}
|
||||||
|
pixels.data = newarray;
|
||||||
|
pixels.shape = [w,h,4];
|
||||||
|
pixels.stride[1] = 4*w;
|
||||||
|
|
||||||
|
options.format = "jpeg";
|
||||||
|
|
||||||
|
w = base64.encode();
|
||||||
|
var r = savePixels(pixels, options.format);
|
||||||
|
r.pipe(w).on('finish',function(){
|
||||||
|
data = w.read().toString();
|
||||||
|
datauri = 'data:image/' + options.format + ';base64,' + data;
|
||||||
|
callback(datauri,options.format);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
42
src/modules/Crop/Module.js
Normal file
42
src/modules/Crop/Module.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Image Cropping module
|
||||||
|
* Usage:
|
||||||
|
* Expected Inputs:
|
||||||
|
* options.x : x-coordinate of image where the modules starts cropping | default : 0
|
||||||
|
* options.y : y-coordinate of image where the modules starts cropping | default : 0
|
||||||
|
* options.w : width of the resulting cropped image | default : 50% of input image width
|
||||||
|
* options.h : height of the resulting cropped image | default : 50% of input image height
|
||||||
|
* Output:
|
||||||
|
* The cropped image, which is essentially a rectangle bounded by the lines:
|
||||||
|
* x = options.x
|
||||||
|
* x = options.x + options.w
|
||||||
|
* y = options.y
|
||||||
|
* y = options.y + options.h
|
||||||
|
*/
|
||||||
|
module.exports = function CropModule(options) {
|
||||||
|
options = options || {};
|
||||||
|
options.title = "Crop Image";
|
||||||
|
this_ = this;
|
||||||
|
var output
|
||||||
|
|
||||||
|
function draw(input,callback) {
|
||||||
|
|
||||||
|
const this_ = this;
|
||||||
|
|
||||||
|
require('./Crop')(input,options,function(out,format){
|
||||||
|
this_.output = {
|
||||||
|
src: out,
|
||||||
|
format: format
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
options: options,
|
||||||
|
draw: draw,
|
||||||
|
output: output
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Demo Module. Does nothing.
|
* Demo Module. Does nothing. Adds a step where output is equal to input.
|
||||||
*/
|
*/
|
||||||
module.exports = function DoNothing(options) {
|
module.exports = function DoNothing(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@@ -7,8 +7,6 @@ module.exports = function DoNothingPix(options) {
|
|||||||
options.title = "Do Nothing with pixels";
|
options.title = "Do Nothing with pixels";
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
//function setup() {} // optional
|
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
this_ = this;
|
this_ = this;
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
@@ -17,7 +15,7 @@ module.exports = function DoNothingPix(options) {
|
|||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
this_.output = {src:datauri,format:mimetype}
|
this_.output = {src:datauri,format:mimetype}
|
||||||
}
|
}
|
||||||
return require('./PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
changePixel: changePixel,
|
changePixel: changePixel,
|
||||||
format: input.format,
|
format: input.format,
|
||||||
@@ -28,7 +26,6 @@ module.exports = function DoNothingPix(options) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
options: options,
|
options: options,
|
||||||
//setup: setup, // optional
|
|
||||||
draw: draw,
|
draw: draw,
|
||||||
output: output
|
output: output
|
||||||
}
|
}
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* Display only the green channel
|
|
||||||
*/
|
|
||||||
module.exports = function FishEye(options) {
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
options.title = "Fish Eye";
|
|
||||||
options.description = "Corrects fish eye or barrel distortion.";
|
|
||||||
var output;
|
|
||||||
|
|
||||||
//function setup() {} // optional
|
|
||||||
|
|
||||||
function draw(input,callback) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
options: options,
|
|
||||||
//setup: setup, // optional
|
|
||||||
draw: draw,
|
|
||||||
output: output
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,7 @@ module.exports = function GreenChannel(options) {
|
|||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
this_.output = {src:datauri,format:mimetype}
|
this_.output = {src:datauri,format:mimetype}
|
||||||
}
|
}
|
||||||
return require('./PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
changePixel: changePixel,
|
changePixel: changePixel,
|
||||||
format: input.format,
|
format: input.format,
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Special module to kick off the sequence
|
|
||||||
* -- depends on jQuery for interface setup & drag & drop
|
|
||||||
*/
|
|
||||||
module.exports = function ImageSelect(options) {
|
|
||||||
|
|
||||||
if (!window.hasOwnProperty('$')) window.$ = window.jQuery = require('jquery');
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
options.title = "Select image";
|
|
||||||
options.inputSelector = options.inputSelector || "#file-select";
|
|
||||||
|
|
||||||
var image,
|
|
||||||
el = $('.' + options.selector + ' .mod-drop');
|
|
||||||
|
|
||||||
function setup() {
|
|
||||||
|
|
||||||
// CSS UI
|
|
||||||
el.on('dragenter', function(e) {
|
|
||||||
el.addClass('hover');
|
|
||||||
});
|
|
||||||
|
|
||||||
el.on('dragleave', function(e) {
|
|
||||||
el.removeClass('hover');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Drag & Drop behavior
|
|
||||||
function onImage(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation(); // stops the browser from redirecting.
|
|
||||||
|
|
||||||
var files;
|
|
||||||
if (e.target && e.target.files) files = e.target.files;
|
|
||||||
else files = e.dataTransfer.files;
|
|
||||||
|
|
||||||
for (var i = 0, f; f = files[i]; i++) {
|
|
||||||
// Read the File objects in this FileList.
|
|
||||||
|
|
||||||
reader = new FileReader();
|
|
||||||
reader.onload = function(e) {
|
|
||||||
// we should trigger "load" event here
|
|
||||||
|
|
||||||
image = new Image();
|
|
||||||
image.src = e.target.result;
|
|
||||||
options.initialImage = image;
|
|
||||||
el.html(image); // may be redundant
|
|
||||||
|
|
||||||
// this is done once per image:
|
|
||||||
options.output(image);
|
|
||||||
}
|
|
||||||
reader.readAsDataURL(f);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onDragOver(e) {
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
|
|
||||||
}
|
|
||||||
|
|
||||||
el.on('dragover', onDragOver, false);
|
|
||||||
el[0].addEventListener('drop', onImage, false);
|
|
||||||
$(options.inputSelector).change(onImage);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// this module is unique because it creates the image
|
|
||||||
function draw(image) {
|
|
||||||
el.html(image);
|
|
||||||
options.initialImage = image;
|
|
||||||
if (options.output) options.output(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
options: options,
|
|
||||||
draw: draw,
|
|
||||||
setup: setup
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,7 @@ module.exports = function GreenChannel(options) {
|
|||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
this_.output = {src:datauri,format:mimetype}
|
this_.output = {src:datauri,format:mimetype}
|
||||||
}
|
}
|
||||||
return require('./PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
changePixel: changePixel,
|
changePixel: changePixel,
|
||||||
format: input.format,
|
format: input.format,
|
||||||
@@ -7,18 +7,17 @@ module.exports = function NdviRed(options) {
|
|||||||
options.title = "NDVI for red-filtered cameras (blue is infrared)";
|
options.title = "NDVI for red-filtered cameras (blue is infrared)";
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
//function setup() {} // optional
|
|
||||||
|
|
||||||
function draw(input,callback) {
|
function draw(input,callback) {
|
||||||
this_ = this;
|
this_ = this;
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
var ndvi = 255 * (b - r) / (1.00 * b + r);
|
var ndvi = (b - r) / (1.00 * b + r);
|
||||||
return [ndvi, ndvi, ndvi, a];
|
var x = 255 * (ndvi + 1) / 2;
|
||||||
|
return [x, x, x, a];
|
||||||
}
|
}
|
||||||
function output(image,datauri,mimetype){
|
function output(image,datauri,mimetype){
|
||||||
this_.output = {src:datauri,format:mimetype}
|
this_.output = {src:datauri,format:mimetype}
|
||||||
}
|
}
|
||||||
return require('./PixelManipulation.js')(input, {
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
output: output,
|
output: output,
|
||||||
changePixel: changePixel,
|
changePixel: changePixel,
|
||||||
format: input.format,
|
format: input.format,
|
||||||
@@ -29,7 +28,6 @@ module.exports = function NdviRed(options) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
options: options,
|
options: options,
|
||||||
//setup: setup, // optional
|
|
||||||
draw: draw
|
draw: draw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Plot image on a graph with color bar
|
|
||||||
*/
|
|
||||||
module.exports = function Plot(options) {
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
options.title = "Plot with colorbar";
|
|
||||||
options.colorscale = options.colorscale || 'Jet',//'RdBu';
|
|
||||||
options.type = options.type || 'contour'; // or 'heatmap'
|
|
||||||
|
|
||||||
var image;
|
|
||||||
|
|
||||||
function draw(_image) {
|
|
||||||
|
|
||||||
/* https://plot.ly/javascript/heatmap-and-contour-colorscales/#custom-colorscale
|
|
||||||
type: 'contour',
|
|
||||||
colorscale: [[0, 'rgb(166,206,227)'],
|
|
||||||
[0.25, 'rgb(31,120,180)'],
|
|
||||||
[0.45, 'rgb(178,223,138)'],
|
|
||||||
[0.65, 'rgb(51,160,44)'],
|
|
||||||
[0.85, 'rgb(251,154,153)'],
|
|
||||||
[1, 'rgb(227,26,28)']]
|
|
||||||
*/
|
|
||||||
|
|
||||||
var Plotly = require('plotly.js'),
|
|
||||||
getPixels = require("get-pixels");
|
|
||||||
|
|
||||||
var data = [{
|
|
||||||
z: [],
|
|
||||||
colorscale: options.colorscale,
|
|
||||||
type: options.type
|
|
||||||
}];
|
|
||||||
|
|
||||||
getPixels(_image.src, function(err, pixels) {
|
|
||||||
|
|
||||||
if(err) {
|
|
||||||
console.log("Bad image path")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for(var y = pixels.shape[1]; y > 0; y--) {
|
|
||||||
data[0].z.push([]);
|
|
||||||
for(var x = 1; x < pixels.shape[0]; x++) {
|
|
||||||
|
|
||||||
data[0].z[data[0].z.length - 1].push(pixels.get(x, y, 0) / 255.00);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var layout = { title: '' };
|
|
||||||
random = parseInt(Math.random() * (new Date()).getTime() / 1000000);
|
|
||||||
|
|
||||||
options.ui.el.append('<div id="plot-' + random + '"></div>');
|
|
||||||
Plotly.newPlot('plot-' + random, data, layout)
|
|
||||||
/* .then(function afterPlot(graphData) {
|
|
||||||
|
|
||||||
options.output(Plotly.toImage(graphData, {
|
|
||||||
format: 'jpeg',
|
|
||||||
height: _image.height,
|
|
||||||
width: _image.width
|
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
options: options,
|
|
||||||
draw: draw
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Resize image
|
|
||||||
*/
|
|
||||||
module.exports = function Resize(options) {
|
|
||||||
options.title = "Resize image";
|
|
||||||
options.description = "Resizes image to given width";
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
function setup() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function draw(image) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
options: options,
|
|
||||||
setup: setup,
|
|
||||||
draw: draw
|
|
||||||
}
|
|
||||||
}
|
|
||||||
32
src/modules/SegmentedColormap/Module.js
Normal file
32
src/modules/SegmentedColormap/Module.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
module.exports = function SegmentedColormap(options) {
|
||||||
|
|
||||||
|
options = options || {};
|
||||||
|
options.title = "Segmented Colormap";
|
||||||
|
var output;
|
||||||
|
|
||||||
|
function draw(input,callback) {
|
||||||
|
this_ = this;
|
||||||
|
function changePixel(r, g, b, a) {
|
||||||
|
var ndvi = (b - r) / (r + b);
|
||||||
|
var normalized = (ndvi + 1) / 2;
|
||||||
|
var res = require('./SegmentedColormap')(normalized,options);
|
||||||
|
return [res[0], res[1], res[2], 255];
|
||||||
|
}
|
||||||
|
function output(image,datauri,mimetype){
|
||||||
|
this_.output = {src:datauri,format:mimetype}
|
||||||
|
}
|
||||||
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
||||||
|
output: output,
|
||||||
|
changePixel: changePixel,
|
||||||
|
format: input.format,
|
||||||
|
image: options.image,
|
||||||
|
callback: callback
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
options: options,
|
||||||
|
draw: draw,
|
||||||
|
output: output
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,53 +1,16 @@
|
|||||||
module.exports = function SegmentedColormap(options) {
|
/*
|
||||||
|
* Accepts a normalized ndvi and returns the new color-mapped pixel
|
||||||
|
*/
|
||||||
|
|
||||||
options = options || {};
|
module.exports = function SegmentedColormap(normalized,options) {
|
||||||
options.title = "Segmented Colormap";
|
|
||||||
options.colormap = options.colormap || "default";
|
options.colormap = options.colormap || "default";
|
||||||
if(typeof(options.colormap) == "object")
|
if(typeof(options.colormap) == "object")
|
||||||
options.colormap = segmented_colormap(options.colormap);
|
colormapFunction = segmented_colormap(options.colormap);
|
||||||
else options.colormap = colormaps[options.colormap];
|
else if(colormaps.hasOwnProperty(options.colormap))
|
||||||
var output;
|
colormapFunction = colormaps[options.colormap];
|
||||||
|
else colormapFunction = colormaps.default;
|
||||||
|
|
||||||
function draw(input,callback) {
|
return colormapFunction(normalized);
|
||||||
this_ = this;
|
|
||||||
function changePixel(r, g, b, a) {
|
|
||||||
var ndvi = (b - r) / (r + b);
|
|
||||||
var normalized = (ndvi + 1) / 2;
|
|
||||||
var res = options.colormap(normalized);
|
|
||||||
return [res[0], res[1], res[2], 255];
|
|
||||||
}
|
|
||||||
function output(image,datauri,mimetype){
|
|
||||||
this_.output = {src:datauri,format:mimetype}
|
|
||||||
}
|
|
||||||
return require('./PixelManipulation.js')(input, {
|
|
||||||
output: output,
|
|
||||||
changePixel: changePixel,
|
|
||||||
format: input.format,
|
|
||||||
image: options.image,
|
|
||||||
callback: callback
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
options: options,
|
|
||||||
draw: draw,
|
|
||||||
output: output
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var greyscale_colormap = segmented_colormap([[0, [0, 0, 0], [255, 255, 255]], [1, [255, 255, 255], [255, 255, 255]]]);
|
|
||||||
|
|
||||||
var default_colormap = segmented_colormap([[0, [0, 0, 255], [38, 195, 195]], [0.5, [0, 150, 0], [255, 255, 0]], [0.75, [255, 255, 0], [255, 50, 50]]]);
|
|
||||||
|
|
||||||
var stretched_colormap = segmented_colormap([[0, [0, 0, 255], [0, 0, 255]], [0.1, [0, 0, 255], [38, 195, 195]], [0.5, [0, 150, 0], [255, 255, 0]], [0.7, [255, 255, 0], [255, 50, 50]], [0.9, [255, 50, 50], [255, 50, 50]]]);
|
|
||||||
|
|
||||||
var fastie_colormap = segmented_colormap([[0, [255, 255, 255], [0, 0, 0]], [0.167, [0, 0, 0], [255, 255, 255]], [0.33, [255, 255, 255], [0, 0, 0]], [0.5, [0, 0, 0], [140, 140, 255]], [0.55, [140, 140, 255], [0, 255, 0]], [0.63, [0, 255, 0], [255, 255, 0]], [0.75, [255, 255, 0], [255, 0, 0]], [0.95, [255, 0, 0], [255, 0, 255]]]);
|
|
||||||
|
|
||||||
var colormaps = {
|
|
||||||
greyscale: greyscale_colormap,
|
|
||||||
default: default_colormap,
|
|
||||||
stretched: stretched_colormap,
|
|
||||||
fastie: fastie_colormap
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function segmented_colormap(segments) {
|
function segmented_colormap(segments) {
|
||||||
@@ -77,3 +40,18 @@ function segmented_colormap(segments) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var greyscale_colormap = segmented_colormap([[0, [0, 0, 0], [255, 255, 255]], [1, [255, 255, 255], [255, 255, 255]]]);
|
||||||
|
|
||||||
|
var default_colormap = segmented_colormap([[0, [0, 0, 255], [38, 195, 195]], [0.5, [0, 150, 0], [255, 255, 0]], [0.75, [255, 255, 0], [255, 50, 50]]]);
|
||||||
|
|
||||||
|
var stretched_colormap = segmented_colormap([[0, [0, 0, 255], [0, 0, 255]], [0.1, [0, 0, 255], [38, 195, 195]], [0.5, [0, 150, 0], [255, 255, 0]], [0.7, [255, 255, 0], [255, 50, 50]], [0.9, [255, 50, 50], [255, 50, 50]]]);
|
||||||
|
|
||||||
|
var fastie_colormap = segmented_colormap([[0, [255, 255, 255], [0, 0, 0]], [0.167, [0, 0, 0], [255, 255, 255]], [0.33, [255, 255, 255], [0, 0, 0]], [0.5, [0, 0, 0], [140, 140, 255]], [0.55, [140, 140, 255], [0, 255, 0]], [0.63, [0, 255, 0], [255, 255, 0]], [0.75, [255, 255, 0], [255, 0, 0]], [0.95, [255, 0, 0], [255, 0, 255]]]);
|
||||||
|
|
||||||
|
var colormaps = {
|
||||||
|
greyscale: greyscale_colormap,
|
||||||
|
default: default_colormap,
|
||||||
|
stretched: stretched_colormap,
|
||||||
|
fastie: fastie_colormap
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
module.exports = function(ref,image,pos) {
|
|
||||||
images = ref.images;
|
|
||||||
thisimage = images[image];
|
|
||||||
var thisstep = thisimage[pos];
|
|
||||||
console.log(thisstep);
|
|
||||||
return function(img) {
|
|
||||||
thisstep.output = img;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user