mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-15 12:50:04 +01:00
plotly integration???!
This commit is contained in:
19
dist/imageboard.css
vendored
19
dist/imageboard.css
vendored
@@ -1,12 +1,17 @@
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
margin: 0 auto;
|
||||||
|
max-width: 700px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.panels {
|
||||||
|
}
|
||||||
|
|
||||||
.panel {
|
.panel {
|
||||||
padding: 20px 0;
|
padding: 20px 0;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
@@ -21,8 +26,20 @@ body {
|
|||||||
color: #aaa;
|
color: #aaa;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ImageSelect styles */
|
.log h4 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log {
|
||||||
|
margin-top: 20px;
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 9px;
|
||||||
|
font-family: monospace;
|
||||||
|
color: #666;
|
||||||
|
background: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ImageSelect styles */
|
||||||
|
|
||||||
.mod-image-select #drop {
|
.mod-image-select #drop {
|
||||||
background: #efefef;
|
background: #efefef;
|
||||||
|
|||||||
149876
dist/imageboard.js
vendored
149876
dist/imageboard.js
vendored
File diff suppressed because one or more lines are too long
10
index.html
10
index.html
@@ -5,6 +5,7 @@
|
|||||||
<title>ImageBoard</title>
|
<title>ImageBoard</title>
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF8">
|
||||||
|
|
||||||
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet">
|
<link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet">
|
||||||
@@ -31,7 +32,7 @@
|
|||||||
<div class="panel mod-image-select">
|
<div class="panel mod-image-select">
|
||||||
<div id="drop">Drag image here</div>
|
<div id="drop">Drag image here</div>
|
||||||
<p class="instructions">Select or drop an image here to begin.</p>
|
<p class="instructions">Select or drop an image here to begin.</p>
|
||||||
<span class="file-select" class="upload"><input type="file" /></span>
|
<input id="file-select" type="file" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -42,11 +43,16 @@
|
|||||||
<select class="select-module form-control">
|
<select class="select-module form-control">
|
||||||
<option value="ndvi-red">NDVI with red filter</option>
|
<option value="ndvi-red">NDVI with red filter</option>
|
||||||
<option value="green-channel">Green channel</option>
|
<option value="green-channel">Green channel</option>
|
||||||
|
<option value="plot">Plot with colorbar</option>
|
||||||
</select>
|
</select>
|
||||||
<p><button class="btn btn-default add-step">Add step</button></p>
|
<p><button class="btn btn-default add-step">Add step</button></p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="log">
|
||||||
|
<h4>Log</h4>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
var imageboard;
|
var imageboard;
|
||||||
@@ -62,7 +68,7 @@
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
imageboard.addStep('ndvi-red');
|
imageboard.addStep('ndvi-red');
|
||||||
// imageboard.addStep('green-channel');
|
imageboard.addStep('plot');
|
||||||
|
|
||||||
$('.add-step').click(function(e) {
|
$('.add-step').click(function(e) {
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
"save-pixels": "^2.3.4",
|
"save-pixels": "^2.3.4",
|
||||||
"base64-stream": "^0.1.3",
|
"base64-stream": "^0.1.3",
|
||||||
"buffer": "^5.0.2",
|
"buffer": "^5.0.2",
|
||||||
|
"plotly.js": "^1.21.2",
|
||||||
|
|
||||||
"image-filter-threshold": "^0.0.8",
|
"image-filter-threshold": "^0.0.8",
|
||||||
"babelify": "^7.2.0",
|
"babelify": "^7.2.0",
|
||||||
|
|||||||
@@ -37,14 +37,21 @@ ImageBoard = function ImageBoard(options) {
|
|||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
|
function log(msg) {
|
||||||
|
$('.log').append(msg + ' at ' + new Date());
|
||||||
|
console.log(msg);
|
||||||
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
|
|
||||||
var lastImage;
|
var lastImage;
|
||||||
|
|
||||||
|
// THIS MUST BE EVENT BASED OR CALLBACKED -- ITS ASYNCHRONOUS
|
||||||
steps.forEach(function forEachStep(step) {
|
steps.forEach(function forEachStep(step) {
|
||||||
|
|
||||||
step.module.run(lastImage, function onComplete(image) {
|
step.module.run(lastImage, function onComplete(image) {
|
||||||
lastImage = image;
|
lastImage = image;
|
||||||
|
log('completed step "' + step.module.title + '"');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ module.exports = {
|
|||||||
|
|
||||||
'green-channel': require('./modules/GreenChannel.js'),
|
'green-channel': require('./modules/GreenChannel.js'),
|
||||||
'ndvi-red': require('./modules/NdviRed.js'),
|
'ndvi-red': require('./modules/NdviRed.js'),
|
||||||
|
'plot': require('./modules/Plot.js'),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
'image-threshold': {
|
'image-threshold': {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module.exports = function ImageSelect(options) {
|
|||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.selector = options.selector || "#drop";
|
options.selector = options.selector || "#drop";
|
||||||
|
options.inputSelector = options.inputSelector || "#file-select";
|
||||||
options.output = options.output || function output(image) {
|
options.output = options.output || function output(image) {
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@@ -24,11 +25,14 @@ module.exports = function ImageSelect(options) {
|
|||||||
|
|
||||||
// Drag & Drop behavior
|
// Drag & Drop behavior
|
||||||
|
|
||||||
var onDrop = function(e) {
|
var onImage = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation(); // stops the browser from redirecting.
|
e.stopPropagation(); // stops the browser from redirecting.
|
||||||
|
|
||||||
var files = e.dataTransfer.files;
|
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++) {
|
for (var i = 0, f; f = files[i]; i++) {
|
||||||
// Read the File objects in this FileList.
|
// Read the File objects in this FileList.
|
||||||
|
|
||||||
@@ -56,7 +60,8 @@ module.exports = function ImageSelect(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(options.selector).on('dragover', onDragOver, false);
|
$(options.selector).on('dragover', onDragOver, false);
|
||||||
$(options.selector)[0].addEventListener('drop', onDrop, false);
|
$(options.selector)[0].addEventListener('drop', onImage, false);
|
||||||
|
$(options.inputSelector).change(onImage);
|
||||||
|
|
||||||
function getImage() {
|
function getImage() {
|
||||||
return image;
|
return image;
|
||||||
|
|||||||
79
src/modules/Plot.js
Normal file
79
src/modules/Plot.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Plot image on a graph with color bar
|
||||||
|
*/
|
||||||
|
module.exports = function Plot(options) {
|
||||||
|
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
|
var image,
|
||||||
|
selector = 'mod-plot',
|
||||||
|
random = options.random || parseInt(Math.random() * (new Date()).getTime() / 1000000),
|
||||||
|
uniqueSelector = selector + '-' + random,
|
||||||
|
el;
|
||||||
|
|
||||||
|
// should we just run setup on constructor?
|
||||||
|
function setup() {
|
||||||
|
|
||||||
|
$(options.container).append('<div class="panel ' + selector + ' ' + uniqueSelector + '"></div>');
|
||||||
|
el = $('.' + uniqueSelector);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function run(_image, onComplete, options) {
|
||||||
|
|
||||||
|
options = options || {};
|
||||||
|
options.colorscale = options.colorscale || 'Jet',//'RdBu';
|
||||||
|
options.type = options.type || 'contour'; // or 'heatmap'
|
||||||
|
|
||||||
|
/* 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: 'heatmap'
|
||||||
|
}];
|
||||||
|
|
||||||
|
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: '' };
|
||||||
|
el.append('<div id="plot-' + random + '"></div>');
|
||||||
|
Plotly.newPlot('plot-' + random, data, layout);
|
||||||
|
|
||||||
|
// return Plotly.toImage(gd,{format:'jpeg',height:400,width:400});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: "Plot with colorbar",
|
||||||
|
run: run,
|
||||||
|
setup: setup,
|
||||||
|
image: image
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user