Added Crop Module (#8)

* ImageThreshold.js and ImageSelect.js bugfixes

* Added Crop Module

* lowercase parameters

* Added usage notes, changed a variable name.
This commit is contained in:
Chinmay Pandhare (CCD)
2017-03-14 21:01:43 +05:30
committed by Jeffrey Warren
parent 18571afab7
commit bf4a264ed9
6 changed files with 85398 additions and 85221 deletions

170544
dist/image-sequencer.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>Image Sequencer</title> <title>Image Sequencer</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -48,7 +48,7 @@
<option value="green-channel">Green channel</option> <option value="green-channel">Green channel</option>
<option value="plot">Plot with colorbar</option> <option value="plot">Plot with colorbar</option>
<option value="image-threshold">Threshold image</option> <option value="image-threshold">Threshold image</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>
@@ -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) {

View File

@@ -60,7 +60,7 @@ ImageSequencer = function ImageSequencer(options) {
} }
// Pre-set the initial output behavior of the final step, // Pre-set the initial output behavior of the final step,
// which will be changed if an additional step is added. // which will be changed if an additional step is added.
module.options.output = function output(image) { module.options.output = function output(image) {
if (module.options.ui && module.options.ui.display) module.options.ui.display(image); if (module.options.ui && module.options.ui.display) module.options.ui.display(image);
@@ -68,7 +68,7 @@ ImageSequencer = function ImageSequencer(options) {
} }
// passed image is optional but you can pass a // passed image is optional but you can pass a
// non-stored image through the whole steps chain // non-stored image through the whole steps chain
function run(image) { function run(image) {
if (image) steps[1].draw(image); if (image) steps[1].draw(image);

View File

@@ -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')
} }

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

@@ -0,0 +1,61 @@
/*
* Image Cropping module
* Usage:
* Expected Inputs:
* options.x : x-coordinate of image where the modules starts cropping | default : 0
* options.y : y-coordinate of image where the modules starts cropping | default : 0
* options.w : width of the resulting cropped image | default : 50% of input image width
* options.h : height of the resulting cropped image | default : 50% of input image height
* Output:
* The cropped image, which is essentially a rectangle bounded by the lines:
* x = options.x
* x = options.x + options.w
* y = options.y
* y = options.y + options.h
*/
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.x || 0;
var oy = options.y || 0;
var w = options.w || Math.floor(0.5*pixels.shape[0]);
var h = options.h || Math.floor(0.5*pixels.shape[1]);
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' * 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;