From c189bd72eb2662944cf63ff663502be56accf720 Mon Sep 17 00:00:00 2001 From: Chinmay Pandhare Date: Thu, 13 Jul 2017 00:45:46 +0530 Subject: [PATCH] Segmented Colormap - Error --- dist/image-sequencer.js | 82 +++++++++++++++++++++++++++++--- output.txt | 1 + src/Modules.js | 3 +- src/modules/DoNothingPix.js | 5 +- src/modules/SegmentedColormap.js | 68 ++++++++++++++++++++++++++ 5 files changed, 149 insertions(+), 10 deletions(-) create mode 100644 output.txt create mode 100644 src/modules/SegmentedColormap.js diff --git a/dist/image-sequencer.js b/dist/image-sequencer.js index 92a4e574..3c6ef06d 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,74 @@ 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"; + var output + + function draw(input,callback) { + this_ = this; + function changePixel(r, g, b, a) { + var ndvi = (r - b) / (r + b); + var normalized = (ndvi + 1) / 2; + var res = default_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]]]); + +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/output.txt b/output.txt new file mode 100644 index 00000000..96c63471 --- /dev/null +++ b/output.txt @@ -0,0 +1 @@ +data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2MBERISGBUYLxoaL2NCOEJjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY//AABEIAMgAyAMBEQACEQEDEQH/xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+gEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APP6ACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgA+tNWvqAUgCgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAO1Vqlbv/X9f8MAVIBQAUAFABQAU1bqAUgCgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKAFALHAGSauEJVJKEFdsG7BtP4evTNWqMm9Nuj2T9L2FcSsRhQAdelNJt2QDtoHJzj1Arf2MYrmle3dLT8bX6q2nzFcDG3BHzD2qpYSpZOHvJ9tfv7C5l1G1ylBQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAOK87RyeoPqK6p0Upeyjq909dVa60t/XXuTfqBGCeoK/zqZQ5G7aONv8AwL16dbeS7jEPU9PwrKo7zb/Lb5DQlQAoxnnpVwcVJc+wMVSobkZWtKM6cJ++uaP4+vr/AMMJptABlhtHfgGinFSqL2a6qyfX8l/w4PbUcwBYHDFe5P8AjXVVhGc1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oAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAUnIHtVym5JJ9NPxb/UBKgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKADr0ppNuyAKQBQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAOVd3dR9TW9Gg6v2kvV2/4Im7DvLA5ZgQOu0810rBwh785pxW/K7vt+ZPN2EChlJCPnt3qIUoVINwhK/Tqvnp/XkO7XUQqQA3O09DWNSjKMVUXwvZ/02NPoNrAYUAFABTSAKQBQAUAFABQAUAFABQAUAFABQAUAFABQAUAFAC/w8j6GtFZQd1vs/wA/UQlZjJVTEXmZ7EY/SvTp4Xkw/wBZv0at63jv+JDld8pFXmFikY64/A1c4ODs/wAGn+QXBhtYgEH3FVWpqnNxTvbqhJ3QlZDCgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAk2GOVQeeRj3rveHlhsVGD11VvPUm/NEsN8q8EivoqtqMLJ2+7tsr6KyX3Lu7mK1ZUPGRgema+Uk1C8El2vv13X5enqbj3mZgR0BrsxGZVa0XBaJ/1b+vy0JUEiOvNLCgBxIKqvAI711TnGcIU3o1fXyeq2u/l0+8nZtja5SgoAKdna4BSAKACgAoAKACgAoAKACgAoAKAADJAqox5pKN7XAKkBVXdwPvelbUqTqtRhrJ9P+DcTdhKxGSvsIDdDt4H6V6uIVBxVRaPl0Wnpv1/PTdGavsJJL5gxjH41njMe8TFRtb5/wDAv+I4x5Ru35N3bOK5VRfsfat6Xt89/wAir62G1gMKACgB8rbmxjAHGK7cbXdWaVrKOlv+B+Hy2WymKshlcRQUAFABQAUAFABQAUAFABQAUAFABQAUAOT73XBAyK3w6XPe9mk2vVK4nsf/2Q== \ No newline at end of file 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..4164dcc7 100644 --- a/src/modules/DoNothingPix.js +++ b/src/modules/DoNothingPix.js @@ -1,11 +1,10 @@ /* * 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 diff --git a/src/modules/SegmentedColormap.js b/src/modules/SegmentedColormap.js new file mode 100644 index 00000000..1615f184 --- /dev/null +++ b/src/modules/SegmentedColormap.js @@ -0,0 +1,68 @@ +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 = (r - b) / (r + b); + var normalized = (ndvi + 1) / 2; + var res = default_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]]]); + +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; + }; +};