mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 20:00:05 +01:00
various fixes and changes to SegmentedColormap module (#128)
This commit is contained in:
68
dist/image-sequencer.js
vendored
68
dist/image-sequencer.js
vendored
@@ -38688,9 +38688,8 @@ module.exports = function SegmentedColormap(options,UI) {
|
|||||||
var step = this;
|
var step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
var ndvi = (b - r) / (r + b);
|
var combined = (r + g + b) / 3.000;
|
||||||
var normalized = (ndvi + 1) / 2;
|
var res = require('./SegmentedColormap')(combined,options);
|
||||||
var res = require('./SegmentedColormap')(normalized,options);
|
|
||||||
return [res[0], res[1], res[2], 255];
|
return [res[0], res[1], res[2], 255];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38726,18 +38725,28 @@ module.exports = function SegmentedColormap(options,UI) {
|
|||||||
|
|
||||||
},{"../_nomodule/PixelManipulation.js":146,"./SegmentedColormap":144}],144:[function(require,module,exports){
|
},{"../_nomodule/PixelManipulation.js":146,"./SegmentedColormap":144}],144:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
* Accepts a normalized ndvi and returns the new color-mapped pixel
|
* 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]
|
||||||
|
* gradients, where begin and end are represented as [r, g, b] colors. In
|
||||||
|
* combination, a lookup table which maps values from 0 - 255 smoothly from black to white looks like:
|
||||||
|
* [
|
||||||
|
* [0, [0, 0, 0], [255, 255, 255]],
|
||||||
|
* [1, [255, 255, 255], [255, 255, 255]]
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* Adapted from bgamari's work in Infragram: https://github.com/p-v-o-s/infragram-js/commit/346c97576a07b71a55671d17e0153b7df74e803b
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function SegmentedColormap(normalized,options) {
|
module.exports = function SegmentedColormap(value, options) {
|
||||||
options.colormap = options.colormap || "default";
|
options.colormap = options.colormap || colormaps.default;
|
||||||
|
// if a lookup table is provided as an array:
|
||||||
if(typeof(options.colormap) == "object")
|
if(typeof(options.colormap) == "object")
|
||||||
colormapFunction = segmented_colormap(options.colormap);
|
colormapFunction = segmented_colormap(options.colormap);
|
||||||
|
// if a stored colormap is named with a string like "fastie":
|
||||||
else if(colormaps.hasOwnProperty(options.colormap))
|
else if(colormaps.hasOwnProperty(options.colormap))
|
||||||
colormapFunction = colormaps[options.colormap];
|
colormapFunction = colormaps[options.colormap];
|
||||||
else colormapFunction = colormaps.default;
|
else colormapFunction = colormaps.default;
|
||||||
|
return colormapFunction(value / 255.00);
|
||||||
return colormapFunction(normalized);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function segmented_colormap(segments) {
|
function segmented_colormap(segments) {
|
||||||
@@ -38768,19 +38777,38 @@ function segmented_colormap(segments) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
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 = {
|
var colormaps = {
|
||||||
greyscale: greyscale_colormap,
|
greyscale: segmented_colormap([
|
||||||
default: default_colormap,
|
[0, [0, 0, 0], [255, 255, 255] ],
|
||||||
stretched: stretched_colormap,
|
[1, [255, 255, 255], [255, 255, 255] ]
|
||||||
fastie: fastie_colormap
|
]),
|
||||||
|
default: segmented_colormap([
|
||||||
|
[0, [0, 0, 255], [0, 255, 255] ],
|
||||||
|
[0.33, [0, 255, 255], [255, 255, 0] ],
|
||||||
|
[0.66, [255, 255, 0], [255, 0, 0] ]
|
||||||
|
]),
|
||||||
|
ndvi: 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] ]
|
||||||
|
]),
|
||||||
|
stretched: 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] ]
|
||||||
|
]),
|
||||||
|
fastie: 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] ]
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
},{}],145:[function(require,module,exports){
|
},{}],145:[function(require,module,exports){
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ module.exports = function SegmentedColormap(options,UI) {
|
|||||||
var step = this;
|
var step = this;
|
||||||
|
|
||||||
function changePixel(r, g, b, a) {
|
function changePixel(r, g, b, a) {
|
||||||
var ndvi = (b - r) / (r + b);
|
var combined = (r + g + b) / 3.000;
|
||||||
var normalized = (ndvi + 1) / 2;
|
var res = require('./SegmentedColormap')(combined, options);
|
||||||
var res = require('./SegmentedColormap')(normalized,options);
|
|
||||||
return [res[0], res[1], res[2], 255];
|
return [res[0], res[1], res[2], 255];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* Accepts a normalized ndvi and returns the new color-mapped pixel
|
* 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]
|
||||||
|
* gradients, where begin and end are represented as [r, g, b] colors. In
|
||||||
|
* combination, a lookup table which maps values from 0 - 255 smoothly from black to white looks like:
|
||||||
|
* [
|
||||||
|
* [0, [0, 0, 0], [255, 255, 255]],
|
||||||
|
* [1, [255, 255, 255], [255, 255, 255]]
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* Adapted from bgamari's work in Infragram: https://github.com/p-v-o-s/infragram-js/commit/346c97576a07b71a55671d17e0153b7df74e803b
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function SegmentedColormap(normalized,options) {
|
module.exports = function SegmentedColormap(value, options) {
|
||||||
options.colormap = options.colormap || "default";
|
options.colormap = options.colormap || colormaps.default;
|
||||||
|
// if a lookup table is provided as an array:
|
||||||
if(typeof(options.colormap) == "object")
|
if(typeof(options.colormap) == "object")
|
||||||
colormapFunction = segmented_colormap(options.colormap);
|
colormapFunction = segmented_colormap(options.colormap);
|
||||||
|
// if a stored colormap is named with a string like "fastie":
|
||||||
else if(colormaps.hasOwnProperty(options.colormap))
|
else if(colormaps.hasOwnProperty(options.colormap))
|
||||||
colormapFunction = colormaps[options.colormap];
|
colormapFunction = colormaps[options.colormap];
|
||||||
else colormapFunction = colormaps.default;
|
else colormapFunction = colormaps.default;
|
||||||
|
return colormapFunction(value / 255.00);
|
||||||
return colormapFunction(normalized);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function segmented_colormap(segments) {
|
function segmented_colormap(segments) {
|
||||||
@@ -41,17 +51,37 @@ function segmented_colormap(segments) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
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 = {
|
var colormaps = {
|
||||||
greyscale: greyscale_colormap,
|
greyscale: segmented_colormap([
|
||||||
default: default_colormap,
|
[0, [0, 0, 0], [255, 255, 255] ],
|
||||||
stretched: stretched_colormap,
|
[1, [255, 255, 255], [255, 255, 255] ]
|
||||||
fastie: fastie_colormap
|
]),
|
||||||
|
default: segmented_colormap([
|
||||||
|
[0, [0, 0, 255], [0, 255, 0] ],
|
||||||
|
[0.25, [0, 255, 0], [255, 255, 0] ],
|
||||||
|
[0.50, [0, 255, 255], [255, 255, 0] ],
|
||||||
|
[0.75, [255, 255, 0], [255, 0, 0] ]
|
||||||
|
]),
|
||||||
|
ndvi: 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] ]
|
||||||
|
]),
|
||||||
|
stretched: 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] ]
|
||||||
|
]),
|
||||||
|
fastie: 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] ]
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user