mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-15 04:40:02 +01:00
Added Crop Module
This commit is contained in:
68
dist/image-sequencer.js
vendored
68
dist/image-sequencer.js
vendored
@@ -184268,11 +184268,11 @@ module.exports = {
|
|||||||
'green-channel': require('./modules/GreenChannel'),
|
'green-channel': require('./modules/GreenChannel'),
|
||||||
'ndvi-red': require('./modules/NdviRed'),
|
'ndvi-red': require('./modules/NdviRed'),
|
||||||
'plot': require('./modules/Plot'),
|
'plot': require('./modules/Plot'),
|
||||||
'image-threshold': require('./modules/ImageThreshold')
|
'image-threshold': require('./modules/ImageThreshold'),
|
||||||
|
'crop': require('./modules/Crop')
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./modules/GreenChannel":1040,"./modules/ImageSelect":1041,"./modules/ImageThreshold":1042,"./modules/NdviRed":1043,"./modules/Plot":1045}],1039:[function(require,module,exports){
|
},{"./modules/Crop":1040,"./modules/GreenChannel":1041,"./modules/ImageSelect":1042,"./modules/ImageThreshold":1043,"./modules/NdviRed":1044,"./modules/Plot":1046}],1039:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
* Default UI for each image-sequencer module
|
* Default UI for each image-sequencer module
|
||||||
*/
|
*/
|
||||||
@@ -184313,6 +184313,57 @@ module.exports = function UserInterface(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
},{}],1040:[function(require,module,exports){
|
},{}],1040:[function(require,module,exports){
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},{"base64-stream":13,"get-pixels":113,"save-pixels":963}],1041:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
* Display only the green channel
|
* Display only the green channel
|
||||||
*/
|
*/
|
||||||
@@ -184341,7 +184392,7 @@ module.exports = function GreenChannel(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./PixelManipulation.js":1044}],1041:[function(require,module,exports){
|
},{"./PixelManipulation.js":1045}],1042:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
* Special module to kick off the sequence
|
* Special module to kick off the sequence
|
||||||
* -- depends on jQuery for interface setup & drag & drop
|
* -- depends on jQuery for interface setup & drag & drop
|
||||||
@@ -184424,12 +184475,11 @@ module.exports = function ImageSelect(options) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"jquery":273}],1042:[function(require,module,exports){
|
},{"jquery":273}],1043:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
* Image thresholding with 'image-filter-threshold'
|
* Image thresholding with 'image-filter-threshold'
|
||||||
*/
|
*/
|
||||||
module.exports = function ImageThreshold(options) {
|
module.exports = function ImageThreshold(options) {
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Threshold image";
|
options.title = "Threshold image";
|
||||||
options.threshold = options.threshold || 30;
|
options.threshold = options.threshold || 30;
|
||||||
@@ -184473,7 +184523,7 @@ module.exports = function ImageThreshold(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"image-filter-core":261,"image-filter-threshold":262}],1043:[function(require,module,exports){
|
},{"image-filter-core":261,"image-filter-threshold":262}],1044:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
* NDVI with red filter (blue channel is infrared)
|
* NDVI with red filter (blue channel is infrared)
|
||||||
*/
|
*/
|
||||||
@@ -184502,7 +184552,7 @@ module.exports = function NdviRed(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"./PixelManipulation.js":1044}],1044:[function(require,module,exports){
|
},{"./PixelManipulation.js":1045}],1045:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
* General purpose per-pixel manipulation
|
* General purpose per-pixel manipulation
|
||||||
* accepting a changePixel() method to remix a pixel's channels
|
* accepting a changePixel() method to remix a pixel's channels
|
||||||
@@ -184565,7 +184615,7 @@ module.exports = function PixelManipulation(image, options) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},{"base64-stream":13,"get-pixels":113,"save-pixels":963}],1045:[function(require,module,exports){
|
},{"base64-stream":13,"get-pixels":113,"save-pixels":963}],1046:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
* Plot image on a graph with color bar
|
* Plot image on a graph with color bar
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
|
|
||||||
sequencer.addStep('ndvi-red');
|
sequencer.addStep('ndvi-red');
|
||||||
sequencer.addStep('image-threshold');
|
sequencer.addStep('image-threshold');
|
||||||
|
sequencer.addStep('crop');
|
||||||
//sequencer.addStep('plot');
|
//sequencer.addStep('plot');
|
||||||
|
|
||||||
$('.add-step').click(function(e) {
|
$('.add-step').click(function(e) {
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ module.exports = {
|
|||||||
'green-channel': require('./modules/GreenChannel'),
|
'green-channel': require('./modules/GreenChannel'),
|
||||||
'ndvi-red': require('./modules/NdviRed'),
|
'ndvi-red': require('./modules/NdviRed'),
|
||||||
'plot': require('./modules/Plot'),
|
'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
49
src/modules/Crop.js
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
* Image thresholding with 'image-filter-threshold'
|
* Image thresholding with 'image-filter-threshold'
|
||||||
*/
|
*/
|
||||||
module.exports = function ImageThreshold(options) {
|
module.exports = function ImageThreshold(options) {
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Threshold image";
|
options.title = "Threshold image";
|
||||||
options.threshold = options.threshold || 30;
|
options.threshold = options.threshold || 30;
|
||||||
|
|||||||
Reference in New Issue
Block a user