mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-17 05:40:00 +01:00
Double Inversion Test (#30)
* Double Inversion Test * Double Inversion Test * Buildfix
This commit is contained in:
committed by
Jeffrey Warren
parent
9e9d0afcfd
commit
ef2d315089
13
Gruntfile.js
13
Gruntfile.js
@@ -23,13 +23,9 @@ module.exports = function(grunt) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
browserify: {
|
browserify: {
|
||||||
// dist: {
|
dist: {
|
||||||
// src: ['src/ImageSequencer.js'],
|
src: ['src/ImageSequencer.js'],
|
||||||
// dest: 'dist/image-sequencer.js'
|
dest: 'dist/image-sequencer.js'
|
||||||
// },
|
|
||||||
node: {
|
|
||||||
src: ['src/ImageSequencerNode.js'],
|
|
||||||
dest: 'dist/image-sequencer-node.js'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,8 +35,7 @@ module.exports = function(grunt) {
|
|||||||
grunt.registerTask('default', ['watch']);
|
grunt.registerTask('default', ['watch']);
|
||||||
|
|
||||||
grunt.registerTask('build', [
|
grunt.registerTask('build', [
|
||||||
// 'browserify:dist',
|
'browserify:dist'
|
||||||
'browserify:node'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
34429
dist/image-sequencer-node.js
vendored
34429
dist/image-sequencer-node.js
vendored
File diff suppressed because it is too large
Load Diff
153144
dist/image-sequencer.js
vendored
153144
dist/image-sequencer.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,85 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
|
|
||||||
<title>Image Sequencer</title>
|
|
||||||
|
|
||||||
<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/font-awesome/css/font-awesome.min.css" rel="stylesheet">
|
|
||||||
<link href="../../dist/image-sequencer.css" rel="stylesheet">
|
|
||||||
|
|
||||||
<script src="../../node_modules/jquery/dist/jquery.min.js"></script>
|
|
||||||
<script src="../../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
|
||||||
<script src="../../dist/image-sequencer.js"></script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div class="header">
|
|
||||||
|
|
||||||
<h1>Image Sequencer</h1>
|
|
||||||
<h3>
|
|
||||||
<i>NDVI example</i>
|
|
||||||
<a href="https://github.com/jywarren/image-sequencer"><i class="fa fa-github"></i></a>
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p style="display:none;" class="spinner"><i class="fa fa-spinner fa-spin"></i></p>
|
|
||||||
|
|
||||||
<div class="panels">
|
|
||||||
|
|
||||||
<div class="panel ismod-image-select">
|
|
||||||
<div class="mod-drop">Drag image here</div>
|
|
||||||
<p class="instructions">Select or drop an image here to begin.</p>
|
|
||||||
<input id="file-select" type="file" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ismod-new-panel">
|
|
||||||
<form class="ismod-new-panel">
|
|
||||||
<p class="instructions">Add a new step</p>
|
|
||||||
<select class="select-module form-control" style="margin-bottom:6px;">
|
|
||||||
<option value="ndvi-red">NDVI with red filter</option>
|
|
||||||
<option value="green-channel">Green channel</option>
|
|
||||||
<option value="plot">Plot with colorbar</option>
|
|
||||||
<option value="image-threshold">Threshold image</option>
|
|
||||||
</select>
|
|
||||||
<p><button class="btn btn-default add-step">Add step</button></p>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="log">
|
|
||||||
<h4>Log</h4>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
var sequencer;
|
|
||||||
|
|
||||||
jQuery(document).ready(function($) {
|
|
||||||
|
|
||||||
sequencer = ImageSequencer();
|
|
||||||
|
|
||||||
sequencer.addStep('ndvi-red');
|
|
||||||
sequencer.addStep('plot');
|
|
||||||
|
|
||||||
$('.add-step').click(function(e) {
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
sequencer.addStep($('.select-module').val());
|
|
||||||
sequencer.run();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
2
index.js
2
index.js
@@ -2,7 +2,7 @@ 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','do-nothing-pix','do-nothing-pix','ndvi-red']);
|
sequencer.addSteps(['do-nothing-pix','ndvi-red','invert']);
|
||||||
sequencer.removeSteps(1);
|
sequencer.removeSteps(1);
|
||||||
sequencer.insertSteps({
|
sequencer.insertSteps({
|
||||||
red: [{index: -1, name: 'do-nothing', o:{}}]
|
red: [{index: -1, name: 'do-nothing', o:{}}]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
function LoadImage(ref, name, src) {
|
function LoadImage(ref, name, src) {
|
||||||
function CImage(src) {
|
function CImage(src) {
|
||||||
datauri = (ref.options.inBrowser)?(src):require('urify')(src);
|
datauri = (ref.options.inBrowser || src.substring(0,11) == "data:image/")?(src):require('urify')(src);
|
||||||
image = {
|
image = {
|
||||||
src: datauri,
|
src: datauri,
|
||||||
format: datauri.split(':')[1].split(';')[0].split('/')[1]
|
format: datauri.split(':')[1].split(';')[0].split('/')[1]
|
||||||
|
|||||||
@@ -5,5 +5,6 @@ module.exports = {
|
|||||||
'do-nothing': require('./modules/DoNothing'),
|
'do-nothing': require('./modules/DoNothing'),
|
||||||
'green-channel': require('./modules/GreenChannel'),
|
'green-channel': require('./modules/GreenChannel'),
|
||||||
'ndvi-red': require('./modules/NdviRed'),
|
'ndvi-red': require('./modules/NdviRed'),
|
||||||
'do-nothing-pix': require('./modules/DoNothingPix')
|
'do-nothing-pix': require('./modules/DoNothingPix'),
|
||||||
|
'invert': require('./modules/Invert')
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/modules/Invert.js
Normal file
36
src/modules/Invert.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Display only the green channel
|
||||||
|
*/
|
||||||
|
module.exports = function GreenChannel(options) {
|
||||||
|
|
||||||
|
options = options || {};
|
||||||
|
options.title = "Invert Colors";
|
||||||
|
options.description = "Inverts the colors of the image";
|
||||||
|
var output;
|
||||||
|
|
||||||
|
//function setup() {} // optional
|
||||||
|
|
||||||
|
function draw(input,callback) {
|
||||||
|
this_ = this;
|
||||||
|
function changePixel(r, g, b, a) {
|
||||||
|
return [255-r, 255-g, 255-b, a];
|
||||||
|
}
|
||||||
|
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,
|
||||||
|
//setup: setup, // optional
|
||||||
|
draw: draw,
|
||||||
|
output: output
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,8 +22,8 @@ module.exports = function PixelManipulation(image, options) {
|
|||||||
// iterate through pixels;
|
// iterate through pixels;
|
||||||
// this could possibly be more efficient; see
|
// this could possibly be more efficient; see
|
||||||
// https://github.com/p-v-o-s/infragram-js/blob/master/public/infragram.js#L173-L181
|
// https://github.com/p-v-o-s/infragram-js/blob/master/public/infragram.js#L173-L181
|
||||||
for(var x = 1; x < pixels.shape[0]; x++) {
|
for(var x = 0; x < pixels.shape[0]; x++) {
|
||||||
for(var y = 1; y < pixels.shape[1]; y++) {
|
for(var y = 0; y < pixels.shape[1]; y++) {
|
||||||
|
|
||||||
pixel = options.changePixel(
|
pixel = options.changePixel(
|
||||||
pixels.get(x, y, 0),
|
pixels.get(x, y, 0),
|
||||||
@@ -40,15 +40,18 @@ module.exports = function PixelManipulation(image, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.format = "jpeg";
|
||||||
|
|
||||||
// there may be a more efficient means to encode an image object,
|
// there may be a more efficient means to encode an image object,
|
||||||
// but node modules and their documentation are essentially arcane on this point
|
// but node modules and their documentation are essentially arcane on this point
|
||||||
var buffer = base64.encode();
|
w = base64.encode();
|
||||||
savePixels(pixels, (options.format=="png"?"jpeg":options.format)).on('end', function() {
|
var r = savePixels(pixels, options.format);
|
||||||
data = buffer.read().toString();
|
r.pipe(w).on('finish',function(){
|
||||||
datauri = 'data:image/' + (options.format=="png"?"jpeg":options.format) + ';base64,' + data;
|
data = w.read().toString();
|
||||||
if (options.output) options.output(options.image,datauri,(options.format=="png"?"jpeg":options.format));
|
datauri = 'data:image/' + options.format + ';base64,' + data;
|
||||||
|
if (options.output) options.output(options.image,datauri,options.format);
|
||||||
if (options.callback) options.callback();
|
if (options.callback) options.callback();
|
||||||
}).pipe(buffer);
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
28
test/image-manip.js
Normal file
28
test/image-manip.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var test = require('tape');
|
||||||
|
|
||||||
|
// We should only test headless code here.
|
||||||
|
// http://stackoverflow.com/questions/21358015/error-jquery-requires-a-window-with-a-document#25622933
|
||||||
|
|
||||||
|
require('../src/ImageSequencer.js');
|
||||||
|
|
||||||
|
var sequencer = ImageSequencer({ ui: "none" });
|
||||||
|
var image = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
|
||||||
|
sequencer.loadImages({images:{
|
||||||
|
test1: image,
|
||||||
|
test2: image
|
||||||
|
}, callback:function(){}});
|
||||||
|
|
||||||
|
sequencer.addSteps("test1", ['do-nothing-pix','invert','invert']);
|
||||||
|
sequencer.run();
|
||||||
|
|
||||||
|
test("Inverted image isn't identical", function (t) {
|
||||||
|
t.notEqual(sequencer.images.test1.steps[1].output.src, sequencer.images.test1.steps[2].output.src);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Twice inverted image is identical to original image", function (t) {
|
||||||
|
t.equal(sequencer.images.test1.steps[1].output.src, sequencer.images.test1.steps[3].output.src);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user