Added Crop Module

This commit is contained in:
Chinmay Pandhare
2017-03-11 09:28:37 +05:30
parent c58cbcf5c0
commit 5cbfca85b9
6 changed files with 85395 additions and 85239 deletions

170451
dist/image-sequencer.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -69,6 +69,7 @@
sequencer.addStep('ndvi-red');
sequencer.addStep('image-threshold');
sequencer.addStep('crop');
//sequencer.addStep('plot');
$('.add-step').click(function(e) {

View File

@@ -7,6 +7,6 @@ module.exports = {
'green-channel': require('./modules/GreenChannel'),
'ndvi-red': require('./modules/NdviRed'),
'plot': require('./modules/Plot'),
'image-threshold': require('./modules/ImageThreshold')
'image-threshold': require('./modules/ImageThreshold'),
'crop': require('./modules/Crop')
}

49
src/modules/Crop.js Normal file
View File

@@ -0,0 +1,49 @@
/*
* Image Cropping module
*/
module.exports = function Crop(options){
options = options || {};
options.title = "Crop Image";
options.format = options.format || "png";
function draw(image) {
var getPixels = require("get-pixels"),
savePixels = require("save-pixels"),
base64 = require('base64-stream');
getPixels(image.src,function(err,pixels){
var newdata = [];
var ox = options.cropX || 0; //Where to begin the crop on X axis
var oy = options.cropY || 0; //Where to begin the crop on Y axis
var w = options.cropL || Math.floor(0.5*pixels.shape[0]); //Length of crop
var h = options.cropH || Math.floor(0.5*pixels.shape[1]); //Height of crop
var iw = pixels.shape[0]; //Width of Original Image
newarray = new Uint8Array(4*w*h);
for (var n = oy; n < oy + h; n++) {
newarray.set(pixels.data.slice(n*4*iw + ox, n*4*iw + ox + 4*w),4*w*(n-oy));
}
pixels.data = newarray;
pixels.shape = [w,h,4];
pixels.stride[1] = 4*w;
var buffer = base64.encode();
savePixels(pixels, options.format)
.on('end', function() {
var img = new Image();
img.src = 'data:image/' + options.format + ';base64,' + buffer.read().toString();
if (options.output) options.output(img);
}).pipe(buffer);
});
}
return {
options: options,
draw: draw
}
}

View File

@@ -2,7 +2,6 @@
* Image thresholding with 'image-filter-threshold'
*/
module.exports = function ImageThreshold(options) {
options = options || {};
options.title = "Threshold image";
options.threshold = options.threshold || 30;