diff --git a/dist/image-sequencer.js b/dist/image-sequencer.js index 92a4e574..b1d30aac 100644 --- a/dist/image-sequencer.js +++ b/dist/image-sequencer.js @@ -35032,10 +35032,11 @@ module.exports = { 'ndvi-red': require('./modules/NdviRed'), 'do-nothing-pix': require('./modules/DoNothingPix'), 'invert': require('./modules/Invert'), - 'crop': require('./modules/Crop') + 'crop': require('./modules/Crop'), + 'segmented-colormap': require('./modules/SegmentedColormap') } -},{"./modules/Crop":122,"./modules/DoNothing":123,"./modules/DoNothingPix":124,"./modules/GreenChannel":125,"./modules/Invert":126,"./modules/NdviRed":127}],120:[function(require,module,exports){ +},{"./modules/Crop":122,"./modules/DoNothing":123,"./modules/DoNothingPix":124,"./modules/GreenChannel":125,"./modules/Invert":126,"./modules/NdviRed":127,"./modules/SegmentedColormap":129}],120:[function(require,module,exports){ function ReplaceImage(ref,selector,steps,options) { if(!ref.options.inBrowser) return false; // This isn't for Node.js this_ = ref; @@ -35212,11 +35213,10 @@ module.exports = function DoNothing(options) { /* * Display only the green channel */ -module.exports = function GreenChannel(options) { +module.exports = function DoNothingPix(options) { options = options || {}; - options.title = "Green channel only"; - options.description = "Displays only the green channel of an image"; + options.title = "Do Nothing with pixels"; var output; //function setup() {} // optional @@ -35419,4 +35419,82 @@ module.exports = function PixelManipulation(image, options) { } -},{"base64-stream":3,"get-pixels":27,"save-pixels":104}]},{},[116]); +},{"base64-stream":3,"get-pixels":27,"save-pixels":104}],129:[function(require,module,exports){ +module.exports = function SegmentedColormap(options) { + + options = options || {}; + options.title = "Segmented Colormap"; + options.colormap = options.colormap || "default"; + 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 = colormaps[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) { + return function(x) { + var i, result, x0, x1, xstart, y0, y1, _i, _j, _len, _ref, _ref1, _ref2, _ref3; + _ref = [0, 0], y0 = _ref[0], y1 = _ref[1]; + _ref1 = [segments[0][0], 1], x0 = _ref1[0], x1 = _ref1[1]; + if (x < x0) { + return y0; + } + for (i = _i = 0, _len = segments.length; _i < _len; i = ++_i) { + _ref2 = segments[i], xstart = _ref2[0], y0 = _ref2[1], y1 = _ref2[2]; + x0 = xstart; + if (i === segments.length - 1) { + x1 = 1; + break; + } + x1 = segments[i + 1][0]; + if ((xstart <= x && x < x1)) { + break; + } + } + result = []; + for (i = _j = 0, _ref3 = y0.length; 0 <= _ref3 ? _j < _ref3 : _j > _ref3; i = 0 <= _ref3 ? ++_j : --_j) { + result[i] = (x - x0) / (x1 - x0) * (y1[i] - y0[i]) + y0[i]; + } + return result; + }; +}; + +},{"./PixelManipulation.js":128}]},{},[116]); diff --git a/src/Modules.js b/src/Modules.js index 90e53906..b37b64e9 100644 --- a/src/Modules.js +++ b/src/Modules.js @@ -7,5 +7,6 @@ module.exports = { 'ndvi-red': require('./modules/NdviRed'), 'do-nothing-pix': require('./modules/DoNothingPix'), 'invert': require('./modules/Invert'), - 'crop': require('./modules/Crop') + 'crop': require('./modules/Crop'), + 'segmented-colormap': require('./modules/SegmentedColormap') } diff --git a/src/modules/DoNothingPix.js b/src/modules/DoNothingPix.js index 775e175d..4c28662b 100644 --- a/src/modules/DoNothingPix.js +++ b/src/modules/DoNothingPix.js @@ -1,11 +1,10 @@ /* - * Display only the green channel + * This module extracts pixels and saves them as it is. */ -module.exports = function GreenChannel(options) { +module.exports = function DoNothingPix(options) { options = options || {}; - options.title = "Green channel only"; - options.description = "Displays only the green channel of an image"; + options.title = "Do Nothing with pixels"; var output; //function setup() {} // optional diff --git a/src/modules/SegmentedColormap.js b/src/modules/SegmentedColormap.js new file mode 100644 index 00000000..66145410 --- /dev/null +++ b/src/modules/SegmentedColormap.js @@ -0,0 +1,79 @@ +module.exports = function SegmentedColormap(options) { + + options = options || {}; + options.title = "Segmented Colormap"; + options.colormap = options.colormap || "default"; + if(typeof(options.colormap) == "object") + options.colormap = segmented_colormap(options.colormap); + else options.colormap = colormaps[options.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 = 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) { + return function(x) { + var i, result, x0, x1, xstart, y0, y1, _i, _j, _len, _ref, _ref1, _ref2, _ref3; + _ref = [0, 0], y0 = _ref[0], y1 = _ref[1]; + _ref1 = [segments[0][0], 1], x0 = _ref1[0], x1 = _ref1[1]; + if (x < x0) { + return y0; + } + for (i = _i = 0, _len = segments.length; _i < _len; i = ++_i) { + _ref2 = segments[i], xstart = _ref2[0], y0 = _ref2[1], y1 = _ref2[2]; + x0 = xstart; + if (i === segments.length - 1) { + x1 = 1; + break; + } + x1 = segments[i + 1][0]; + if ((xstart <= x && x < x1)) { + break; + } + } + result = []; + for (i = _j = 0, _ref3 = y0.length; 0 <= _ref3 ? _j < _ref3 : _j > _ref3; i = 0 <= _ref3 ? ++_j : --_j) { + result[i] = (x - x0) / (x1 - x0) * (y1[i] - y0[i]) + y0[i]; + } + return result; + }; +};